100 lines
4.4 KiB
PHP
100 lines
4.4 KiB
PHP
<?php
|
|
use Index\Db\DbConnection;
|
|
use Index\Db\Migration\DbMigration;
|
|
|
|
final class CreateNewTables_20230822_231052 implements DbMigration {
|
|
public function migrate(DbConnection $conn): void {
|
|
$conn->execute('
|
|
CREATE TABLE verifications (
|
|
verify_code BINARY(10) NOT NULL,
|
|
verify_uuid BINARY(16) NOT NULL,
|
|
verify_name VARCHAR(255) NOT NULL COLLATE "ascii_bin",
|
|
verify_addr VARBINARY(16) NOT NULL,
|
|
verify_created TIMESTAMP NOT NULL DEFAULT current_timestamp(),
|
|
PRIMARY KEY (verify_code),
|
|
UNIQUE KEY verifications_uuid_unique (verify_uuid),
|
|
UNIQUE KEY verifications_name_unique (verify_name),
|
|
KEY verifications_created_index (verify_created)
|
|
) ENGINE=InnoDB COLLATE=utf8mb4_bin
|
|
');
|
|
|
|
$conn->execute('
|
|
CREATE TABLE users (
|
|
user_id INT(10) UNSIGNED NOT NULL,
|
|
user_name VARCHAR(255) NOT NULL COLLATE "utf8mb4_unicode_520_ci",
|
|
user_colour INT(10) UNSIGNED NULL DEFAULT NULL,
|
|
PRIMARY KEY (user_id)
|
|
) ENGINE=InnoDB COLLATE=utf8mb4_bin
|
|
');
|
|
|
|
$conn->execute('
|
|
CREATE TABLE links (
|
|
user_id INT(10) UNSIGNED NOT NULL,
|
|
link_uuid BINARY(16) NOT NULL,
|
|
link_name VARCHAR(255) NOT NULL COLLATE "ascii_bin",
|
|
link_created TIMESTAMP NOT NULL DEFAULT current_timestamp(),
|
|
UNIQUE KEY links_user_foreign (user_id),
|
|
UNIQUE KEY links_uuid_unique (link_uuid),
|
|
UNIQUE KEY links_name_unique (link_name),
|
|
CONSTRAINT links_user_foreign
|
|
FOREIGN KEY (user_id)
|
|
REFERENCES users (user_id)
|
|
ON UPDATE CASCADE
|
|
ON DELETE CASCADE
|
|
) ENGINE=InnoDB COLLATE=utf8mb4_bin
|
|
');
|
|
|
|
$conn->execute('
|
|
CREATE TABLE authorisations (
|
|
auth_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
auth_uuid BINARY(16) NOT NULL,
|
|
auth_addr VARBINARY(16) NOT NULL,
|
|
auth_requested TIMESTAMP NOT NULL DEFAULT current_timestamp(),
|
|
auth_granted TIMESTAMP NULL DEFAULT NULL,
|
|
auth_used TIMESTAMP NULL DEFAULT NULL,
|
|
PRIMARY KEY (auth_id),
|
|
UNIQUE KEY authorisations_unique (auth_uuid, auth_addr),
|
|
KEY authorisations_uuid_foreign (auth_uuid),
|
|
KEY authorisations_granted_index (auth_granted),
|
|
KEY authorisations_requested_index (auth_requested),
|
|
KEY authorisations_used_index (auth_used),
|
|
CONSTRAINT authorisations_uuid_foreign
|
|
FOREIGN KEY (auth_uuid)
|
|
REFERENCES links (link_uuid)
|
|
ON UPDATE CASCADE
|
|
ON DELETE CASCADE
|
|
) ENGINE=InnoDB COLLATE=utf8mb4_bin
|
|
');
|
|
|
|
$conn->execute('
|
|
CREATE TABLE skins (
|
|
user_id INT(10) UNSIGNED NOT NULL,
|
|
skin_hash BINARY(32) NOT NULL,
|
|
skin_model ENUM("classic", "slim") NOT NULL COLLATE "ascii_general_ci",
|
|
skin_updated TIMESTAMP NOT NULL DEFAULT current_timestamp(),
|
|
UNIQUE KEY skins_user_foreign (user_id),
|
|
KEY skins_hash_index (skin_hash),
|
|
CONSTRAINT skins_user_foreign
|
|
FOREIGN KEY (user_id)
|
|
REFERENCES users (user_id)
|
|
ON UPDATE CASCADE
|
|
ON DELETE CASCADE
|
|
) ENGINE=InnoDB COLLATE=utf8mb4_bin
|
|
');
|
|
|
|
$conn->execute('
|
|
CREATE TABLE capes (
|
|
user_id INT(10) UNSIGNED NOT NULL,
|
|
cape_hash BINARY(32) NOT NULL,
|
|
cape_updated TIMESTAMP NOT NULL DEFAULT current_timestamp(),
|
|
UNIQUE KEY capes_user_foreign (user_id),
|
|
KEY capes_hash_index (cape_hash),
|
|
CONSTRAINT capes_user_foreign
|
|
FOREIGN KEY (user_id)
|
|
REFERENCES users (user_id)
|
|
ON UPDATE CASCADE
|
|
ON DELETE CASCADE
|
|
) ENGINE=InnoDB COLLATE=utf8mb4_bin
|
|
');
|
|
}
|
|
}
|