Fix migrations upgrade and downgrade

+ Add option to disable auto migrate
This commit is contained in:
slawkens 2024-11-08 10:20:44 +01:00
parent 8aff9f36fb
commit c24c93ad79
7 changed files with 22 additions and 7 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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')) {

View File

@ -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');
}
};

View File

@ -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');
//}
};

View File

@ -1,8 +1,11 @@
<?php
/**
* @var OTS_DB_MySQL $db
*/
// 2023-11-11
// execute highscores_ids_hidden once again, cause of settings
$up = function () {
$up = function () use ($db) {
require __DIR__ . '/20.php';
};

View File

@ -392,6 +392,13 @@ return [
'default' => 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',