Refactor migrations with $up & $down

This commit is contained in:
slawkens
2024-11-08 07:04:24 +01:00
parent c7cb00f8da
commit 8aff9f36fb
49 changed files with 842 additions and 370 deletions

View File

@@ -1,10 +1,17 @@
<?php
/**
* @var OTS_DB_MySQL $db
*/
// add look column
$up = function () use ($db) {
$db->exec('ALTER TABLE `' . TABLE_PREFIX . "monsters` ADD `look` VARCHAR(255) NOT NULL DEFAULT '' AFTER `health`;");
if (!$db->hasColumn(TABLE_PREFIX . 'monsters', 'look')) {
$db->addColumn(TABLE_PREFIX . 'monsters', 'look', "VARCHAR(255) NOT NULL DEFAULT '' AFTER `health`");
}
};
$down = function () use ($db) {
$db->exec('ALTER TABLE `' . TABLE_PREFIX . "monsters` DROP COLUMN `look`;");
if ($db->hasColumn(TABLE_PREFIX . 'monsters', 'look')) {
$db->dropColumn(TABLE_PREFIX . 'monsters', 'look');
}
};