-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Migrations up down * Add forum model * Syntactic sugar for db structure changes * Refactor migrations with $up & $down * Fix migrations upgrade and downgrade + Add option to disable auto migrate * Add migrate:to command Usage: php aac migrate:to x (x - database version) * Show error when mail is not enabled * Fixes regarding to init.php * Add migrate command to manually upgrade db, incase auto migrate is disabled * Fixed rest of the migrations * Limit max version of database * Don't allow minus number * Option to clear specified plugin settings by name * Version is required * Fix PHPStan errors * Unset $up after migration, to prevent executing same migration twice * Add database version to output * This is not needed * Update 5.php * Set database_auto_migrate on install * Set blank & color only if current db version supports it * Fix duplicate function declaration
- Loading branch information
Showing
72 changed files
with
1,268 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE `myaac_hooks` | ||
( | ||
`id` INT(11) NOT NULL AUTO_INCREMENT, | ||
`name` VARCHAR(30) NOT NULL DEFAULT '', | ||
`type` INT(2) NOT NULL DEFAULT 0, | ||
`file` VARCHAR(100) NOT NULL, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
<?php | ||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` MODIFY `ip` INT(11) NOT NULL DEFAULT 0;"); | ||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` MODIFY `date` INT(11) NOT NULL DEFAULT 0;"); | ||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` MODIFY `action` VARCHAR(255) NOT NULL DEFAULT '';"); | ||
$db->query(" | ||
CREATE TABLE `myaac_hooks` | ||
( | ||
`id` INT(11) NOT NULL AUTO_INCREMENT, | ||
`name` VARCHAR(30) NOT NULL DEFAULT '', | ||
`type` INT(2) NOT NULL DEFAULT 0, | ||
`file` VARCHAR(100) NOT NULL, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; | ||
"); | ||
/** | ||
* @var OTS_DB_MySQL $db | ||
*/ | ||
|
||
?> | ||
$up = function () use ($db) { | ||
$db->modifyColumn(TABLE_PREFIX . 'account_actions', 'ip', "INT(11) NOT NULL DEFAULT 0"); | ||
$db->modifyColumn(TABLE_PREFIX . 'account_actions', 'date', "INT(11) NOT NULL DEFAULT 0"); | ||
$db->modifyColumn(TABLE_PREFIX . 'account_actions', 'action', "VARCHAR(255) NOT NULL DEFAULT ''"); | ||
|
||
$db->query(file_get_contents(__DIR__ . '/1-hooks.sql')); | ||
}; | ||
|
||
$down = function () use ($db) { | ||
$db->dropTable(TABLE_PREFIX . 'hooks'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE `myaac_admin_menu` | ||
( | ||
`id` INT(11) NOT NULL AUTO_INCREMENT, | ||
`name` VARCHAR(255) NOT NULL DEFAULT '', | ||
`page` VARCHAR(255) NOT NULL DEFAULT '', | ||
`ordering` INT(11) NOT NULL DEFAULT 0, | ||
`flags` INT(11) NOT NULL DEFAULT 0, | ||
`enabled` INT(1) NOT NULL DEFAULT 1, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
<?php | ||
if(!$db->hasColumn(TABLE_PREFIX . 'hooks', 'ordering')) | ||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "hooks` ADD `ordering` INT(11) NOT NULL DEFAULT 0 AFTER `file`;"); | ||
/** | ||
* @var OTS_DB_MySQL $db | ||
*/ | ||
|
||
if(!$db->hasTable(TABLE_PREFIX . 'admin_menu')) | ||
$db->query(" | ||
CREATE TABLE `myaac_admin_menu` | ||
( | ||
`id` INT(11) NOT NULL AUTO_INCREMENT, | ||
`name` VARCHAR(255) NOT NULL DEFAULT '', | ||
`page` VARCHAR(255) NOT NULL DEFAULT '', | ||
`ordering` INT(11) NOT NULL DEFAULT 0, | ||
`flags` INT(11) NOT NULL DEFAULT 0, | ||
`enabled` INT(1) NOT NULL DEFAULT 1, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; | ||
"); | ||
$up = function () use ($db) { | ||
if (!$db->hasColumn(TABLE_PREFIX . 'hooks', 'ordering')) { | ||
$db->addColumn(TABLE_PREFIX . 'hooks', 'ordering', "INT(11) NOT NULL DEFAULT 0 AFTER `file`"); | ||
} | ||
|
||
if (!$db->hasTable(TABLE_PREFIX . 'admin_menu')) { | ||
$db->query(file_get_contents(__DIR__ . '/10-admin_menu.sql')); | ||
} | ||
}; | ||
|
||
$down = function () use ($db) { | ||
if ($db->hasColumn(TABLE_PREFIX . 'hooks', 'ordering')) { | ||
$db->dropColumn(TABLE_PREFIX . 'hooks', 'ordering'); | ||
} | ||
|
||
if ($db->hasTable(TABLE_PREFIX . 'admin_menu')) { | ||
$db->dropTable(TABLE_PREFIX . 'admin_menu'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,44 @@ | ||
<?php | ||
/** | ||
* @var OTS_DB_MySQL $db | ||
*/ | ||
|
||
$up = function () use ($db) { | ||
// rename database tables | ||
$db->query("RENAME TABLE | ||
" . TABLE_PREFIX . "screenshots TO " . TABLE_PREFIX . "gallery, | ||
" . TABLE_PREFIX . "movies TO " . TABLE_PREFIX . "videos;"); | ||
$db->renameTable(TABLE_PREFIX . 'screenshots', TABLE_PREFIX . 'gallery'); | ||
$db->renameTable(TABLE_PREFIX . 'movies', TABLE_PREFIX . 'videos'); | ||
|
||
// rename images dir | ||
if(file_exists(BASE . 'images/screenshots') && !file_exists(BASE . GALLERY_DIR)) { | ||
if (file_exists(BASE . 'images/screenshots') && !file_exists(BASE . GALLERY_DIR)) { | ||
rename(BASE . 'images/screenshots', BASE . GALLERY_DIR); | ||
} | ||
|
||
// convert old database screenshots images to gallery | ||
$query = $db->query('SELECT `id`, `image`, `thumb` FROM `' . TABLE_PREFIX . 'gallery`;'); | ||
foreach($query->fetchAll() as $item) { | ||
foreach ($query->fetchAll() as $item) { | ||
$db->update(TABLE_PREFIX . 'gallery', array( | ||
'image' => str_replace('/screenshots/', '/gallery/', $item['image']), | ||
'thumb' => str_replace('/screenshots/', '/gallery/', $item['thumb']), | ||
), array('id' => $item['id'])); | ||
} | ||
}; | ||
|
||
$down = function () use ($db) { | ||
// rename database tables | ||
$db->renameTable(TABLE_PREFIX . 'gallery', TABLE_PREFIX . 'screenshots'); | ||
$db->renameTable(TABLE_PREFIX . 'videos', TABLE_PREFIX . 'movies'); | ||
|
||
// rename images dir | ||
if (file_exists(BASE . GALLERY_DIR) && !file_exists(BASE . 'images/screenshots')) { | ||
rename(BASE . GALLERY_DIR, BASE . 'images/screenshots'); | ||
} | ||
|
||
// convert new database gallery images to screenshots | ||
$query = $db->query('SELECT `id`, `image`, `thumb` FROM `' . TABLE_PREFIX . 'screenshots`;'); | ||
foreach ($query->fetchAll() as $item) { | ||
$db->update(TABLE_PREFIX . 'screenshots', [ | ||
'image' => str_replace('/gallery/', '/screenshots/', $item['image']), | ||
'thumb' => str_replace('/gallery/', '/screenshots/', $item['thumb']), | ||
], ['id' => $item['id']]); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CREATE TABLE `myaac_items` | ||
( | ||
`id` INT(11) NOT NULL, | ||
`article` VARCHAR(5) NOT NULL DEFAULT '', | ||
`name` VARCHAR(50) NOT NULL DEFAULT '', | ||
`plural` VARCHAR(50) NOT NULL DEFAULT '', | ||
`attributes` VARCHAR(500) NOT NULL DEFAULT '', | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE `myaac_weapons` | ||
( | ||
`id` INT(11) NOT NULL, | ||
`level` INT(11) NOT NULL DEFAULT 0, | ||
`maglevel` INT(11) NOT NULL DEFAULT 0, | ||
`vocations` VARCHAR(100) NOT NULL DEFAULT '', | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,65 @@ | ||
<?php | ||
/** | ||
* @var OTS_DB_MySQL $db | ||
*/ | ||
|
||
// add new item_id field for runes | ||
if(!$db->hasColumn(TABLE_PREFIX . 'spells', 'item_id')) | ||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` ADD `item_id` INT(11) NOT NULL DEFAULT 0 AFTER `conjure_count`;"); | ||
|
||
// change unique index from spell to name | ||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` DROP INDEX `spell`;"); | ||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` ADD UNIQUE INDEX (`name`);"); | ||
|
||
// change comment of spells.type | ||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` MODIFY `type` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '1 - instant, 2 - conjure, 3 - rune';"); | ||
|
||
// new items table | ||
if(!$db->hasTable(TABLE_PREFIX . 'items')) | ||
$db->query(" | ||
CREATE TABLE `" . TABLE_PREFIX . "items` | ||
( | ||
`id` INT(11) NOT NULL, | ||
`article` VARCHAR(5) NOT NULL DEFAULT '', | ||
`name` VARCHAR(50) NOT NULL DEFAULT '', | ||
`plural` VARCHAR(50) NOT NULL DEFAULT '', | ||
`attributes` VARCHAR(500) NOT NULL DEFAULT '', | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; | ||
"); | ||
|
||
// new weapons table | ||
if(!$db->hasTable(TABLE_PREFIX . 'weapons')) | ||
$db->query(" | ||
CREATE TABLE `" . TABLE_PREFIX . "weapons` | ||
( | ||
`id` INT(11) NOT NULL, | ||
`level` INT(11) NOT NULL DEFAULT 0, | ||
`maglevel` INT(11) NOT NULL DEFAULT 0, | ||
`vocations` VARCHAR(100) NOT NULL DEFAULT '', | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8; | ||
"); | ||
|
||
// modify vocations to support json data | ||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` MODIFY `vocations` VARCHAR(100) NOT NULL DEFAULT '';"); | ||
$query = $db->query('SELECT `id`, `vocations` FROM `' . TABLE_PREFIX . 'spells`'); | ||
foreach($query->fetchAll() as $spell) { | ||
$tmp = explode(',', $spell['vocations']); | ||
foreach($tmp as &$v) { | ||
$v = (int)$v; | ||
use MyAAC\Models\Spell; | ||
|
||
$up = function () use ($db) { | ||
// add new item_id field for runes | ||
if (!$db->hasColumn(TABLE_PREFIX . 'spells', 'item_id')) { | ||
$db->addColumn(TABLE_PREFIX . 'spells', 'item_id', 'INT(11) NOT NULL DEFAULT 0 AFTER `conjure_count`'); | ||
} | ||
|
||
// change unique index from spell to name | ||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` DROP INDEX `spell`;"); | ||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` ADD UNIQUE INDEX (`name`);"); | ||
|
||
// change comment of spells.type | ||
$db->modifyColumn(TABLE_PREFIX . 'spells', 'type', "TINYINT(1) NOT NULL DEFAULT 0 COMMENT '1 - instant, 2 - conjure, 3 - rune'"); | ||
|
||
// new items table | ||
if (!$db->hasTable(TABLE_PREFIX . 'items')) { | ||
$db->query(file_get_contents(__DIR__ . '/12-items.sql')); | ||
} | ||
|
||
// new weapons table | ||
if (!$db->hasTable(TABLE_PREFIX . 'weapons')) { | ||
$db->query(file_get_contents(__DIR__ . '/12-weapons.sql')); | ||
} | ||
|
||
// modify vocations to support json data | ||
$db->modifyColumn(TABLE_PREFIX . 'spells', 'vocations', "VARCHAR(100) NOT NULL DEFAULT ''"); | ||
|
||
$spells = Spell::select('id', 'vocations')->get(); | ||
foreach ($spells as $spell) { | ||
$tmp = explode(',', $spell->vocations); | ||
foreach ($tmp as &$v) { | ||
$v = (int)$v; | ||
} | ||
|
||
Spell::where('id', $spell->id)->update(['vocations' => json_encode($tmp)]); | ||
} | ||
}; | ||
|
||
$down = function () use ($db) { | ||
// remove item_id field for runes | ||
if ($db->hasColumn(TABLE_PREFIX . 'spells', 'item_id')) { | ||
$db->dropColumn(TABLE_PREFIX . 'spells', 'item_id'); | ||
} | ||
|
||
// change unique index from spell to name | ||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` DROP INDEX `name`;"); | ||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "spells` ADD INDEX (`spell`);"); | ||
|
||
$db->dropTable(TABLE_PREFIX . 'items'); | ||
$db->dropTable(TABLE_PREFIX . 'weapons'); | ||
|
||
$spells = Spell::select('id', 'vocations')->get(); | ||
// modify vocations to use vocation separated by comma | ||
foreach ($spells as $spell) { | ||
$vocations = empty($spell->vocations) ? [] : json_decode($spell->vocations); | ||
|
||
Spell::where('id', $spell->id)->update(['vocations' => implode(',', $vocations)]); | ||
} | ||
$db->update(TABLE_PREFIX . 'spells', array('vocations' => json_encode($tmp)), array('id' => $spell['id'])); | ||
} | ||
?> | ||
}; |
Oops, something went wrong.