46 lines
2 KiB
PHP
46 lines
2 KiB
PHP
<?php
|
|
use Index\Db\DbConnection;
|
|
use Index\Db\Migration\DbMigration;
|
|
|
|
final class ExistingStructure_20230816_161818 implements DbMigration {
|
|
public function migrate(DbConnection $conn): void {
|
|
$hasWhiteList2020 = false;
|
|
$hasWhiteList2022 = false;
|
|
|
|
// check if the old tables exist
|
|
$tables = $conn->query('SHOW TABLES');
|
|
while($tables->next()) {
|
|
$tableName = $tables->getString(0);
|
|
if($tableName === 'whitelist')
|
|
$hasWhiteList2020 = true;
|
|
elseif($tableName === 'whitelist_2022')
|
|
$hasWhiteList2022 = true;
|
|
if($hasWhiteList2020 && $hasWhiteList2022)
|
|
break;
|
|
}
|
|
|
|
if(!$hasWhiteList2020)
|
|
$conn->execute('
|
|
CREATE TABLE whitelist (
|
|
flashii_id INT(10) UNSIGNED NOT NULL,
|
|
minecraft_username VARCHAR(255) NOT NULL COLLATE "utf8mb4_unicode_ci",
|
|
whitelist_added TIMESTAMP NOT NULL DEFAULT current_timestamp(),
|
|
UNIQUE KEY whitelist_unique (flashii_id, minecraft_username),
|
|
KEY whitelist_flashii_key (flashii_id),
|
|
KEY whitelist_minecraft_key (minecraft_username)
|
|
) ENGINE=InnoDB COLLATE="latin1_swedish_ci";
|
|
');
|
|
|
|
if(!$hasWhiteList2022)
|
|
$conn->execute('
|
|
CREATE TABLE whitelist_2022 (
|
|
flashii_id INT(10) UNSIGNED NOT NULL,
|
|
minecraft_username VARCHAR(255) NOT NULL COLLATE "utf8mb4_unicode_ci",
|
|
whitelist_added TIMESTAMP NOT NULL DEFAULT current_timestamp(),
|
|
UNIQUE KEY whitelist_2022_unique (flashii_id, minecraft_username),
|
|
KEY whitelist_2022_flashii_key (flashii_id),
|
|
KEY whitelist_2022_minecraft_key (minecraft_username)
|
|
) ENGINE=InnoDB COLLATE="latin1_swedish_ci";
|
|
');
|
|
}
|
|
}
|