Skip to content

Commit 296e5eb

Browse files
committed
fix(backup-server): run backup setup before migrations in moox:install
1 parent 41c8a3f commit 296e5eb

2 files changed

Lines changed: 33 additions & 19 deletions

File tree

packages/backup-server/src/Installers/BackupServerInstaller.php

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66

77
use Illuminate\Support\Facades\Artisan;
88
use Illuminate\Support\Facades\File;
9-
use Illuminate\Support\Facades\Schema;
109
use Moox\Core\Installer\AbstractAssetInstaller;
1110

1211
use function Moox\Prompts\error;
1312
use function Moox\Prompts\note;
1413

1514
/**
16-
* Installer für das Backup-Server-Package.
15+
* Installer for the Backup Server package.
1716
*
18-
* Publiziert die Spatie Laravel Backup Server Konfiguration und Migrationen
19-
* und führt die Migrationen aus. Wird vom Moox-Installer ausgeführt.
17+
* Publishes Spatie Laravel Backup Server configuration and migration files,
18+
* then runs only the backup-server migration (not all pending migrations).
2019
*/
2120
class BackupServerInstaller extends AbstractAssetInstaller
2221
{
@@ -33,7 +32,7 @@ public function getLabel(): string
3332
protected function getDefaultConfig(): array
3433
{
3534
$config = parent::getDefaultConfig();
36-
$config['priority'] = 10;
35+
$config['priority'] = 8;
3736

3837
return $config;
3938
}
@@ -49,7 +48,7 @@ public function checkExists(string $packageName, array $items): bool
4948
return false;
5049
}
5150

52-
return $this->hasBackupServerMigration() || Schema::hasTable('backup_server_sources');
51+
return $this->hasBackupServerMigration();
5352
}
5453

5554
public function install(array $assets): bool
@@ -69,7 +68,7 @@ public function install(array $assets): bool
6968

7069
note('✅ Spatie Laravel Backup Server config published.');
7170

72-
if (! $this->hasBackupServerMigration() && ! Schema::hasTable('backup_server_sources')) {
71+
if (! $this->hasBackupServerMigration()) {
7372
note('📦 Publishing Spatie Laravel Backup Server migrations…');
7473
$this->publish('backup-server-migrations', $force);
7574

@@ -84,20 +83,28 @@ public function install(array $assets): bool
8483
note('ℹ️ Backup Server migrations already present, skipping publish.');
8584
}
8685

87-
if (! Schema::hasTable('backup_server_sources')) {
88-
note('🔄 Running Backup Server migrations…');
86+
$migrationPath = $this->getBackupServerMigrationPath();
87+
if ($migrationPath === null) {
88+
error('⚠️ Backup Server migration file not found.');
8989

90-
if ($this->command) {
91-
$this->command->call('migrate', ['--force' => true]);
92-
} else {
93-
Artisan::call('migrate', ['--force' => true]);
94-
}
90+
return false;
91+
}
9592

96-
note('✅ Backup Server migrations executed.');
93+
note('🔄 Running Backup Server migration…');
94+
95+
$migrateOptions = [
96+
'--force' => true,
97+
'--path' => $migrationPath,
98+
];
99+
100+
if ($this->command) {
101+
$this->command->call('migrate', $migrateOptions);
97102
} else {
98-
note('ℹ️ Backup Server tables already exist, skipping migrate.');
103+
Artisan::call('migrate', $migrateOptions);
99104
}
100105

106+
note('✅ Backup Server migration executed.');
107+
101108
return true;
102109
} catch (\Throwable $e) {
103110
error('⚠️ Backup Server setup failed: '.$e->getMessage());
@@ -122,19 +129,24 @@ private function publish(string $tag, bool $force): void
122129
}
123130

124131
private function hasBackupServerMigration(): bool
132+
{
133+
return $this->getBackupServerMigrationPath() !== null;
134+
}
135+
136+
private function getBackupServerMigrationPath(): ?string
125137
{
126138
$migrationPath = database_path('migrations');
127139

128140
if (! File::isDirectory($migrationPath)) {
129-
return false;
141+
return null;
130142
}
131143

132144
foreach (File::files($migrationPath) as $file) {
133145
if (str_contains($file->getFilename(), 'create_backup_server_tables')) {
134-
return true;
146+
return 'database/migrations/'.$file->getFilename();
135147
}
136148
}
137149

138-
return false;
150+
return null;
139151
}
140152
}

packages/core/src/Console/Commands/MooxInstallCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ protected function runWithHooks(InstallerRegistry $registry, array $assets, arra
398398

399399
$failedInstallers = [];
400400

401+
usort($selectedTypes, fn (string $a, string $b): int => ($registry->get($a)?->getPriority() ?? PHP_INT_MAX) <=> ($registry->get($b)?->getPriority() ?? PHP_INT_MAX));
402+
401403
foreach ($selectedTypes as $type) {
402404
try {
403405
$installer = $registry->get($type);

0 commit comments

Comments
 (0)