diff --git a/system/init.php b/system/init.php index 81ce3bbf..1673d3d8 100644 --- a/system/init.php +++ b/system/init.php @@ -142,7 +142,10 @@ if(!defined('MYAAC_INSTALL') && !$db->hasTable('myaac_account_actions')) { } // execute migrations -require SYSTEM . 'migrate.php'; +$configDatabaseAutoMigrate = config('database_auto_migrate'); +if (!isset($configDatabaseAutoMigrate) || $configDatabaseAutoMigrate) { + require SYSTEM . 'migrate.php'; +} // settings $settings = Settings::getInstance(); diff --git a/system/migrate.php b/system/migrate.php index 4342cacc..391fe253 100644 --- a/system/migrate.php +++ b/system/migrate.php @@ -9,10 +9,6 @@ */ defined('MYAAC') or die('Direct access not allowed!'); -if (!config('database_auto_migrate')) { - return; -} - // database migrations $tmp = ''; if(fetchDatabaseConfig('database_version', $tmp)) { // we got version @@ -21,6 +17,11 @@ if(fetchDatabaseConfig('database_version', $tmp)) { // we got version $db->revalidateCache(); for($i = $tmp + 1; $i <= DATABASE_VERSION; $i++) { require SYSTEM . 'migrations/' . $i . '.php'; + + if (isset($up)) { + $up(); + } + updateDatabaseConfig('database_version', $i); } } @@ -30,6 +31,11 @@ else { // register first version $db->revalidateCache(); for($i = 1; $i <= DATABASE_VERSION; $i++) { require SYSTEM . 'migrations/' . $i . '.php'; + + if (isset($up)) { + $up(); + } + updateDatabaseConfig('database_version', $i); } } diff --git a/system/src/Commands/MigrateCommand.php b/system/src/Commands/MigrateCommand.php new file mode 100644 index 00000000..c5bf010c --- /dev/null +++ b/system/src/Commands/MigrateCommand.php @@ -0,0 +1,28 @@ +setName('migrate') + ->setDescription('This command updates the AAC to latest migration'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + require SYSTEM . 'init.php'; + + $io = new SymfonyStyle($input, $output); + require SYSTEM . 'migrate.php'; + + $io->success('Migrated to latest version'); + return Command::SUCCESS; + } +}