diff --git a/system/migrations/31.php b/system/migrations/31.php index 8dadb817..d4d8162c 100644 --- a/system/migrations/31.php +++ b/system/migrations/31.php @@ -1,57 +1,118 @@ hasColumn(TABLE_PREFIX . 'monsters', 'elements')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `elements` TEXT NOT NULL AFTER `immunities`;"); -} +$up = function () use ($db) { + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'elements')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `elements` TEXT NOT NULL AFTER `immunities`;"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'pushable')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `pushable` TINYINT(1) NOT NULL DEFAULT '0' AFTER `convinceable`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'pushable')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `pushable` TINYINT(1) NOT NULL DEFAULT '0' AFTER `convinceable`;"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushitems')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canpushitems` TINYINT(1) NOT NULL DEFAULT '0' AFTER `pushable`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushitems')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canpushitems` TINYINT(1) NOT NULL DEFAULT '0' AFTER `pushable`;"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushcreatures')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canpushcreatures` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canpushitems`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushcreatures')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canpushcreatures` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canpushitems`;"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonenergy')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonenergy` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canpushitems`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonenergy')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonenergy` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canpushitems`;"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonpoison')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonpoison` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonenergy`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonpoison')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonpoison` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonenergy`;"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonfire')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonfire` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonpoison`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonfire')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonfire` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonpoison`;"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'runonhealth')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `runonhealth` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonfire`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'runonhealth')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `runonhealth` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonfire`;"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'hostile')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `hostile` TINYINT(1) NOT NULL DEFAULT '0' AFTER `runonhealth`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'hostile')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `hostile` TINYINT(1) NOT NULL DEFAULT '0' AFTER `runonhealth`;"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'attackable')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `attackable` TINYINT(1) NOT NULL DEFAULT '0' AFTER `hostile`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'attackable')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `attackable` TINYINT(1) NOT NULL DEFAULT '0' AFTER `hostile`;"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'rewardboss')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `rewardboss` TINYINT(1) NOT NULL DEFAULT '0' AFTER `attackable`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'rewardboss')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `rewardboss` TINYINT(1) NOT NULL DEFAULT '0' AFTER `attackable`;"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'defense')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `defense` INT(11) NOT NULL DEFAULT '0' AFTER `rewardboss`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'defense')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `defense` INT(11) NOT NULL DEFAULT '0' AFTER `rewardboss`;"); + } -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'armor')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `armor` INT(11) NOT NULL DEFAULT '0' AFTER `defense`;"); -} + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'armor')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `armor` INT(11) NOT NULL DEFAULT '0' AFTER `defense`;"); + } + + if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'summons')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `summons` TEXT NOT NULL AFTER `loot`;"); + } +}; + +$down = function () use ($db) { + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'elements')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `elements`;"); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'pushable')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `pushable`;"); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushitems')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `canpushitems`;"); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushcreatures')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `canpushcreatures`;"); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonenergy')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `canwalkonenergy`;"); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonpoison')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `canwalkonpoison`;"); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonfire')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `canwalkonfire`;"); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'runonhealth')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `runonhealth`;"); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'hostile')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `hostile`;"); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'attackable')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `attackable`;"); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'rewardboss')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `rewardboss`;"); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'defense')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `defense`;"); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'armor')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `armor`;"); + } + + if($db->hasColumn(TABLE_PREFIX . 'monsters', 'summons')) { + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` DROP COLUMN `summons`;"); + } +}; -if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'summons')) { - $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `summons` TEXT NOT NULL AFTER `loot`;"); -} diff --git a/system/migrations/32.php b/system/migrations/32.php index ca1e4859..0fb1238a 100644 --- a/system/migrations/32.php +++ b/system/migrations/32.php @@ -1,4 +1,10 @@ exec('ALTER TABLE `' . TABLE_PREFIX . "visitors` MODIFY `page` VARCHAR(2048) NOT NULL;"); +$up = function () use ($db) { + $db->exec('ALTER TABLE `' . TABLE_PREFIX . "visitors` MODIFY `page` VARCHAR(2048) NOT NULL;"); +}; + +$down = function () { + // nothing to be done, as we have just extended the size of a column +}; diff --git a/system/migrations/33.php b/system/migrations/33.php index 12fe4c2c..cbe7a410 100644 --- a/system/migrations/33.php +++ b/system/migrations/33.php @@ -3,4 +3,10 @@ // according to this answer: https://stackoverflow.com/questions/166132/maximum-length-of-the-textual-representation-of-an-ipv6-address // the size of ipv6 can be maximal 45 chars -$db->exec('ALTER TABLE `' . TABLE_PREFIX . "visitors` MODIFY `ip` VARCHAR(45) NOT NULL;"); +$up = function () use ($db) { + $db->exec('ALTER TABLE `' . TABLE_PREFIX . "visitors` MODIFY `ip` VARCHAR(45) NOT NULL;"); +}; + +$down = function () { + // nothing to be done, as we have just extended the size of a column +}; diff --git a/system/migrations/34.php b/system/migrations/34.php index 6f4e6b4a..358b5cfc 100644 --- a/system/migrations/34.php +++ b/system/migrations/34.php @@ -1,4 +1,10 @@ exec('ALTER TABLE `' . TABLE_PREFIX . "visitors` ADD `user_agent` VARCHAR(255) NOT NULL DEFAULT '';"); +$up = function () use ($db) { + $db->exec('ALTER TABLE `' . TABLE_PREFIX . "visitors` ADD `user_agent` VARCHAR(255) NOT NULL DEFAULT '';"); +}; + +$down = function () use ($db) { + $db->exec('ALTER TABLE `' . TABLE_PREFIX . "monsters` DROP COLUMN `user_agent`;"); +}; diff --git a/system/migrations/35.php b/system/migrations/35.php index 8016807d..6579f373 100644 --- a/system/migrations/35.php +++ b/system/migrations/35.php @@ -1,3 +1,10 @@ exec('ALTER TABLE `' . TABLE_PREFIX . "monsters` ADD `look` VARCHAR(255) NOT NULL DEFAULT '' AFTER `health`;"); \ No newline at end of file +$up = function () use ($db) { + $db->exec('ALTER TABLE `' . TABLE_PREFIX . "monsters` ADD `look` VARCHAR(255) NOT NULL DEFAULT '' AFTER `health`;"); +}; + +$down = function () use ($db) { + $db->exec('ALTER TABLE `' . TABLE_PREFIX . "monsters` DROP COLUMN `look`;"); +}; diff --git a/system/migrations/36.php b/system/migrations/36.php index d88e9d28..f9899368 100644 --- a/system/migrations/36.php +++ b/system/migrations/36.php @@ -1,14 +1,20 @@ hasTable(TABLE_PREFIX . 'settings')) { - $db->exec("CREATE TABLE `" . TABLE_PREFIX . "settings` - ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` VARCHAR(255) NOT NULL DEFAULT '', - `key` VARCHAR(255) NOT NULL DEFAULT '', - `value` TEXT NOT NULL, - PRIMARY KEY (`id`), - KEY `key` (`key`) - ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;"); -} +$up = function () use ($db) { + // add settings table + if (!$db->hasTable(TABLE_PREFIX . 'settings')) { + $db->exec("CREATE TABLE `" . TABLE_PREFIX . "settings` + ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NOT NULL DEFAULT '', + `key` VARCHAR(255) NOT NULL DEFAULT '', + `value` TEXT NOT NULL, + PRIMARY KEY (`id`), + KEY `key` (`key`) + ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;"); + } +}; + +$down = function () use ($db) { + $db->exec("DROP TABLE IF EXISTS `" . TABLE_PREFIX . "settings`"); +}; diff --git a/system/migrations/37.php b/system/migrations/37.php index dd12f35a..110d15c2 100644 --- a/system/migrations/37.php +++ b/system/migrations/37.php @@ -5,4 +5,10 @@ use MyAAC\Models\Pages; -Pages::query()->where('access', 1)->update(['access' => 0]); +$up = function () { + Pages::query()->where('access', 1)->update(['access' => 0]); +}; + +$down = function () { + Pages::query()->where('access', 0)->update(['access' => 1]); +}; diff --git a/system/migrations/38.php b/system/migrations/38.php index b2d066a7..80887452 100644 --- a/system/migrations/38.php +++ b/system/migrations/38.php @@ -2,4 +2,11 @@ // 2023-11-11 // execute highscores_ids_hidden once again, cause of settings -require __DIR__ . '/20.php'; +$up = function () { + require __DIR__ . '/20.php'; +}; + +$down = function () { + // there is no downgrade for this +}; + diff --git a/system/migrations/39.php b/system/migrations/39.php index d05d911f..637dca77 100644 --- a/system/migrations/39.php +++ b/system/migrations/39.php @@ -3,16 +3,34 @@ // 2024-01-27 // change hidden to hide (Eloquent model reserved keyword) -if (!$db->hasColumn('players', 'hide')) { - $db->exec("ALTER TABLE `players` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -} +$up = function () use ($db) { + if (!$db->hasColumn('players', 'hide')) { + $db->exec("ALTER TABLE `players` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); + } -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "changelog` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "faq` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "forum_boards` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "news` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "news_categories` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "pages` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "gallery` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); -$db->exec("ALTER TABLE `" . TABLE_PREFIX . "spells` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "changelog` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "faq` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "forum_boards` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "news` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "news_categories` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "pages` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "gallery` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "spells` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); +}; + +$down = function () use ($db) { + if (!$db->hasColumn('players', 'hide')) { + $db->exec("ALTER TABLE `players` CHANGE `hide` `hidden` TINYINT(1) NOT NULL DEFAULT 0;"); + } + + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "changelog` CHANGE `hide` `hidden` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "faq` CHANGE `hide` `hidden` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "forum_boards` CHANGE `hide` `hidden` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` CHANGE `hide` `hidden` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "news` CHANGE `hide` `hidden` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "news_categories` CHANGE `hide` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "pages` CHANGE `hide` `hidden` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "gallery` CHANGE `hide` `hidden` TINYINT(1) NOT NULL DEFAULT 0;"); + $db->exec("ALTER TABLE `" . TABLE_PREFIX . "spells` CHANGE `hide` `hidden` TINYINT(1) NOT NULL DEFAULT 0;"); +}; diff --git a/system/migrations/40.php b/system/migrations/40.php index 7a7eb310..ef492a11 100644 --- a/system/migrations/40.php +++ b/system/migrations/40.php @@ -5,8 +5,19 @@ use MyAAC\Models\Menu; -Menu::where('link', 'lastkills')->update(['link' => 'last-kills']); -Menu::where('link', 'serverInfo')->update(['link' => 'server-info']); -Menu::where('link', 'experienceStages')->update(['link' => 'exp-stages']); -Menu::where('link', 'experienceTable')->update(['link' => 'exp-table']); -Menu::where('link', 'creatures')->update(['link' => 'monsters']); +$up = function() { + Menu::where('link', 'lastkills')->update(['link' => 'last-kills']); + Menu::where('link', 'serverInfo')->update(['link' => 'server-info']); + Menu::where('link', 'experienceStages')->update(['link' => 'exp-stages']); + Menu::where('link', 'experienceTable')->update(['link' => 'exp-table']); + Menu::where('link', 'creatures')->update(['link' => 'monsters']); +}; + +$down = function() { + Menu::where('link', 'last-kills')->update(['link' => 'lastkills']); + Menu::where('link', 'server-info')->update(['link' => 'serverInfo']); + Menu::where('link', 'exp-stages')->update(['link' => 'experienceStages']); + Menu::where('link', 'exp-table')->update(['link' => 'experienceTable']); + Menu::where('link', 'monsters')->update(['link' => 'creatures']); +}; +