34 lines
1.3 KiB
PHP
34 lines
1.3 KiB
PHP
|
<?php
|
||
|
namespace Misuzu\DatabaseMigrations\NukeRelationsTable;
|
||
|
|
||
|
use PDO;
|
||
|
|
||
|
function migrate_up(PDO $conn): void {
|
||
|
$conn->exec("DROP TABLE `msz_user_relations`");
|
||
|
}
|
||
|
|
||
|
function migrate_down(PDO $conn): void {
|
||
|
$conn->exec("
|
||
|
CREATE TABLE `msz_user_relations` (
|
||
|
`user_id` INT(10) UNSIGNED NOT NULL,
|
||
|
`subject_id` INT(10) UNSIGNED NOT NULL,
|
||
|
`relation_type` TINYINT(3) UNSIGNED NOT NULL,
|
||
|
`relation_created` TIMESTAMP NOT NULL DEFAULT current_timestamp(),
|
||
|
UNIQUE INDEX `user_relations_unique` (`user_id`, `subject_id`) USING BTREE,
|
||
|
INDEX `user_relations_subject_id_foreign` (`subject_id`) USING BTREE,
|
||
|
INDEX `user_relations_type_index` (`relation_type`) USING BTREE,
|
||
|
INDEX `user_relations_created_index` (`relation_created`) USING BTREE,
|
||
|
CONSTRAINT `user_relations_subject_id_foreign`
|
||
|
FOREIGN KEY (`subject_id`)
|
||
|
REFERENCES `msz_users` (`user_id`)
|
||
|
ON UPDATE CASCADE
|
||
|
ON DELETE CASCADE,
|
||
|
CONSTRAINT `user_relations_user_id_foreign`
|
||
|
FOREIGN KEY (`user_id`)
|
||
|
REFERENCES `msz_users` (`user_id`)
|
||
|
ON UPDATE CASCADE
|
||
|
ON DELETE CASCADE
|
||
|
) COLLATE='utf8mb4_bin' ENGINE=InnoDB;
|
||
|
");
|
||
|
}
|