Migrations up down

This commit is contained in:
slawkens 2024-09-05 15:34:49 +02:00
parent d99b22f98b
commit b5dcf76d8e
10 changed files with 211 additions and 77 deletions

View File

@ -1,57 +1,118 @@
<?php <?php
if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'elements')) { $up = function () use ($db) {
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `elements` TEXT NOT NULL AFTER `immunities`;"); 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')) { if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'pushable')) {
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `pushable` TINYINT(1) NOT NULL DEFAULT '0' AFTER `convinceable`;"); $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `pushable` TINYINT(1) NOT NULL DEFAULT '0' AFTER `convinceable`;");
} }
if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushitems')) { if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushitems')) {
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canpushitems` TINYINT(1) NOT NULL DEFAULT '0' AFTER `pushable`;"); $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canpushitems` TINYINT(1) NOT NULL DEFAULT '0' AFTER `pushable`;");
} }
if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushcreatures')) { if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canpushcreatures')) {
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canpushcreatures` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canpushitems`;"); $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canpushcreatures` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canpushitems`;");
} }
if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonenergy')) { if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonenergy')) {
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonenergy` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canpushitems`;"); $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonenergy` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canpushitems`;");
} }
if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonpoison')) { if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonpoison')) {
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonpoison` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonenergy`;"); $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonpoison` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonenergy`;");
} }
if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonfire')) { if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'canwalkonfire')) {
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonfire` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonpoison`;"); $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `canwalkonfire` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonpoison`;");
} }
if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'runonhealth')) { if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'runonhealth')) {
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `runonhealth` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonfire`;"); $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `runonhealth` TINYINT(1) NOT NULL DEFAULT '0' AFTER `canwalkonfire`;");
} }
if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'hostile')) { if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'hostile')) {
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `hostile` TINYINT(1) NOT NULL DEFAULT '0' AFTER `runonhealth`;"); $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `hostile` TINYINT(1) NOT NULL DEFAULT '0' AFTER `runonhealth`;");
} }
if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'attackable')) { if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'attackable')) {
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `attackable` TINYINT(1) NOT NULL DEFAULT '0' AFTER `hostile`;"); $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `attackable` TINYINT(1) NOT NULL DEFAULT '0' AFTER `hostile`;");
} }
if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'rewardboss')) { if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'rewardboss')) {
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `rewardboss` TINYINT(1) NOT NULL DEFAULT '0' AFTER `attackable`;"); $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `rewardboss` TINYINT(1) NOT NULL DEFAULT '0' AFTER `attackable`;");
} }
if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'defense')) { if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'defense')) {
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `defense` INT(11) NOT NULL DEFAULT '0' AFTER `rewardboss`;"); $db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `defense` INT(11) NOT NULL DEFAULT '0' AFTER `rewardboss`;");
} }
if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'armor')) { if(!$db->hasColumn(TABLE_PREFIX . 'monsters', 'armor')) {
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "monsters` ADD `armor` INT(11) NOT NULL DEFAULT '0' AFTER `defense`;"); $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`;");
}

View File

@ -1,4 +1,10 @@
<?php <?php
// Increase size of page in myaac_visitors table // Increase size of page in myaac_visitors table
$db->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
};

View File

@ -3,4 +3,10 @@
// according to this answer: https://stackoverflow.com/questions/166132/maximum-length-of-the-textual-representation-of-an-ipv6-address // 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 // 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
};

View File

@ -1,4 +1,10 @@
<?php <?php
// add user_agent column into visitors // add user_agent column into visitors
$db->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`;");
};

View File

@ -1,3 +1,10 @@
<?php <?php
// add look column // add look column
$db->exec('ALTER TABLE `' . TABLE_PREFIX . "monsters` ADD `look` VARCHAR(255) NOT NULL DEFAULT '' AFTER `health`;"); $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`;");
};

View File

@ -1,14 +1,20 @@
<?php <?php
// add settings table $up = function () use ($db) {
if(!$db->hasTable(TABLE_PREFIX . 'settings')) { // add settings table
$db->exec("CREATE TABLE `" . TABLE_PREFIX . "settings` 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 '', `id` int(11) NOT NULL AUTO_INCREMENT,
`key` VARCHAR(255) NOT NULL DEFAULT '', `name` VARCHAR(255) NOT NULL DEFAULT '',
`value` TEXT NOT NULL, `key` VARCHAR(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`), `value` TEXT NOT NULL,
KEY `key` (`key`) PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;"); KEY `key` (`key`)
} ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;");
}
};
$down = function () use ($db) {
$db->exec("DROP TABLE IF EXISTS `" . TABLE_PREFIX . "settings`");
};

View File

@ -5,4 +5,10 @@
use MyAAC\Models\Pages; 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]);
};

View File

@ -2,4 +2,11 @@
// 2023-11-11 // 2023-11-11
// execute highscores_ids_hidden once again, cause of settings // 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
};

View File

@ -3,16 +3,34 @@
// 2024-01-27 // 2024-01-27
// change hidden to hide (Eloquent model reserved keyword) // change hidden to hide (Eloquent model reserved keyword)
if (!$db->hasColumn('players', 'hide')) { $up = function () use ($db) {
$db->exec("ALTER TABLE `players` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;"); 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 . "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 . "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 . "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 . "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` 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 . "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 . "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 . "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 . "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;");
};

View File

@ -5,8 +5,19 @@
use MyAAC\Models\Menu; use MyAAC\Models\Menu;
Menu::where('link', 'lastkills')->update(['link' => 'last-kills']); $up = function() {
Menu::where('link', 'serverInfo')->update(['link' => 'server-info']); Menu::where('link', 'lastkills')->update(['link' => 'last-kills']);
Menu::where('link', 'experienceStages')->update(['link' => 'exp-stages']); Menu::where('link', 'serverInfo')->update(['link' => 'server-info']);
Menu::where('link', 'experienceTable')->update(['link' => 'exp-table']); Menu::where('link', 'experienceStages')->update(['link' => 'exp-stages']);
Menu::where('link', 'creatures')->update(['link' => 'monsters']); 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']);
};