66
77use Illuminate \Support \Facades \Artisan ;
88use Illuminate \Support \Facades \File ;
9- use Illuminate \Support \Facades \Schema ;
109use Moox \Core \Installer \AbstractAssetInstaller ;
1110
1211use function Moox \Prompts \error ;
1312use 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 */
2120class 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}
0 commit comments