mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-29 18:59:21 +02:00
Add migrate command to manually upgrade db, incase auto migrate is disabled
This commit is contained in:
parent
92024cfdbf
commit
dead8e4043
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
28
system/src/Commands/MigrateCommand.php
Normal file
28
system/src/Commands/MigrateCommand.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace MyAAC\Commands;
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class MigrateCommand extends Command
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user