misuzu/database/2025_02_01_181944_create_apps_tables.php

54 lines
2.8 KiB
PHP

<?php
use Index\Db\DbConnection;
use Index\Db\Migration\DbMigration;
final class CreateAppsTables_20250201_181944 implements DbMigration {
public function migrate(DbConnection $conn): void {
$conn->execute(<<<SQL
CREATE TABLE msz_apps (
app_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
user_id INT(10) UNSIGNED NULL DEFAULT NULL,
app_name VARCHAR(64) NOT NULL COLLATE 'utf8mb4_unicode_520_ci',
app_summary VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin',
app_website VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin',
app_type ENUM('public','confidential','trusted') NOT NULL COLLATE 'ascii_general_ci',
app_access_lifetime INT(10) UNSIGNED NULL DEFAULT NULL,
app_refresh_lifetime INT(10) UNSIGNED NULL DEFAULT NULL,
app_client_id CHAR(20) NOT NULL COLLATE 'ascii_bin',
app_client_secret VARCHAR(255) NOT NULL COLLATE 'ascii_bin',
app_created TIMESTAMP NOT NULL DEFAULT current_timestamp(),
app_updated TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
app_deleted TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (app_id),
UNIQUE INDEX apps_client_id_unique (app_client_id),
UNIQUE INDEX apps_name_unique (app_name),
INDEX apps_user_foreign (user_id),
INDEX apps_created_index (app_created),
INDEX apps_deleted_index (app_deleted),
CONSTRAINT apps_user_foreign
FOREIGN KEY (user_id)
REFERENCES msz_users (user_id)
ON UPDATE CASCADE
ON DELETE CASCADE
) COLLATE='utf8mb4_bin' ENGINE=InnoDB;
SQL);
$conn->execute(<<<SQL
CREATE TABLE msz_apps_uris (
uri_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
app_id INT(10) UNSIGNED NOT NULL,
uri_string VARCHAR(255) NOT NULL COLLATE 'ascii_bin',
uri_created TIMESTAMP NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (uri_id),
INDEX apps_uris_app_foreign (app_id),
INDEX apps_uris_lookup_index (uri_id, uri_string),
INDEX apps_uri_created_index (uri_created),
CONSTRAINT apps_uris_app_foreign
FOREIGN KEY (app_id)
REFERENCES msz_apps (app_id)
ON UPDATE CASCADE
ON DELETE CASCADE
) COLLATE='utf8mb4_bin' ENGINE=InnoDB;
SQL);
}
}