From c24c93ad79db102d0c0adf9792d70ecc793f8d37 Mon Sep 17 00:00:00 2001 From: slawkens Date: Fri, 8 Nov 2024 10:20:44 +0100 Subject: [PATCH] Fix migrations upgrade and downgrade + Add option to disable auto migrate --- system/libs/pot/OTS_Base_DB.php | 2 +- system/migrate.php | 4 ++++ system/migrations/31.php | 2 +- system/migrations/34.php | 2 +- system/migrations/36.php | 7 ++++--- system/migrations/38.php | 5 ++++- system/settings.php | 7 +++++++ 7 files changed, 22 insertions(+), 7 deletions(-) diff --git a/system/libs/pot/OTS_Base_DB.php b/system/libs/pot/OTS_Base_DB.php index f4605cf9..1d7ae287 100644 --- a/system/libs/pot/OTS_Base_DB.php +++ b/system/libs/pot/OTS_Base_DB.php @@ -237,7 +237,7 @@ abstract class OTS_Base_DB extends PDO implements IOTS_DB } public function addColumn($table, $column, $definition): void { - $this->exec('ALTER TABLE ' . $this->tableName($table) . ' ADD `access` ' . $this->fieldName($column) . ' ' . $definition . ';'); + $this->exec('ALTER TABLE ' . $this->tableName($table) . ' ADD ' . $this->fieldName($column) . ' ' . $definition . ';'); } public function modifyColumn($table, $column, $definition): void { diff --git a/system/migrate.php b/system/migrate.php index 4eb7bf7a..4342cacc 100644 --- a/system/migrate.php +++ b/system/migrate.php @@ -9,6 +9,10 @@ */ 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 diff --git a/system/migrations/31.php b/system/migrations/31.php index dc8f342d..edbf7020 100644 --- a/system/migrations/31.php +++ b/system/migrations/31.php @@ -45,7 +45,7 @@ $up = function () use ($db) { } if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'rewardboss')) { - $db->addColumn(TABLE_PREFIX . 'monsters', 'rewardboss', "TINYINT(1) TINYINT(1) NOT NULL DEFAULT '0' AFTER `attackable`"); + $db->addColumn(TABLE_PREFIX . 'monsters', 'rewardboss', "TINYINT(1) NOT NULL DEFAULT '0' AFTER `attackable`"); } if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'defense')) { diff --git a/system/migrations/34.php b/system/migrations/34.php index 702e3a65..0e51c7c3 100644 --- a/system/migrations/34.php +++ b/system/migrations/34.php @@ -13,6 +13,6 @@ $up = function () use ($db) { $down = function () use ($db) { if ($db->hasColumn(TABLE_PREFIX . 'visitors', 'user_agent')) { - $db->dropColumn(TABLE_PREFIX . 'monsters', 'user_agent'); + $db->dropColumn(TABLE_PREFIX . 'visitors', 'user_agent'); } }; diff --git a/system/migrations/36.php b/system/migrations/36.php index 15f9eb55..ac6969f8 100644 --- a/system/migrations/36.php +++ b/system/migrations/36.php @@ -11,7 +11,8 @@ $up = function () use ($db) { }; $down = function () use ($db) { - if ($db->hasTable(TABLE_PREFIX . 'settings')) { - $db->dropTable(TABLE_PREFIX . 'settings'); - } + // will break the aac + //if ($db->hasTable(TABLE_PREFIX . 'settings')) { + // $db->dropTable(TABLE_PREFIX . 'settings'); + //} }; diff --git a/system/migrations/38.php b/system/migrations/38.php index 80887452..24dd2f72 100644 --- a/system/migrations/38.php +++ b/system/migrations/38.php @@ -1,8 +1,11 @@ false, 'is_config' => true, ], + 'database_auto_migrate' => [ + 'name' => 'Database Auto Migrate', + 'desc' => 'Migrate database to latest version in myaac, automatically.', + 'type' => 'boolean', + 'default' => true, + 'is_config' => true, + ], [ 'type' => 'category', 'title' => 'Mailing',