diff --git a/database/2018_05_16_155840_initial_structure.php b/database/2018_05_16_155840_initial_structure.php deleted file mode 100644 index 37711cbd..00000000 --- a/database/2018_05_16_155840_initial_structure.php +++ /dev/null @@ -1,171 +0,0 @@ -exec(" - CREATE TABLE `msz_roles` ( - `role_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `role_hierarchy` INT(11) NOT NULL DEFAULT '1', - `role_name` VARCHAR(255) NOT NULL, - `role_title` VARCHAR(64) NULL DEFAULT NULL, - `role_description` TEXT NULL, - `role_secret` TINYINT(1) NOT NULL DEFAULT '0', - `role_colour` INT(11) NOT NULL DEFAULT '0', - `created_at` TIMESTAMP NULL DEFAULT NULL, - `updated_at` TIMESTAMP NULL DEFAULT NULL, - PRIMARY KEY (`role_id`) - ) - "); - - $conn->exec(" - CREATE TABLE `msz_users` ( - `user_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `username` VARCHAR(255) NOT NULL, - `password` VARCHAR(255) NULL DEFAULT NULL, - `email` VARCHAR(255) NOT NULL, - `register_ip` VARBINARY(16) NOT NULL, - `last_ip` VARBINARY(16) NOT NULL, - `user_country` CHAR(2) NOT NULL DEFAULT 'XX', - `user_chat_key` VARCHAR(32) NULL DEFAULT NULL, - `created_at` TIMESTAMP NULL DEFAULT NULL, - `updated_at` TIMESTAMP NULL DEFAULT NULL, - `deleted_at` TIMESTAMP NULL DEFAULT NULL, - `display_role` INT(10) UNSIGNED NULL DEFAULT NULL, - `user_website` VARCHAR(255) NOT NULL DEFAULT '', - `user_twitter` VARCHAR(20) NOT NULL DEFAULT '', - `user_github` VARCHAR(40) NOT NULL DEFAULT '', - `user_skype` VARCHAR(60) NOT NULL DEFAULT '', - `user_discord` VARCHAR(40) NOT NULL DEFAULT '', - `user_youtube` VARCHAR(255) NOT NULL DEFAULT '', - `user_steam` VARCHAR(255) NOT NULL DEFAULT '', - `user_twitchtv` VARCHAR(30) NOT NULL DEFAULT '', - `user_osu` VARCHAR(20) NOT NULL DEFAULT '', - `user_lastfm` VARCHAR(20) NOT NULL DEFAULT '', - `user_title` VARCHAR(64) NULL DEFAULT NULL, - `last_seen` TIMESTAMP NULL DEFAULT NULL, - PRIMARY KEY (`user_id`), - UNIQUE INDEX `users_username_unique` (`username`), - UNIQUE INDEX `users_email_unique` (`email`), - INDEX `users_display_role_foreign` (`display_role`), - CONSTRAINT `users_display_role_foreign` - FOREIGN KEY (`display_role`) - REFERENCES `msz_roles` (`role_id`) - ON UPDATE CASCADE - ON DELETE SET NULL - ) - "); - - $conn->exec(" - CREATE TABLE `msz_user_roles` ( - `user_id` INT(10) UNSIGNED NOT NULL, - `role_id` INT(10) UNSIGNED NOT NULL, - UNIQUE INDEX `user_roles_unique` (`user_id`, `role_id`), - INDEX `user_roles_role_id_foreign` (`role_id`), - CONSTRAINT `user_roles_role_id_foreign` - FOREIGN KEY (`role_id`) - REFERENCES `msz_roles` (`role_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `user_roles_user_id_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - ) - "); - - $conn->exec(" - CREATE TABLE `msz_sessions` ( - `session_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `user_id` INT(10) UNSIGNED NOT NULL, - `session_key` VARCHAR(255) NOT NULL, - `session_ip` VARBINARY(16) NOT NULL, - `user_agent` VARCHAR(255) NULL DEFAULT NULL, - `expires_on` TIMESTAMP NULL DEFAULT NULL, - `created_at` TIMESTAMP NULL DEFAULT NULL, - `updated_at` TIMESTAMP NULL DEFAULT NULL, - `session_country` CHAR(2) NOT NULL DEFAULT 'XX', - PRIMARY KEY (`session_id`), - INDEX `sessions_user_id_foreign` (`user_id`), - CONSTRAINT `sessions_user_id_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - ) - "); - - $conn->exec(" - CREATE TABLE `msz_login_attempts` ( - `attempt_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `was_successful` TINYINT(1) NOT NULL, - `attempt_ip` VARBINARY(16) NOT NULL, - `attempt_country` CHAR(2) NOT NULL DEFAULT 'XX', - `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `created_at` TIMESTAMP NULL DEFAULT NULL, - `updated_at` TIMESTAMP NULL DEFAULT NULL, - `user_agent` VARCHAR(255) NOT NULL DEFAULT '', - PRIMARY KEY (`attempt_id`), - INDEX `login_attempts_user_id_foreign` (`user_id`), - CONSTRAINT `login_attempts_user_id_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE SET NULL - ) - "); - - $conn->exec(" - CREATE TABLE `msz_news_categories` ( - `category_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `category_name` VARCHAR(255) NOT NULL, - `category_description` TEXT NOT NULL, - `is_hidden` TINYINT(1) NOT NULL DEFAULT '0', - `created_at` TIMESTAMP NULL DEFAULT NULL, - `updated_at` TIMESTAMP NULL DEFAULT NULL, - PRIMARY KEY (`category_id`) - ) - "); - - $conn->exec(" - CREATE TABLE `msz_news_posts` ( - `post_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `category_id` INT(10) UNSIGNED NOT NULL, - `is_featured` TINYINT(1) NOT NULL DEFAULT '0', - `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `post_title` VARCHAR(255) NOT NULL, - `post_text` TEXT NOT NULL, - `scheduled_for` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `created_at` TIMESTAMP NULL DEFAULT NULL, - `updated_at` TIMESTAMP NULL DEFAULT NULL, - `deleted_at` TIMESTAMP NULL DEFAULT NULL, - PRIMARY KEY (`post_id`), - INDEX `news_posts_category_id_foreign` (`category_id`), - INDEX `news_posts_user_id_foreign` (`user_id`), - CONSTRAINT `news_posts_category_id_foreign` - FOREIGN KEY (`category_id`) - REFERENCES `msz_news_categories` (`category_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `news_posts_user_id_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE SET NULL - ) - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec('DROP TABLE `msz_news_posts`'); - $conn->exec('DROP TABLE `msz_news_categories`'); - $conn->exec('DROP TABLE `msz_login_attempts`'); - $conn->exec('DROP TABLE `msz_sessions`'); - $conn->exec('DROP TABLE `msz_user_roles`'); - $conn->exec('DROP TABLE `msz_users`'); - $conn->exec('DROP TABLE `msz_roles`'); -} diff --git a/database/2018_05_17_000055_forum_structure.php b/database/2018_05_17_000055_forum_structure.php deleted file mode 100644 index 03b977f5..00000000 --- a/database/2018_05_17_000055_forum_structure.php +++ /dev/null @@ -1,124 +0,0 @@ -exec(" - CREATE TABLE `msz_forum_categories` ( - `forum_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `forum_order` INT(10) UNSIGNED NOT NULL DEFAULT '1', - `forum_parent` INT(10) UNSIGNED NOT NULL DEFAULT '0', - `forum_name` VARCHAR(255) NOT NULL, - `forum_type` TINYINT(4) NOT NULL DEFAULT '0', - `forum_description` TEXT NULL, - `forum_link` VARCHAR(255) NULL DEFAULT NULL, - `forum_link_clicks` INT(10) UNSIGNED NULL DEFAULT NULL, - `forum_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `forum_archived` TINYINT(1) NOT NULL DEFAULT '0', - `forum_hidden` TINYINT(1) NOT NULL DEFAULT '0', - PRIMARY KEY (`forum_id`), - INDEX `forums_indices` (`forum_order`, `forum_parent`, `forum_type`) - ) - "); - - $conn->exec(" - CREATE TABLE `msz_forum_topics` ( - `topic_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `forum_id` INT(10) UNSIGNED NOT NULL, - `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `topic_type` TINYINT(4) NOT NULL DEFAULT '0', - `topic_title` VARCHAR(255) NOT NULL, - `topic_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `topic_bumped` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `topic_deleted` TIMESTAMP NULL DEFAULT NULL, - `topic_locked` TIMESTAMP NULL DEFAULT NULL, - PRIMARY KEY (`topic_id`), - INDEX `topics_forum_id_foreign` (`forum_id`), - INDEX `topics_user_id_foreign` (`user_id`), - INDEX `topics_indices` (`topic_bumped`, `topic_type`), - CONSTRAINT `topics_forum_id_foreign` - FOREIGN KEY (`forum_id`) - REFERENCES `msz_forum_categories` (`forum_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `topics_user_id_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - ) - "); - - $conn->exec(" - CREATE TABLE `msz_forum_posts` ( - `post_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `topic_id` INT(10) UNSIGNED NOT NULL, - `forum_id` INT(10) UNSIGNED NOT NULL, - `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `post_ip` VARBINARY(16) NOT NULL, - `post_text` TEXT NOT NULL, - `post_parse` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0', - `post_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `post_edited` TIMESTAMP NULL DEFAULT NULL, - `post_deleted` TIMESTAMP NULL DEFAULT NULL, - PRIMARY KEY (`post_id`), - INDEX `posts_topic_id_foreign` (`topic_id`), - INDEX `posts_forum_id_foreign` (`forum_id`), - INDEX `posts_user_id_foreign` (`user_id`), - INDEX `posts_indices` (`post_created`), - CONSTRAINT `posts_topic_id_foreign` - FOREIGN KEY (`topic_id`) - REFERENCES `msz_forum_topics` (`topic_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `posts_forum_id_foreign` - FOREIGN KEY (`forum_id`) - REFERENCES `msz_forum_categories` (`forum_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `posts_user_id_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE SET NULL - ) - "); - - $conn->exec(" - CREATE TABLE `msz_forum_topics_track` ( - `user_id` INT(10) UNSIGNED NOT NULL, - `topic_id` INT(10) UNSIGNED NOT NULL, - `forum_id` INT(10) UNSIGNED NOT NULL, - `track_last_read` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - UNIQUE INDEX `topics_track_unique` (`user_id`, `topic_id`), - INDEX `topics_track_topic_id_foreign` (`topic_id`), - INDEX `topics_track_user_id_foreign` (`user_id`), - INDEX `topics_track_forum_id_foreign` (`forum_id`), - CONSTRAINT `topics_track_topic_id_foreign` - FOREIGN KEY (`topic_id`) - REFERENCES `msz_forum_topics` (`topic_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `topics_track_user_id_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `topics_track_forum_id_foreign` - FOREIGN KEY (`forum_id`) - REFERENCES `msz_forum_categories` (`forum_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - ) - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec('DROP TABLE `msz_forum_topics_track`'); - $conn->exec('DROP TABLE `msz_forum_posts`'); - $conn->exec('DROP TABLE `msz_forum_topics`'); - $conn->exec('DROP TABLE `msz_forum_categories`'); -} diff --git a/database/2018_07_06_031800_changelog_tables.php b/database/2018_07_06_031800_changelog_tables.php deleted file mode 100644 index 0cffd412..00000000 --- a/database/2018_07_06_031800_changelog_tables.php +++ /dev/null @@ -1,83 +0,0 @@ -exec(" - CREATE TABLE `msz_changelog_actions` ( - `action_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `action_name` VARCHAR(50) NOT NULL, - `action_colour` INT(10) UNSIGNED NOT NULL DEFAULT '0', - `action_class` VARCHAR(20) NOT NULL, - PRIMARY KEY (`action_id`), - UNIQUE INDEX `action_class_unique` (`action_class`) - ) - "); - - $conn->exec(" - CREATE TABLE `msz_changelog_changes` ( - `change_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `action_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `change_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `change_log` VARCHAR(255) NOT NULL, - `change_text` TEXT NULL, - PRIMARY KEY (`change_id`), - INDEX `changes_user_id_foreign` (`user_id`), - INDEX `changes_action_id_foreign` (`action_id`), - INDEX `changes_change_created_index` (`change_created`), - CONSTRAINT `changes_action_id_foreign` - FOREIGN KEY (`action_id`) - REFERENCES `msz_changelog_actions` (`action_id`) - ON UPDATE CASCADE - ON DELETE SET NULL, - CONSTRAINT `changes_user_id_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE SET NULL - ) - "); - - $conn->exec(" - CREATE TABLE `msz_changelog_tags` ( - `tag_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `tag_name` VARCHAR(255) NOT NULL, - `tag_description` TEXT NULL, - `tag_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `tag_archived` TIMESTAMP NULL DEFAULT NULL, - PRIMARY KEY (`tag_id`), - UNIQUE INDEX `tag_name` (`tag_name`), - INDEX `tag_archived` (`tag_archived`) - ) - "); - - $conn->exec(" - CREATE TABLE `msz_changelog_change_tags` ( - `change_id` INT(10) UNSIGNED NOT NULL, - `tag_id` INT(10) UNSIGNED NOT NULL, - INDEX `tag_id_foreign_key` (`tag_id`), - UNIQUE INDEX `change_tag_unique` (`change_id`, `tag_id`), - CONSTRAINT `change_id_foreign_key` - FOREIGN KEY (`change_id`) - REFERENCES `msz_changelog_changes` (`change_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `tag_id_foreign_key` - FOREIGN KEY (`tag_id`) - REFERENCES `msz_changelog_tags` (`tag_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - ) - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec('DROP TABLE `msz_changelog_change_tags`'); - $conn->exec('DROP TABLE `msz_changelog_tags`'); - $conn->exec('DROP TABLE `msz_changelog_changes`'); - $conn->exec('DROP TABLE `msz_changelog_actions`'); -} diff --git a/database/2018_07_08_212121_initial_permissions_table.php b/database/2018_07_08_212121_initial_permissions_table.php deleted file mode 100644 index 1b2eab8f..00000000 --- a/database/2018_07_08_212121_initial_permissions_table.php +++ /dev/null @@ -1,39 +0,0 @@ -exec(" - CREATE TABLE `msz_permissions` ( - `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `role_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `user_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', - `user_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', - `changelog_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', - `changelog_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', - `news_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', - `news_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', - UNIQUE INDEX `user_id` (`user_id`), - UNIQUE INDEX `role_id` (`role_id`), - CONSTRAINT `role_id_foreign` - FOREIGN KEY (`role_id`) - REFERENCES `msz_roles` (`role_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `user_id_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - ) - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec('DROP TABLE `msz_permissions`'); -} diff --git a/database/2018_07_10_212820_added_general_and_forum_perms.php b/database/2018_07_10_212820_added_general_and_forum_perms.php deleted file mode 100644 index b31d2370..00000000 --- a/database/2018_07_10_212820_added_general_and_forum_perms.php +++ /dev/null @@ -1,30 +0,0 @@ -exec(" - ALTER TABLE `msz_permissions` - ADD COLUMN `general_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `role_id`, - ADD COLUMN `general_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `general_perms_allow`, - ADD COLUMN `forum_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `news_perms_deny`, - ADD COLUMN `forum_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `forum_perms_allow`, - ADD COLUMN `comments_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `forum_perms_deny`, - ADD COLUMN `comments_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `comments_perms_allow`; - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(' - ALTER TABLE `msz_permissions` - DROP COLUMN `general_perms_allow`, - DROP COLUMN `general_perms_deny`, - DROP COLUMN `forum_perms_allow`, - DROP COLUMN `forum_perms_deny, - DROP COLUMN `forum_perms_allow`, - DROP COLUMN `forum_perms_deny`; - '); -} diff --git a/database/2018_07_11_175100_users_table_updates.php b/database/2018_07_11_175100_users_table_updates.php deleted file mode 100644 index f07a9c6c..00000000 --- a/database/2018_07_11_175100_users_table_updates.php +++ /dev/null @@ -1,28 +0,0 @@ -exec(" - ALTER TABLE `msz_users` - DROP COLUMN `updated_at`, - ADD INDEX `users_user_country_index` (`user_country`), - ADD INDEX `users_created_at_index` (`created_at`), - ADD INDEX `users_last_seen_index` (`last_seen`); - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(' - ALTER TABLE `msz_users` - ADD COLUMN `updated_at` TIMESTAMP NULL DEFAULT NULL, - DROP INDEX `users_user_country_index`, - DROP INDEX `users_created_at_index`, - DROP INDEX `users_last_seen_index`; - '); -} diff --git a/database/2018_07_17_170102_audit_log_struct.php b/database/2018_07_17_170102_audit_log_struct.php deleted file mode 100644 index e65a1168..00000000 --- a/database/2018_07_17_170102_audit_log_struct.php +++ /dev/null @@ -1,66 +0,0 @@ -exec(' - ALTER TABLE `msz_permissions` - RENAME INDEX `user_id` TO `permissions_user_id_unique`, - RENAME INDEX `role_id` TO `permissions_role_id_unique`, - DROP FOREIGN KEY `role_id_foreign`, - DROP FOREIGN KEY `user_id_foreign`, - ADD CONSTRAINT `permissions_user_id_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - ADD CONSTRAINT `permissions_role_id_foreign` - FOREIGN KEY (`role_id`) - REFERENCES `msz_roles` (`role_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - '); - - $conn->exec(" - CREATE TABLE `msz_audit_log` ( - `log_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `log_action` VARCHAR(50) NOT NULL, - `log_params` TEXT NOT NULL, - `log_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `log_ip` VARBINARY(16) NULL DEFAULT NULL, - PRIMARY KEY (`log_id`), - INDEX `audit_log_user_id_foreign` (`user_id`), - CONSTRAINT `audit_log_user_id_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - ) - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec('DROP TABLE `msz_audit_log`'); - - $conn->exec(' - ALTER TABLE `msz_permissions` - RENAME INDEX `permissions_user_id_unique` TO `user_id`, - RENAME INDEX `permissions_role_id_unique` TO `role_id`, - DROP FOREIGN KEY `permissions_user_id_foreign`, - DROP FOREIGN KEY `permissions_role_id_foreign`, - ADD CONSTRAINT `role_id_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - ADD CONSTRAINT `user_id_foreign` - FOREIGN KEY (`role_id`) - REFERENCES `msz_roles` (`role_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - '); -} diff --git a/database/2018_07_18_151413_add_user_colour_column.php b/database/2018_07_18_151413_add_user_colour_column.php deleted file mode 100644 index 88a50cbc..00000000 --- a/database/2018_07_18_151413_add_user_colour_column.php +++ /dev/null @@ -1,22 +0,0 @@ -exec(' - ALTER TABLE `msz_users` - ADD COLUMN `user_colour` INT(11) NULL DEFAULT NULL AFTER `user_country`, - DROP COLUMN `user_chat_key`; - '); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(' - ALTER TABLE `msz_users` - DROP COLUMN `user_colour`, - ADD COLUMN `user_chat_key` VARCHAR(32) NULL DEFAULT NULL AFTER `user_country`; - '); -} diff --git a/database/2018_07_22_000529_add_password_resets_table.php b/database/2018_07_22_000529_add_password_resets_table.php deleted file mode 100644 index 26fccfa1..00000000 --- a/database/2018_07_22_000529_add_password_resets_table.php +++ /dev/null @@ -1,28 +0,0 @@ -exec(' - CREATE TABLE `msz_users_password_resets` ( - `user_id` INT(10) UNSIGNED NOT NULL, - `reset_ip` VARBINARY(16) NOT NULL, - `reset_requested` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `verification_code` CHAR(12) NULL DEFAULT NULL, - UNIQUE INDEX `msz_users_password_resets_unique` (`user_id`, `reset_ip`), - INDEX `msz_users_password_resets_index` (`reset_requested`), - CONSTRAINT `msz_users_password_resets_user_id_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - ) - '); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec('DROP TABLE `msz_users_password_resets`'); -} diff --git a/database/2018_07_23_131728_add_country_to_audit_log.php b/database/2018_07_23_131728_add_country_to_audit_log.php deleted file mode 100644 index 74afe39f..00000000 --- a/database/2018_07_23_131728_add_country_to_audit_log.php +++ /dev/null @@ -1,20 +0,0 @@ -exec(' - ALTER TABLE `msz_audit_log` - ADD COLUMN `log_country` CHAR(2) NOT NULL DEFAULT \'XX\' AFTER `log_ip`; - '); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(' - ALTER TABLE `msz_audit_log` - DROP COLUMN `log_country`; - '); -} diff --git a/database/2018_07_25_194106_add_global_comments_stuff.php b/database/2018_07_25_194106_add_global_comments_stuff.php deleted file mode 100644 index 95db40a5..00000000 --- a/database/2018_07_25_194106_add_global_comments_stuff.php +++ /dev/null @@ -1,110 +0,0 @@ -exec(' - CREATE TABLE `msz_comments_categories` ( - `category_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `category_name` VARCHAR(255) NOT NULL, - `category_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `category_locked` TIMESTAMP NULL DEFAULT NULL, - PRIMARY KEY (`category_id`), - UNIQUE INDEX `comments_categories_name_unique` (`category_name`) - ); - '); - - $conn->exec(' - CREATE TABLE `msz_comments_posts` ( - `comment_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `category_id` INT(10) UNSIGNED NOT NULL, - `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `comment_reply_to` INT(10) UNSIGNED NULL DEFAULT NULL, - `comment_text` TEXT NOT NULL, - `comment_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `comment_pinned` TIMESTAMP NULL DEFAULT NULL, - `comment_edited` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, - `comment_deleted` TIMESTAMP NULL DEFAULT NULL, - PRIMARY KEY (`comment_id`), - INDEX `comments_posts_category_foreign` (`category_id`), - INDEX `comments_posts_user_foreign` (`user_id`), - INDEX `comments_posts_reply_id` (`comment_reply_to`), - INDEX `comments_posts_dates` ( - `comment_created`, - `comment_pinned`, - `comment_edited`, - `comment_deleted` - ), - CONSTRAINT `comments_posts_category_foreign` - FOREIGN KEY (`category_id`) - REFERENCES `msz_comments_categories` (`category_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `comments_posts_user_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE SET NULL - ); - '); - - $conn->exec(" - CREATE TABLE `msz_comments_votes` ( - `comment_id` INT(10) UNSIGNED NOT NULL, - `user_id` INT(10) UNSIGNED NOT NULL, - `comment_vote` ENUM('Like','Dislike') NULL, - UNIQUE INDEX `comments_vote_unique` (`comment_id`, `user_id`), - INDEX `comments_vote_user_foreign` (`user_id`), - INDEX `comments_vote_index` (`comment_vote`), - CONSTRAINT `comment_vote_id` - FOREIGN KEY (`comment_id`) - REFERENCES `msz_comments_posts` (`comment_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `comment_vote_user` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - ); - "); - - $conn->exec(" - ALTER TABLE `msz_news_posts` - ADD COLUMN `comment_section_id` INT UNSIGNED NULL DEFAULT NULL AFTER `deleted_at`, - ADD INDEX `news_posts_comment_section` (`comment_section_id`), - ADD CONSTRAINT `news_posts_comment_section` - FOREIGN KEY (`comment_section_id`) - REFERENCES `msz_comments_categories` (`category_id`) - ON UPDATE CASCADE - ON DELETE SET NULL; - "); - - // create a comment section for all news posts - $getNews = $conn->query('SELECT `post_id` FROM `msz_news_posts` WHERE `comment_section_id` IS NULL') - ->fetchAll(PDO::FETCH_ASSOC); - $setNews = $conn->prepare('UPDATE `msz_news_posts` SET `comment_section_id` = :c WHERE `post_id` = :p'); - - foreach ($getNews as $post) { - $info = comments_category_create("news-{$post['post_id']}"); - $setNews->execute([ - 'p' => $post['post_id'], - 'c' => $info['category_id'], - ]); - } -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(' - ALTER TABLE `msz_news_posts` - DROP COLUMN `comment_section_id`, - DROP INDEX `news_posts_comment_section`, - DROP FOREIGN KEY `news_posts_comment_section`; - '); - $conn->exec('DROP TABLE `msz_comments_votes`'); - $conn->exec('DROP TABLE `msz_comments_posts`'); - $conn->exec('DROP TABLE `msz_comments_categories`'); -} diff --git a/database/2018_08_18_014408_add_forum_permissions.php b/database/2018_08_18_014408_add_forum_permissions.php deleted file mode 100644 index 3a2e0f41..00000000 --- a/database/2018_08_18_014408_add_forum_permissions.php +++ /dev/null @@ -1,73 +0,0 @@ -exec(" - CREATE TABLE `msz_forum_permissions` ( - `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `role_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `forum_id` INT(10) UNSIGNED NOT NULL, - `forum_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', - `forum_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', - UNIQUE INDEX `forum_permissions_user_id_unique` (`user_id`), - UNIQUE INDEX `forum_permissions_role_id_unique` (`role_id`), - UNIQUE INDEX `forum_permissions_forum_id_unique` (`forum_id`), - CONSTRAINT `forum_permissions_user_id_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `forum_permissions_role_id_foreign` - FOREIGN KEY (`role_id`) - REFERENCES `msz_roles` (`role_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `forum_permissions_forum_id_foreign` - FOREIGN KEY (`forum_id`) - REFERENCES `msz_forum_categories` (`forum_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - ) - "); - - $conn->exec(' - CREATE VIEW `msz_forum_permissions_view` AS - WITH RECURSIVE permissions(user_id, role_id, forum_id, forum_perms_allow, forum_perms_deny) as ( - SELECT - pp.`user_id`, pp.`role_id`, - pc.`forum_id`, - IFNULL(pp.`forum_perms_allow`, 0), IFNULL(pp.`forum_perms_deny`, 0) - FROM `msz_forum_categories` as pc - LEFT JOIN `msz_forum_permissions` as pp - ON pp.`forum_id` = pc.`forum_id` - GROUP BY `user_id`, `role_id`, `forum_id` - UNION ALL - SELECT - permissions.`user_id`, permissions.`role_id`, - cc.`forum_id`, - IFNULL(cp.`forum_perms_allow`, 0) | permissions.`forum_perms_allow`, - IFNULL(cp.`forum_perms_deny`, 0) | permissions.`forum_perms_deny` - FROM `msz_forum_categories` as cc - LEFT JOIN `msz_forum_permissions` as cp - ON cp.`forum_id` = cc.`forum_id` - INNER JOIN permissions - ON cc.`forum_parent` = permissions.`forum_id` - ) - SELECT - `user_id`, `role_id`, `forum_id`, - (BIT_OR(`forum_perms_allow`) &~ BIT_OR(`forum_perms_deny`)) as `forum_perms` - FROM permissions - GROUP BY `user_id`, `role_id`, `forum_id` - '); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec('DROP VIEW `msz_forum_permissions_view`'); - $conn->exec('DROP TABLE `msz_forum_permissions`'); -} diff --git a/database/2018_09_17_195802_add_relations_table.php b/database/2018_09_17_195802_add_relations_table.php deleted file mode 100644 index 9d57e1af..00000000 --- a/database/2018_09_17_195802_add_relations_table.php +++ /dev/null @@ -1,33 +0,0 @@ -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`), - INDEX `user_relations_subject_id_foreign` (`subject_id`), - 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 - ) - '); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec('DROP TABLE `msz_user_relations`'); -} diff --git a/database/2018_09_19_170411_add_profile_about_section.php b/database/2018_09_19_170411_add_profile_about_section.php deleted file mode 100644 index 8c69a9df..00000000 --- a/database/2018_09_19_170411_add_profile_about_section.php +++ /dev/null @@ -1,22 +0,0 @@ -exec(" - ALTER TABLE `msz_users` - ADD COLUMN `user_about_content` TEXT NULL DEFAULT NULL AFTER `display_role`, - ADD COLUMN `user_about_parser` TINYINT(4) NOT NULL DEFAULT '0' AFTER `user_about_content`; - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(' - ALTER TABLE `msz_users` - DROP COLUMN `user_about_content`, - DROP COLUMN `user_about_parser`; - '); -} diff --git a/database/2018_10_01_081226_add_background_settings_field.php b/database/2018_10_01_081226_add_background_settings_field.php deleted file mode 100644 index 7436b0c3..00000000 --- a/database/2018_10_01_081226_add_background_settings_field.php +++ /dev/null @@ -1,20 +0,0 @@ -exec(" - ALTER TABLE `msz_users` - ADD COLUMN `user_background_settings` TINYINT(4) DEFAULT '0' AFTER `user_about_parser`; - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(' - ALTER TABLE `msz_users` - DROP COLUMN `user_background_settings`; - '); -} diff --git a/database/2018_10_09_181724_chat_quotes_table.php b/database/2018_10_09_181724_chat_quotes_table.php deleted file mode 100644 index e8c39b67..00000000 --- a/database/2018_10_09_181724_chat_quotes_table.php +++ /dev/null @@ -1,32 +0,0 @@ -exec(" - CREATE TABLE `msz_chat_quotes` ( - `quote_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `quote_parent` INT(10) UNSIGNED NULL DEFAULT NULL, - `quote_user_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `quote_username` VARCHAR(30) NOT NULL, - `quote_user_colour` INT(10) UNSIGNED NOT NULL DEFAULT '1073741824', - `quote_timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `quote_text` TEXT NOT NULL, - PRIMARY KEY (`quote_id`), - INDEX `msz_chat_quotes_parent` (`quote_parent`), - INDEX `msz_chat_quotes_user_id_foreign` (`quote_user_id`), - CONSTRAINT `msz_chat_quotes_user_id_foreign` - FOREIGN KEY (`quote_user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE SET NULL - ) - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec('DROP TABLE `msz_chat_quotes`'); -} diff --git a/database/2018_10_11_194124_fix_news_tables.php b/database/2018_10_11_194124_fix_news_tables.php deleted file mode 100644 index a88bf424..00000000 --- a/database/2018_10_11_194124_fix_news_tables.php +++ /dev/null @@ -1,47 +0,0 @@ -exec(" - ALTER TABLE `msz_news_categories` - CHANGE COLUMN `is_hidden` `category_is_hidden` TINYINT(1) NOT NULL DEFAULT '0' AFTER `category_description`, - CHANGE COLUMN `created_at` `category_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `category_is_hidden`, - DROP COLUMN `updated_at`; - "); - - $conn->exec(" - ALTER TABLE `msz_news_posts` - CHANGE COLUMN `comment_section_id` `comment_section_id` INT(10) UNSIGNED NULL DEFAULT NULL AFTER `user_id`, - CHANGE COLUMN `is_featured` `post_is_featured` TINYINT(1) NOT NULL DEFAULT '0' AFTER `comment_section_id`, - CHANGE COLUMN `scheduled_for` `post_scheduled` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `post_text`, - CHANGE COLUMN `created_at` `post_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `post_scheduled`, - CHANGE COLUMN `updated_at` `post_updated` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP - ON UPDATE CURRENT_TIMESTAMP AFTER `post_created`, - CHANGE COLUMN `deleted_at` `post_deleted` TIMESTAMP NULL DEFAULT NULL AFTER `post_updated`, - ADD INDEX `news_posts_indices` (`post_is_featured`, `post_scheduled`, `post_created`); - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_news_posts` - CHANGE COLUMN `post_is_featured` `is_featured` TINYINT(1) NOT NULL DEFAULT '0' AFTER `category_id`, - CHANGE COLUMN `post_scheduled` `scheduled_for` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `post_text`, - CHANGE COLUMN `post_created` `created_at` TIMESTAMP NULL DEFAULT NULL AFTER `scheduled_for`, - CHANGE COLUMN `post_updated` `updated_at` TIMESTAMP NULL DEFAULT NULL AFTER `created_at`, - CHANGE COLUMN `post_deleted` `deleted_at` TIMESTAMP NULL DEFAULT NULL AFTER `updated_at`, - CHANGE COLUMN `comment_section_id` `comment_section_id` INT(10) UNSIGNED NULL DEFAULT NULL AFTER `deleted_at`, - DROP INDEX `news_posts_indices`; - "); - - $conn->exec(" - ALTER TABLE `msz_news_categories` - CHANGE COLUMN `category_is_hidden` `is_hidden` TINYINT(1) NOT NULL DEFAULT '0' AFTER `category_description`, - CHANGE COLUMN `category_created` `created_at` TIMESTAMP NULL DEFAULT NULL AFTER `is_hidden`, - ADD COLUMN `updated_at` TIMESTAMP NULL DEFAULT NULL AFTER `created_at`; - "); -} diff --git a/database/2018_10_16_211910_add_forum_accent_colours.php b/database/2018_10_16_211910_add_forum_accent_colours.php deleted file mode 100644 index 706c2888..00000000 --- a/database/2018_10_16_211910_add_forum_accent_colours.php +++ /dev/null @@ -1,20 +0,0 @@ -exec(" - ALTER TABLE `msz_forum_categories` - ADD COLUMN `forum_colour` INT UNSIGNED NULL DEFAULT NULL AFTER `forum_description`; - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(' - ALTER TABLE `msz_forum_categories` - DROP COLUMN `forum_colour`; - '); -} diff --git a/database/2018_10_19_071439_add_topics_track_index.php b/database/2018_10_19_071439_add_topics_track_index.php deleted file mode 100644 index 7e70fddd..00000000 --- a/database/2018_10_19_071439_add_topics_track_index.php +++ /dev/null @@ -1,41 +0,0 @@ -exec(' - ALTER TABLE `msz_forum_topics_track` - ADD INDEX `forum_track_last_read` (`track_last_read`); - '); - - // i am actually brain dead, holy shit - $conn->exec(' - ALTER TABLE `msz_forum_permissions` - DROP INDEX `forum_permissions_forum_id_unique`, - ADD UNIQUE INDEX `forum_permissions_unique` (`user_id`, `role_id`, `forum_id`), - DROP INDEX `forum_permissions_user_id_unique`, - ADD INDEX `forum_permissions_forum_id` (`forum_id`), - DROP INDEX `forum_permissions_role_id_unique`, - ADD INDEX `forum_permissions_role_id` (`role_id`); - '); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(' - ALTER TABLE `msz_forum_permissions` - DROP INDEX `forum_permissions_unique`, - ADD UNIQUE INDEX `forum_permissions_user_id_unique` (`user_id`), - DROP INDEX `forum_permissions_forum_id`, - ADD INDEX `forum_permissions_role_id_unique` (`role_id`), - DROP INDEX `forum_permissions_role_id`, - ADD INDEX `forum_permissions_forum_id_unique` (`forum_id`); - '); - - $conn->exec(' - ALTER TABLE `msz_forum_topics_track` - DROP INDEX `forum_track_last_read`; - '); -} diff --git a/database/2018_10_29_201419_undo_laravel_damage.php b/database/2018_10_29_201419_undo_laravel_damage.php deleted file mode 100644 index 7cd0a882..00000000 --- a/database/2018_10_29_201419_undo_laravel_damage.php +++ /dev/null @@ -1,60 +0,0 @@ -exec(" - ALTER TABLE `msz_login_attempts` - ALTER `was_successful` DROP DEFAULT; - "); - - $conn->exec(" - ALTER TABLE `msz_login_attempts` - CHANGE COLUMN `user_id` `user_id` INT(10) UNSIGNED NULL DEFAULT NULL AFTER `attempt_id`, - CHANGE COLUMN `was_successful` `attempt_success` TINYINT(1) NOT NULL AFTER `user_id`, - CHANGE COLUMN `created_at` `attempt_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `attempt_country`, - CHANGE COLUMN `user_agent` `attempt_user_agent` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin' AFTER `attempt_created`, - DROP COLUMN `updated_at`; - "); - - $conn->exec(" - ALTER TABLE `msz_roles` - CHANGE COLUMN `created_at` `role_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `role_colour`, - DROP COLUMN `updated_at`; - "); - - $conn->exec(" - ALTER TABLE `msz_sessions` - ALTER `user_agent` DROP DEFAULT, - ALTER `expires_on` DROP DEFAULT; - "); - - $conn->exec(" - ALTER TABLE `msz_sessions` - CHANGE COLUMN `user_agent` `session_user_agent` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin' AFTER `session_ip`, - CHANGE COLUMN `session_country` `session_country` CHAR(2) NOT NULL DEFAULT 'XX' COLLATE 'utf8mb4_bin' AFTER `session_user_agent`, - CHANGE COLUMN `expires_on` `session_expires` TIMESTAMP NOT NULL AFTER `session_country`, - CHANGE COLUMN `created_at` `session_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `session_expires`, - CHANGE COLUMN `updated_at` `session_active` TIMESTAMP NULL DEFAULT NULL AFTER `session_created`; - "); - - $conn->exec(" - ALTER TABLE `msz_users` - CHANGE COLUMN `created_at` `user_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `user_colour`, - CHANGE COLUMN `last_seen` `user_active` TIMESTAMP NULL DEFAULT NULL AFTER `user_created`, - CHANGE COLUMN `deleted_at` `user_deleted` TIMESTAMP NULL DEFAULT NULL AFTER `user_active`, - DROP INDEX `users_user_country_index`, - DROP INDEX `users_last_seen_index`, - DROP INDEX `users_created_at_index`, - ADD INDEX `users_indices` (`user_country`, `user_created`, `user_active`, `user_deleted`); - "); -} - -function migrate_down(PDO $conn): void -{ - // can't be bothered to write a reverse for this migration - // honestly i might just remove migrate_down system since i don't really ever use it - $conn = $conn; // trick phpcs -} diff --git a/database/2018_11_03_145619_add_permission_override_flag.php b/database/2018_11_03_145619_add_permission_override_flag.php deleted file mode 100644 index 63025d1e..00000000 --- a/database/2018_11_03_145619_add_permission_override_flag.php +++ /dev/null @@ -1,102 +0,0 @@ -exec(" - ALTER TABLE `msz_permissions` - ADD COLUMN `general_perms_override` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `general_perms_deny`, - ADD COLUMN `user_perms_override` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `user_perms_deny`, - ADD COLUMN `changelog_perms_override` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `changelog_perms_deny`, - ADD COLUMN `news_perms_override` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `news_perms_deny`, - ADD COLUMN `forum_perms_override` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `forum_perms_deny`, - ADD COLUMN `comments_perms_override` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `comments_perms_deny`; - "); - - $conn->exec(" - ALTER TABLE `msz_forum_permissions` - ADD COLUMN `forum_perms_override` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `forum_perms_deny`; - "); - - $conn->exec('DROP VIEW `msz_forum_permissions_view`'); - $conn->exec(" - CREATE VIEW `msz_forum_permissions_view` AS - WITH RECURSIVE permissions(user_id, role_id, forum_id, forum_perms_allow, forum_perms_deny) as ( - SELECT - pp.`user_id`, pp.`role_id`, - pc.`forum_id`, - IFNULL(pp.`forum_perms_allow`, 0), IFNULL(pp.`forum_perms_deny`, 0) - FROM `msz_forum_categories` as pc - LEFT JOIN `msz_forum_permissions` as pp - ON pp.`forum_id` = pc.`forum_id` - GROUP BY `user_id`, `role_id`, `forum_id` - UNION ALL - SELECT - permissions.`user_id`, permissions.`role_id`, - cc.`forum_id`, - IFNULL(cp.`forum_perms_allow`, 0) | (permissions.`forum_perms_allow` &~ IFNULL(cp.`forum_perms_override`, 0)), - IFNULL(cp.`forum_perms_deny`, 0) | (permissions.`forum_perms_deny` &~ IFNULL(cp.`forum_perms_override`, 0)) - FROM `msz_forum_categories` as cc - LEFT JOIN `msz_forum_permissions` as cp - ON cp.`forum_id` = cc.`forum_id` - INNER JOIN permissions - ON cc.`forum_parent` = permissions.`forum_id` - ) - SELECT - `user_id`, `role_id`, `forum_id`, - (BIT_OR(`forum_perms_allow`) &~ BIT_OR(`forum_perms_deny`)) as `forum_perms` - FROM permissions - GROUP BY `user_id`, `role_id`, `forum_id` - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec('DROP VIEW `msz_forum_permissions_view`'); - $conn->exec(" - CREATE VIEW `msz_forum_permissions_view` AS - WITH RECURSIVE permissions(user_id, role_id, forum_id, forum_perms_allow, forum_perms_deny) as ( - SELECT - pp.`user_id`, pp.`role_id`, - pc.`forum_id`, - IFNULL(pp.`forum_perms_allow`, 0), IFNULL(pp.`forum_perms_deny`, 0) - FROM `msz_forum_categories` as pc - LEFT JOIN `msz_forum_permissions` as pp - ON pp.`forum_id` = pc.`forum_id` - GROUP BY `user_id`, `role_id`, `forum_id` - UNION ALL - SELECT - permissions.`user_id`, permissions.`role_id`, - cc.`forum_id`, - IFNULL(cp.`forum_perms_allow`, 0) | permissions.`forum_perms_allow`, - IFNULL(cp.`forum_perms_deny`, 0) | permissions.`forum_perms_deny` - FROM `msz_forum_categories` as cc - LEFT JOIN `msz_forum_permissions` as cp - ON cp.`forum_id` = cc.`forum_id` - INNER JOIN permissions - ON cc.`forum_parent` = permissions.`forum_id` - ) - SELECT - `user_id`, `role_id`, `forum_id`, - (BIT_OR(`forum_perms_allow`) &~ BIT_OR(`forum_perms_deny`)) as `forum_perms` - FROM permissions - GROUP BY `user_id`, `role_id`, `forum_id` - "); - - $conn->exec(" - ALTER TABLE `msz_forum_permissions` - DROP COLUMN `forum_perms_override`; - "); - - $conn->exec(" - ALTER TABLE `msz_permissions` - DROP COLUMN `general_perms_override`, - DROP COLUMN `user_perms_override`, - DROP COLUMN `changelog_perms_override`, - DROP COLUMN `news_perms_override`, - DROP COLUMN `forum_perms_override`, - DROP COLUMN `comments_perms_override`; - "); -} diff --git a/database/2018_11_17_191807_roles_table_extensions.php b/database/2018_11_17_191807_roles_table_extensions.php deleted file mode 100644 index b1eee64c..00000000 --- a/database/2018_11_17_191807_roles_table_extensions.php +++ /dev/null @@ -1,22 +0,0 @@ -exec(" - ALTER TABLE `msz_roles` - CHANGE COLUMN `role_secret` `role_hidden` TINYINT(1) NOT NULL DEFAULT '0' AFTER `role_description`, - ADD COLUMN `role_can_leave` TINYINT(1) NOT NULL DEFAULT '0' AFTER `role_hidden`; - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_roles` - CHANGE COLUMN `role_hidden` `role_secret` TINYINT(1) NOT NULL DEFAULT '0' AFTER `role_description`, - DROP COLUMN `role_can_leave`; - "); -} diff --git a/database/2018_12_07_175328_add_switch_friendcode_field.php b/database/2018_12_07_175328_add_switch_friendcode_field.php deleted file mode 100644 index 179c7ec2..00000000 --- a/database/2018_12_07_175328_add_switch_friendcode_field.php +++ /dev/null @@ -1,20 +0,0 @@ -exec(" - ALTER TABLE `msz_users` - ADD COLUMN `user_ninswitch` VARCHAR(14) NOT NULL DEFAULT '' AFTER `user_steam`; - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_users` - DROP COLUMN `user_ninswitch`; - "); -} diff --git a/database/2018_12_24_203231_add_warnings_table.php b/database/2018_12_24_203231_add_warnings_table.php deleted file mode 100644 index 789507aa..00000000 --- a/database/2018_12_24_203231_add_warnings_table.php +++ /dev/null @@ -1,51 +0,0 @@ -exec(" - CREATE TABLE `msz_user_warnings` ( - `warning_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `user_id` INT(10) UNSIGNED NOT NULL, - `user_ip` VARBINARY(16) NOT NULL, - `issuer_id` INT(10) UNSIGNED NULL DEFAULT NULL, - `issuer_ip` VARBINARY(16) NOT NULL, - `warning_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `warning_duration` TIMESTAMP NULL DEFAULT NULL, - `warning_type` TINYINT(3) UNSIGNED NOT NULL, - `warning_note` VARCHAR(255) NOT NULL, - `warning_note_private` TEXT NULL DEFAULT NULL, - PRIMARY KEY (`warning_id`), - INDEX `user_warnings_user_foreign` (`user_id`), - INDEX `user_warnings_issuer_foreign` (`issuer_id`), - INDEX `user_warnings_indices` (`warning_created`, `warning_type`, `warning_duration`, `user_ip`), - CONSTRAINT `user_warnings_issuer_foreign` - FOREIGN KEY (`issuer_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE SET NULL, - CONSTRAINT `user_warnings_user_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - ) - "); - - $conn->exec(" - CREATE TABLE `msz_ip_blacklist` ( - `ip_subnet` VARBINARY(16) NOT NULL, - `ip_mask` TINYINT(3) UNSIGNED NOT NULL, - UNIQUE INDEX `ip_blacklist_unique` (`ip_subnet`, `ip_mask`) - ) - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - DROP TABLE `msz_user_warnings`; - "); -} diff --git a/database/2018_12_28_173507_remove_override_flag.php b/database/2018_12_28_173507_remove_override_flag.php deleted file mode 100644 index 412791d4..00000000 --- a/database/2018_12_28_173507_remove_override_flag.php +++ /dev/null @@ -1,102 +0,0 @@ -exec(" - ALTER TABLE `msz_permissions` - DROP COLUMN `general_perms_override`, - DROP COLUMN `user_perms_override`, - DROP COLUMN `changelog_perms_override`, - DROP COLUMN `news_perms_override`, - DROP COLUMN `forum_perms_override`, - DROP COLUMN `comments_perms_override`; - "); - - $conn->exec('DROP VIEW `msz_forum_permissions_view`'); - $conn->exec(" - CREATE VIEW `msz_forum_permissions_view` AS - WITH RECURSIVE permissions(user_id, role_id, forum_id, forum_perms_allow, forum_perms_deny) as ( - SELECT - pp.`user_id`, pp.`role_id`, - pc.`forum_id`, - IFNULL(pp.`forum_perms_allow`, 0), IFNULL(pp.`forum_perms_deny`, 0) - FROM `msz_forum_categories` as pc - LEFT JOIN `msz_forum_permissions` as pp - ON pp.`forum_id` = pc.`forum_id` - GROUP BY `user_id`, `role_id`, `forum_id` - UNION ALL - SELECT - permissions.`user_id`, permissions.`role_id`, - cc.`forum_id`, - IFNULL(cp.`forum_perms_allow`, 0) | permissions.`forum_perms_allow`, - IFNULL(cp.`forum_perms_deny`, 0) | permissions.`forum_perms_deny` - FROM `msz_forum_categories` as cc - LEFT JOIN `msz_forum_permissions` as cp - ON cp.`forum_id` = cc.`forum_id` - INNER JOIN permissions - ON cc.`forum_parent` = permissions.`forum_id` - ) - SELECT - `user_id`, `role_id`, `forum_id`, - (BIT_OR(`forum_perms_allow`) &~ BIT_OR(`forum_perms_deny`)) as `forum_perms` - FROM permissions - GROUP BY `user_id`, `role_id`, `forum_id` - "); - - $conn->exec(" - ALTER TABLE `msz_forum_permissions` - DROP COLUMN `forum_perms_override`; - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_forum_permissions` - ADD COLUMN `forum_perms_override` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `forum_perms_deny`; - "); - - $conn->exec('DROP VIEW `msz_forum_permissions_view`'); - $conn->exec(" - CREATE VIEW `msz_forum_permissions_view` AS - WITH RECURSIVE permissions(user_id, role_id, forum_id, forum_perms_allow, forum_perms_deny) as ( - SELECT - pp.`user_id`, pp.`role_id`, - pc.`forum_id`, - IFNULL(pp.`forum_perms_allow`, 0), IFNULL(pp.`forum_perms_deny`, 0) - FROM `msz_forum_categories` as pc - LEFT JOIN `msz_forum_permissions` as pp - ON pp.`forum_id` = pc.`forum_id` - GROUP BY `user_id`, `role_id`, `forum_id` - UNION ALL - SELECT - permissions.`user_id`, permissions.`role_id`, - cc.`forum_id`, - IFNULL(cp.`forum_perms_allow`, 0) | (permissions.`forum_perms_allow` &~ IFNULL(cp.`forum_perms_override`, 0)), - IFNULL(cp.`forum_perms_deny`, 0) | (permissions.`forum_perms_deny` &~ IFNULL(cp.`forum_perms_override`, 0)) - FROM `msz_forum_categories` as cc - LEFT JOIN `msz_forum_permissions` as cp - ON cp.`forum_id` = cc.`forum_id` - INNER JOIN permissions - ON cc.`forum_parent` = permissions.`forum_id` - ) - SELECT - `user_id`, `role_id`, `forum_id`, - (BIT_OR(`forum_perms_allow`) &~ BIT_OR(`forum_perms_deny`)) as `forum_perms` - FROM permissions - GROUP BY `user_id`, `role_id`, `forum_id` - "); - - $conn->exec(" - ALTER TABLE `msz_permissions` - ADD COLUMN `general_perms_override` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `general_perms_deny`, - ADD COLUMN `user_perms_override` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `user_perms_deny`, - ADD COLUMN `changelog_perms_override` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `changelog_perms_deny`, - ADD COLUMN `news_perms_override` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `news_perms_deny`, - ADD COLUMN `forum_perms_override` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `forum_perms_deny`, - ADD COLUMN `comments_perms_override` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `comments_perms_deny`; - "); -} diff --git a/database/2018_12_30_025222_automatically_mark_edited.php b/database/2018_12_30_025222_automatically_mark_edited.php deleted file mode 100644 index 316acbdf..00000000 --- a/database/2018_12_30_025222_automatically_mark_edited.php +++ /dev/null @@ -1,20 +0,0 @@ -exec(" - ALTER TABLE `msz_forum_posts` - CHANGE COLUMN `post_edited` `post_edited` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP AFTER `post_created`; - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_forum_posts` - CHANGE COLUMN `post_edited` `post_edited` TIMESTAMP NULL DEFAULT NULL AFTER `post_created`; - "); -} diff --git a/database/2018_12_30_171344_revert_auto_edit_mark.php b/database/2018_12_30_171344_revert_auto_edit_mark.php deleted file mode 100644 index f894236b..00000000 --- a/database/2018_12_30_171344_revert_auto_edit_mark.php +++ /dev/null @@ -1,20 +0,0 @@ -exec(" - ALTER TABLE `msz_forum_posts` - CHANGE COLUMN `post_edited` `post_edited` TIMESTAMP NULL DEFAULT NULL AFTER `post_created`; - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_forum_posts` - CHANGE COLUMN `post_edited` `post_edited` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP AFTER `post_created`; - "); -} diff --git a/database/2019_01_10_225122_nuke_chat_quotes.php b/database/2019_01_10_225122_nuke_chat_quotes.php deleted file mode 100644 index 9be5c68d..00000000 --- a/database/2019_01_10_225122_nuke_chat_quotes.php +++ /dev/null @@ -1,16 +0,0 @@ -exec(" - ALTER TABLE `msz_users` - ADD COLUMN `user_birthdate` DATE NULL DEFAULT NULL AFTER `user_about_parser`, - DROP INDEX `users_indices`, - ADD INDEX `users_indices` (`user_country`, `user_created`, `user_active`, `user_deleted`, `user_birthdate`); - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_users` - DROP COLUMN `user_birthdate`; - "); -} diff --git a/database/2019_01_18_202512_add_signature_columns.php b/database/2019_01_18_202512_add_signature_columns.php deleted file mode 100644 index 49a0a0e6..00000000 --- a/database/2019_01_18_202512_add_signature_columns.php +++ /dev/null @@ -1,31 +0,0 @@ -exec(" - ALTER TABLE `msz_users` - ADD COLUMN `user_signature_content` TEXT NULL AFTER `user_about_parser`, - ADD COLUMN `user_signature_parser` TINYINT(4) NOT NULL DEFAULT '0' AFTER `user_signature_content`; - "); - $conn->exec(" - ALTER TABLE `msz_forum_posts` - ADD COLUMN `post_display_signature` TINYINT(4) UNSIGNED NOT NULL DEFAULT '1' AFTER `post_parse`; - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_forum_posts` - DROP COLUMN `post_display_signature`; - "); - - $conn->exec(" - ALTER TABLE `msz_users` - DROP COLUMN `user_signature_content`, - DROP COLUMN `user_signature_parser`; - "); -} diff --git a/database/2019_02_22_084055_super_user_flag.php b/database/2019_02_22_084055_super_user_flag.php deleted file mode 100644 index 5e75a988..00000000 --- a/database/2019_02_22_084055_super_user_flag.php +++ /dev/null @@ -1,20 +0,0 @@ -exec(" - ALTER TABLE `msz_users` - ADD COLUMN `user_super` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' AFTER `last_ip`; - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_users` - DROP COLUMN `user_super`; - "); -} diff --git a/database/2019_02_25_191413_add_static_forum_counts.php b/database/2019_02_25_191413_add_static_forum_counts.php deleted file mode 100644 index 3079b7e1..00000000 --- a/database/2019_02_25_191413_add_static_forum_counts.php +++ /dev/null @@ -1,22 +0,0 @@ -exec(" - ALTER TABLE `msz_forum_categories` - ADD COLUMN `forum_count_topics` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `forum_hidden`, - ADD COLUMN `forum_count_posts` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `forum_count_topics`; - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_forum_categories` - DROP COLUMN `forum_count_topics`, - DROP COLUMN `forum_count_posts`; - "); -} diff --git a/database/2019_03_03_140632_add_static_topic_viewcount.php b/database/2019_03_03_140632_add_static_topic_viewcount.php deleted file mode 100644 index 0a7ac103..00000000 --- a/database/2019_03_03_140632_add_static_topic_viewcount.php +++ /dev/null @@ -1,43 +0,0 @@ -exec(" - ALTER TABLE `msz_forum_topics` - ADD COLUMN `topic_count_views` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `topic_title`; - "); - - $conn->exec(" - CREATE TRIGGER `msz_forum_topics_track_increase_views` - AFTER INSERT ON `msz_forum_topics_track` - FOR EACH ROW BEGIN - UPDATE `msz_forum_topics` - SET `topic_count_views` = `topic_count_views` + 1 - WHERE `topic_id` = NEW.topic_id; - END; - "); - - // Restore view counts - $conn->exec(" - UPDATE `msz_forum_topics` AS t - INNER JOIN ( - SELECT `topic_id`, COUNT(`user_id`) AS `count_views` - FROM `msz_forum_topics_track` - GROUP BY `topic_id` - ) AS tt - ON tt.`topic_id` = t.`topic_id` - SET t.`topic_count_views` = tt.`count_views` - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec("DROP TRIGGER `msz_forum_topics_track_increase_views`"); - $conn->exec(" - ALTER TABLE `msz_forum_topics` - DROP COLUMN `topic_count_views`; - "); -} diff --git a/database/2019_03_04_200240_remove_trigger_from_topics_track.php b/database/2019_03_04_200240_remove_trigger_from_topics_track.php deleted file mode 100644 index 328d351b..00000000 --- a/database/2019_03_04_200240_remove_trigger_from_topics_track.php +++ /dev/null @@ -1,22 +0,0 @@ -exec("DROP TRIGGER `msz_forum_topics_track_increase_views`"); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - CREATE TRIGGER `msz_forum_topics_track_increase_views` - AFTER INSERT ON `msz_forum_topics_track` - FOR EACH ROW BEGIN - UPDATE `msz_forum_topics` - SET `topic_count_views` = `topic_count_views` + 1 - WHERE `topic_id` = NEW.topic_id; - END; - "); -} diff --git a/database/2019_03_09_222347_add_two_factor_auth.php b/database/2019_03_09_222347_add_two_factor_auth.php deleted file mode 100644 index 8ee25699..00000000 --- a/database/2019_03_09_222347_add_two_factor_auth.php +++ /dev/null @@ -1,20 +0,0 @@ -exec(" - ALTER TABLE `msz_users` - ADD COLUMN `user_totp_key` CHAR(26) NULL DEFAULT NULL AFTER `display_role`; - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_users` - DROP COLUMN `user_totp_key`; - "); -} diff --git a/database/2019_03_10_161059_add_tfa_login_token_table.php b/database/2019_03_10_161059_add_tfa_login_token_table.php deleted file mode 100644 index 13c96e26..00000000 --- a/database/2019_03_10_161059_add_tfa_login_token_table.php +++ /dev/null @@ -1,30 +0,0 @@ -exec(" - CREATE TABLE `msz_auth_tfa` ( - `user_id` INT UNSIGNED NOT NULL, - `tfa_token` CHAR(32) NOT NULL, - `tfa_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - UNIQUE INDEX `auth_tfa_token_unique` (`tfa_token`), - INDEX `auth_tfa_user_foreign` (`user_id`), - INDEX `auth_tfa_created_index` (`tfa_created`), - CONSTRAINT `auth_tfa_user_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - ); - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - DROP TABLE `msz_auth_tfa`; - "); -} diff --git a/database/2019_03_10_183155_change_enum_to_int_in_comment_votes.php b/database/2019_03_10_183155_change_enum_to_int_in_comment_votes.php deleted file mode 100644 index f8a6b87a..00000000 --- a/database/2019_03_10_183155_change_enum_to_int_in_comment_votes.php +++ /dev/null @@ -1,49 +0,0 @@ -exec(" - ALTER TABLE `msz_comments_votes` - ADD COLUMN `comment_vote` TINYINT NOT NULL DEFAULT '0' AFTER `user_id`, - CHANGE COLUMN `comment_vote` `comment_vote_old` ENUM('Like','Dislike') NULL DEFAULT NULL COLLATE 'utf8mb4_bin' AFTER `comment_vote`, - ADD INDEX `comments_vote_old` (`comment_vote_old`); - "); - - // Step 2, migrate old values - $conn->exec(sprintf( - ' - UPDATE `msz_comments_votes` - SET `comment_vote` = %d - WHERE `comment_vote_old` = "Like" - ', - MSZ_COMMENTS_VOTE_LIKE - )); - $conn->exec(sprintf( - ' - UPDATE `msz_comments_votes` - SET `comment_vote` = %d - WHERE `comment_vote_old` = "Dislike" - ', - MSZ_COMMENTS_VOTE_DISLIKE - )); - - // Step 3, nuke the old column - $conn->exec(' - ALTER TABLE `msz_comments_votes` - DROP COLUMN `comment_vote_old`; - '); -} - -function migrate_down(PDO $conn): void -{ - // this one only goes one way! - $conn->exec("TRUNCATE `msz_comments_votes`"); - $conn->exec(" - ALTER TABLE `msz_comments_votes` - CHANGE COLUMN `comment_vote` `comment_vote` ENUM('Like','Dislike') NULL DEFAULT NULL COLLATE 'utf8mb4_bin' AFTER `user_id`; - "); -} diff --git a/database/2019_03_31_003320_sessions_updates.php b/database/2019_03_31_003320_sessions_updates.php deleted file mode 100644 index c09dd70b..00000000 --- a/database/2019_03_31_003320_sessions_updates.php +++ /dev/null @@ -1,26 +0,0 @@ -exec(" - ALTER TABLE `msz_sessions` - ADD COLUMN `session_ip_last` VARBINARY(16) NULL DEFAULT NULL AFTER `session_ip`, - ADD COLUMN `session_expires_bump` TINYINT UNSIGNED NOT NULL DEFAULT '1' AFTER `session_expires`, - ADD UNIQUE INDEX `sessions_key_unique` (`session_key`), - ADD INDEX `sessions_expires_index` (`session_expires`); - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_sessions` - DROP COLUMN `session_ip_last`, - DROP COLUMN `session_expires_bump`, - DROP INDEX `sessions_expires_index`, - DROP INDEX `sessions_key_unique`; - "); -} diff --git a/database/2019_03_31_014743_add_index_to_forum_post_deleted.php b/database/2019_03_31_014743_add_index_to_forum_post_deleted.php deleted file mode 100644 index b654c700..00000000 --- a/database/2019_03_31_014743_add_index_to_forum_post_deleted.php +++ /dev/null @@ -1,24 +0,0 @@ -exec(" - ALTER TABLE `msz_forum_posts` - DROP INDEX `posts_indices`, - ADD INDEX `posts_created_index` (`post_created`), - ADD INDEX `posts_deleted_index` (`post_deleted`); - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_forum_posts` - DROP INDEX `posts_created_index`, - DROP INDEX `posts_deleted_index`, - ADD INDEX `posts_indices` (`post_created`); - "); -} diff --git a/database/2019_04_10_093908_fix_forum_indices.php b/database/2019_04_10_093908_fix_forum_indices.php deleted file mode 100644 index f05aa12e..00000000 --- a/database/2019_04_10_093908_fix_forum_indices.php +++ /dev/null @@ -1,26 +0,0 @@ -exec(" - ALTER TABLE `msz_forum_categories` - DROP INDEX `forums_indices`, - ADD INDEX `forum_order_index` (`forum_order`), - ADD INDEX `forum_parent_index` (`forum_parent`), - ADD INDEX `forum_type_index` (`forum_type`); - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_forum_categories` - DROP INDEX `forum_order_index`, - DROP INDEX `forum_parent_index`, - DROP INDEX `forum_type_index`, - ADD INDEX `forums_indices` (`forum_order`, `forum_parent`, `forum_type`); - "); -} diff --git a/database/2019_04_11_213920_make_changelog_actions_static.php b/database/2019_04_11_213920_make_changelog_actions_static.php deleted file mode 100644 index 35ce6b48..00000000 --- a/database/2019_04_11_213920_make_changelog_actions_static.php +++ /dev/null @@ -1,63 +0,0 @@ -exec(" - ALTER TABLE `msz_changelog_changes` - CHANGE COLUMN `action_id` `change_action` INT(10) UNSIGNED NULL DEFAULT NULL AFTER `user_id`, - DROP INDEX `changes_user_id_foreign`, - ADD INDEX `changes_user_foreign` (`user_id`), - DROP INDEX `changes_action_id_foreign`, - ADD INDEX `changes_action_index` (`change_action`), - DROP INDEX `changes_change_created_index`, - ADD INDEX `changes_created_index` (`change_created`), - DROP FOREIGN KEY `changes_action_id_foreign`; - "); - - $conn->exec("DROP TABLE `msz_changelog_actions`"); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - CREATE TABLE `msz_changelog_actions` ( - `action_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `action_name` VARCHAR(50) NOT NULL, - `action_colour` INT(10) UNSIGNED NOT NULL DEFAULT '0', - `action_class` VARCHAR(20) NOT NULL, - PRIMARY KEY (`action_id`), - UNIQUE INDEX `action_class_unique` (`action_class`) - ) - "); - - $conn->exec(" - INSERT INTO `msz_changelog_actions` - (`action_id`, `action_name`, `action_colour`, `action_class`) - VALUES - (1, 'Added', 1414709, 'add'), - (2, 'Removed', 14890819, 'remove'), - (3, 'Updated', 2718602, 'update'), - (4, 'Fixed', 2973334, 'fix'), - (5, 'Imported', 2856568, 'import'), - (6, 'Reverted', 14910021, 'revert'); - "); - - $conn->exec(" - ALTER TABLE `msz_changelog_changes` - CHANGE COLUMN `change_action` `action_id` INT(10) UNSIGNED NULL DEFAULT NULL AFTER `user_id`, - DROP INDEX `changes_user_foreign`, - ADD INDEX `changes_user_id_foreign` (`user_id`), - DROP INDEX `changes_action_index`, - ADD INDEX `changes_action_id_foreign` (`action_id`), - DROP INDEX `changes_created_index`, - ADD INDEX `changes_change_created_index` (`change_created`), - ADD CONSTRAINT `changes_action_id_foreign` - FOREIGN KEY (`action_id`) - REFERENCES `msz_changelog_actions` (`action_id`) - ON UPDATE CASCADE - ON DELETE SET NULL; - "); -} diff --git a/database/2019_04_12_224041_add_more_indices.php b/database/2019_04_12_224041_add_more_indices.php deleted file mode 100644 index 94e4d0c8..00000000 --- a/database/2019_04_12_224041_add_more_indices.php +++ /dev/null @@ -1,100 +0,0 @@ -exec(" - ALTER TABLE `msz_forum_posts` - ADD INDEX `posts_parse_index` (`post_parse`), - ADD INDEX `posts_edited_index` (`post_edited`), - ADD INDEX `posts_display_signature_index` (`post_display_signature`), - ADD INDEX `posts_ip_index` (`post_ip`), - ADD FULLTEXT INDEX `posts_fulltext` (`post_text`); - "); - - $conn->exec(" - ALTER TABLE `msz_comments_categories` - ADD INDEX `comments_categories_locked_index` (`category_locked`); - "); - - $conn->exec(" - ALTER TABLE `msz_forum_topics` - DROP INDEX `topics_indices`, - ADD FULLTEXT INDEX `topics_fulltext` (`topic_title`), - ADD INDEX `topics_type_index` (`topic_type`), - ADD INDEX `topics_created_index` (`topic_created`), - ADD INDEX `topics_bumped_index` (`topic_bumped`), - ADD INDEX `topics_deleted_index` (`topic_deleted`), - ADD INDEX `topics_locked_index` (`topic_locked`); - "); - - $conn->exec(" - ALTER TABLE `msz_news_posts` - DROP INDEX `news_posts_indices`, - ADD INDEX `news_posts_featured_index` (`post_is_featured`), - ADD INDEX `news_posts_scheduled_index` (`post_scheduled`), - ADD INDEX `news_posts_created_index` (`post_created`), - ADD INDEX `news_posts_updated_index` (`post_updated`), - ADD INDEX `news_posts_deleted_index` (`post_deleted`), - ADD FULLTEXT INDEX `news_posts_fulltext` (`post_title`, `post_text`); - "); - - $conn->exec(" - ALTER TABLE `msz_user_warnings` - DROP INDEX `user_warnings_indices`, - ADD INDEX `user_warnings_created_index` (`warning_created`), - ADD INDEX `user_warnings_duration_index` (`warning_duration`), - ADD INDEX `user_warnings_type_index` (`warning_type`), - ADD INDEX `user_warnings_user_ip_index` (`user_ip`); - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_user_warnings` - DROP INDEX `user_warnings_user_ip_index`, - DROP INDEX `user_warnings_type_index`, - DROP INDEX `user_warnings_duration_index`, - DROP INDEX `user_warnings_created_index`, - ADD INDEX `user_warnings_indices` (`warning_created`, `warning_type`, `warning_duration`, `user_ip`); - "); - - $conn->exec(" - ALTER TABLE `msz_news_posts` - DROP INDEX `news_posts_fulltext`, - DROP INDEX `news_posts_deleted_index`, - DROP INDEX `news_posts_created_index`, - DROP INDEX `news_posts_updated_index`, - DROP INDEX `news_posts_scheduled_index`, - DROP INDEX `news_posts_featured_index`, - ADD INDEX `news_posts_indices` (`post_is_featured`, `post_scheduled`, `post_created`); - "); - - $conn->exec(" - ALTER TABLE `msz_forum_topics` - DROP INDEX `topics_fulltext`, - DROP INDEX `topics_locked_index`, - DROP INDEX `topics_deleted_index`, - DROP INDEX `topics_created_index`, - DROP INDEX `topics_bumped_index`, - DROP INDEX `topics_type_index`, - ADD INDEX `topics_indices` (`topic_type`, `topic_bumped`); - "); - - $conn->exec(" - ALTER TABLE `msz_comments_categories` - DROP INDEX `comments_categories_locked_index`; - "); - - $conn->exec(" - ALTER TABLE `msz_forum_posts` - DROP INDEX `posts_fulltext`, - DROP INDEX `posts_ip_index`, - DROP INDEX `posts_display_signature_index`, - DROP INDEX `posts_edited_index`, - DROP INDEX `posts_parse_index`,; - "); -} diff --git a/database/2019_04_16_123231_create_polls_tables.php b/database/2019_04_16_123231_create_polls_tables.php deleted file mode 100644 index 947a4ea2..00000000 --- a/database/2019_04_16_123231_create_polls_tables.php +++ /dev/null @@ -1,83 +0,0 @@ -exec(" - CREATE TABLE `msz_forum_polls` ( - `poll_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `poll_max_votes` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', - `poll_expires` TIMESTAMP NULL DEFAULT NULL, - `poll_preview_results` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', - PRIMARY KEY (`poll_id`) - ) COLLATE='utf8mb4_bin' ENGINE=InnoDB - "); - - $conn->exec(" - CREATE TABLE `msz_forum_polls_options` ( - `option_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, - `poll_id` INT(10) UNSIGNED NOT NULL, - `option_text` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', - PRIMARY KEY (`option_id`), - INDEX `polls_options_poll_foreign` (`poll_id`), - CONSTRAINT `polls_options_poll_foreign` - FOREIGN KEY (`poll_id`) - REFERENCES `msz_forum_polls` (`poll_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - ) COLLATE='utf8mb4_bin' ENGINE=InnoDB - "); - - $conn->exec(" - CREATE TABLE `msz_forum_polls_answers` ( - `user_id` INT(10) UNSIGNED NOT NULL, - `poll_id` INT(10) UNSIGNED NOT NULL, - `option_id` INT(10) UNSIGNED NOT NULL, - UNIQUE INDEX `polls_answers_unique` (`user_id`, `poll_id`, `option_id`), - INDEX `polls_answers_user_foreign` (`user_id`), - INDEX `polls_answers_poll_foreign` (`poll_id`), - INDEX `polls_answers_option_foreign` (`option_id`), - CONSTRAINT `polls_answers_option_foreign` - FOREIGN KEY (`option_id`) - REFERENCES `msz_forum_polls_options` (`option_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `polls_answers_poll_foreign` - FOREIGN KEY (`poll_id`) - REFERENCES `msz_forum_polls` (`poll_id`) - ON UPDATE CASCADE - ON DELETE CASCADE, - CONSTRAINT `polls_answers_user_foreign` - FOREIGN KEY (`user_id`) - REFERENCES `msz_users` (`user_id`) - ON UPDATE CASCADE - ON DELETE CASCADE - ) COLLATE='utf8mb4_bin' ENGINE=InnoDB - "); - - $conn->exec(" - ALTER TABLE `msz_forum_topics` - ADD COLUMN `poll_id` INT(10) UNSIGNED NULL DEFAULT NULL AFTER `user_id`, - ADD INDEX `posts_poll_id_foreign` (`poll_id`), - ADD CONSTRAINT `posts_poll_id_foreign` - FOREIGN KEY (`poll_id`) - REFERENCES `msz_forum_polls` (`poll_id`) - ON UPDATE CASCADE - ON DELETE SET NULL; - "); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - ALTER TABLE `msz_forum_topics` - DROP COLUMN `poll_id`, - DROP INDEX `posts_poll_id_foreign`, - DROP FOREIGN KEY `posts_poll_id_foreign`; - "); - $conn->exec("DROP TABLE `msz_forum_polls_answers`"); - $conn->exec("DROP TABLE `msz_forum_polls_options`"); - $conn->exec("DROP TABLE `msz_forum_polls`"); -} diff --git a/database/2019_04_30_190530_remove_with_recursive.php b/database/2019_04_30_190530_remove_with_recursive.php deleted file mode 100644 index 25c8c65d..00000000 --- a/database/2019_04_30_190530_remove_with_recursive.php +++ /dev/null @@ -1,42 +0,0 @@ -exec('DROP VIEW `msz_forum_permissions_view`'); -} - -function migrate_down(PDO $conn): void -{ - $conn->exec(" - CREATE VIEW `msz_forum_permissions_view` AS - WITH RECURSIVE permissions(user_id, role_id, forum_id, forum_perms_allow, forum_perms_deny) as ( - SELECT - pp.`user_id`, pp.`role_id`, - pc.`forum_id`, - IFNULL(pp.`forum_perms_allow`, 0), IFNULL(pp.`forum_perms_deny`, 0) - FROM `msz_forum_categories` as pc - LEFT JOIN `msz_forum_permissions` as pp - ON pp.`forum_id` = pc.`forum_id` - GROUP BY `user_id`, `role_id`, `forum_id` - UNION ALL - SELECT - permissions.`user_id`, permissions.`role_id`, - cc.`forum_id`, - IFNULL(cp.`forum_perms_allow`, 0) | permissions.`forum_perms_allow`, - IFNULL(cp.`forum_perms_deny`, 0) | permissions.`forum_perms_deny` - FROM `msz_forum_categories` as cc - LEFT JOIN `msz_forum_permissions` as cp - ON cp.`forum_id` = cc.`forum_id` - INNER JOIN permissions - ON cc.`forum_parent` = permissions.`forum_id` - ) - SELECT - `user_id`, `role_id`, `forum_id`, - (BIT_OR(`forum_perms_allow`) &~ BIT_OR(`forum_perms_deny`)) as `forum_perms` - FROM permissions - GROUP BY `user_id`, `role_id`, `forum_id` - "); -} diff --git a/database/2019_05_01_200400_initial_structure.php b/database/2019_05_01_200400_initial_structure.php new file mode 100644 index 00000000..95b248c4 --- /dev/null +++ b/database/2019_05_01_200400_initial_structure.php @@ -0,0 +1,706 @@ +prepare("SELECT COUNT(*) FROM `msz_migrations`"); + $migrations = (int)($getMigrations->execute() ? $getMigrations->fetchColumn() : 0); + + if($migrations > 0) { + $conn->exec("TRUNCATE `msz_migrations`"); + return; + } + + $conn->exec(" + CREATE TABLE `msz_ip_blacklist` ( + `ip_subnet` VARBINARY(16) NOT NULL, + `ip_mask` TINYINT(3) UNSIGNED NOT NULL, + UNIQUE INDEX `ip_blacklist_unique` (`ip_subnet`, `ip_mask`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_roles` ( + `role_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `role_hierarchy` INT(11) NOT NULL DEFAULT '1', + `role_name` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `role_title` VARCHAR(64) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `role_description` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `role_hidden` TINYINT(1) NOT NULL DEFAULT '0', + `role_can_leave` TINYINT(1) NOT NULL DEFAULT '0', + `role_colour` INT(11) NULL DEFAULT NULL, + `role_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`role_id`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_users` ( + `user_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `username` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `password` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `email` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `register_ip` VARBINARY(16) NOT NULL, + `last_ip` VARBINARY(16) NOT NULL, + `user_super` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0', + `user_country` CHAR(2) NOT NULL DEFAULT 'XX' COLLATE 'utf8mb4_bin', + `user_colour` INT(11) NULL DEFAULT NULL, + `user_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `user_active` TIMESTAMP NULL DEFAULT NULL, + `user_deleted` TIMESTAMP NULL DEFAULT NULL, + `display_role` INT(10) UNSIGNED NULL DEFAULT NULL, + `user_totp_key` CHAR(26) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `user_about_content` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `user_about_parser` TINYINT(4) NOT NULL DEFAULT '0', + `user_signature_content` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `user_signature_parser` TINYINT(4) NOT NULL DEFAULT '0', + `user_birthdate` DATE NULL DEFAULT NULL, + `user_background_settings` TINYINT(4) NULL DEFAULT '0', + `user_website` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_twitter` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_github` VARCHAR(40) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_skype` VARCHAR(60) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_discord` VARCHAR(40) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_youtube` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_steam` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_ninswitch` VARCHAR(14) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_twitchtv` VARCHAR(30) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_osu` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_lastfm` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + `user_title` VARCHAR(64) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + PRIMARY KEY (`user_id`), + UNIQUE INDEX `users_username_unique` (`username`), + UNIQUE INDEX `users_email_unique` (`email`), + INDEX `users_display_role_foreign` (`display_role`), + INDEX `users_indices` ( + `user_country`, `user_created`, `user_active`, + `user_deleted`, `user_birthdate` + ), + CONSTRAINT `users_display_role_foreign` + FOREIGN KEY (`display_role`) + REFERENCES `msz_roles` (`role_id`) + ON UPDATE CASCADE + ON DELETE SET NULL + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_user_roles` ( + `user_id` INT(10) UNSIGNED NOT NULL, + `role_id` INT(10) UNSIGNED NOT NULL, + UNIQUE INDEX `user_roles_unique` (`user_id`, `role_id`), + INDEX `user_roles_role_id_foreign` (`role_id`), + CONSTRAINT `user_roles_role_id_foreign` + FOREIGN KEY (`role_id`) + REFERENCES `msz_roles` (`role_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `user_roles_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_users_password_resets` ( + `user_id` INT(10) UNSIGNED NOT NULL, + `reset_ip` VARBINARY(16) NOT NULL, + `reset_requested` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `verification_code` CHAR(12) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + UNIQUE INDEX `msz_users_password_resets_unique` (`user_id`, `reset_ip`), + INDEX `msz_users_password_resets_index` (`reset_requested`), + CONSTRAINT `msz_users_password_resets_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $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`), + INDEX `user_relations_subject_id_foreign` (`subject_id`), + 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; + "); + + $conn->exec(" + CREATE TABLE `msz_user_warnings` ( + `warning_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `user_id` INT(10) UNSIGNED NOT NULL, + `user_ip` VARBINARY(16) NOT NULL, + `issuer_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `issuer_ip` VARBINARY(16) NOT NULL, + `warning_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `warning_duration` TIMESTAMP NULL DEFAULT NULL, + `warning_type` TINYINT(3) UNSIGNED NOT NULL, + `warning_note` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `warning_note_private` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + PRIMARY KEY (`warning_id`), + INDEX `user_warnings_user_foreign` (`user_id`), + INDEX `user_warnings_issuer_foreign` (`issuer_id`), + INDEX `user_warnings_created_index` (`warning_created`), + INDEX `user_warnings_duration_index` (`warning_duration`), + INDEX `user_warnings_type_index` (`warning_type`), + INDEX `user_warnings_user_ip_index` (`user_ip`), + CONSTRAINT `user_warnings_issuer_foreign` + FOREIGN KEY (`issuer_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE SET NULL, + CONSTRAINT `user_warnings_user_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_sessions` ( + `session_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `user_id` INT(10) UNSIGNED NOT NULL, + `session_key` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `session_ip` VARBINARY(16) NOT NULL, + `session_ip_last` VARBINARY(16) NULL DEFAULT NULL, + `session_user_agent` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `session_country` CHAR(2) NOT NULL DEFAULT 'XX' COLLATE 'utf8mb4_bin', + `session_expires` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `session_expires_bump` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', + `session_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `session_active` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`session_id`), + UNIQUE INDEX `sessions_key_unique` (`session_key`), + INDEX `sessions_user_id_foreign` (`user_id`), + INDEX `sessions_expires_index` (`session_expires`), + CONSTRAINT `sessions_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_permissions` ( + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `role_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `general_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `general_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `user_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `user_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `changelog_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `changelog_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `news_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `news_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `forum_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `forum_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `comments_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `comments_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', + UNIQUE INDEX `permissions_user_id_unique` (`user_id`), + UNIQUE INDEX `permissions_role_id_unique` (`role_id`), + CONSTRAINT `permissions_role_id_foreign` + FOREIGN KEY (`role_id`) + REFERENCES `msz_roles` (`role_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `permissions_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_audit_log` ( + `log_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `log_action` VARCHAR(50) NOT NULL COLLATE 'utf8mb4_bin', + `log_params` TEXT NOT NULL COLLATE 'utf8mb4_bin', + `log_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `log_ip` VARBINARY(16) NULL DEFAULT NULL, + `log_country` CHAR(2) NOT NULL DEFAULT 'XX' COLLATE 'utf8mb4_bin', + PRIMARY KEY (`log_id`), + INDEX `audit_log_user_id_foreign` (`user_id`), + CONSTRAINT `audit_log_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_auth_tfa` ( + `user_id` INT(10) UNSIGNED NOT NULL, + `tfa_token` CHAR(32) NOT NULL COLLATE 'utf8mb4_bin', + `tfa_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + UNIQUE INDEX `auth_tfa_token_unique` (`tfa_token`), + INDEX `auth_tfa_user_foreign` (`user_id`), + INDEX `auth_tfa_created_index` (`tfa_created`), + CONSTRAINT `auth_tfa_user_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_login_attempts` ( + `attempt_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `attempt_success` TINYINT(1) NOT NULL, + `attempt_ip` VARBINARY(16) NOT NULL, + `attempt_country` CHAR(2) NOT NULL DEFAULT 'XX' COLLATE 'utf8mb4_bin', + `attempt_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `attempt_user_agent` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'utf8mb4_bin', + PRIMARY KEY (`attempt_id`), + INDEX `login_attempts_user_id_foreign` (`user_id`), + CONSTRAINT `login_attempts_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE SET NULL + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_comments_categories` ( + `category_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `category_name` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `category_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `category_locked` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`category_id`), + UNIQUE INDEX `comments_categories_name_unique` (`category_name`), + INDEX `comments_categories_locked_index` (`category_locked`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_comments_posts` ( + `comment_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `category_id` INT(10) UNSIGNED NOT NULL, + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `comment_reply_to` INT(10) UNSIGNED NULL DEFAULT NULL, + `comment_text` TEXT NOT NULL COLLATE 'utf8mb4_bin', + `comment_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `comment_pinned` TIMESTAMP NULL DEFAULT NULL, + `comment_edited` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + `comment_deleted` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`comment_id`), + INDEX `comments_posts_category_foreign` (`category_id`), + INDEX `comments_posts_user_foreign` (`user_id`), + INDEX `comments_posts_reply_id` (`comment_reply_to`), + INDEX `comments_posts_dates` ( + `comment_created`, `comment_pinned`, + `comment_edited`, `comment_deleted` + ), + CONSTRAINT `comments_posts_category_foreign` + FOREIGN KEY (`category_id`) + REFERENCES `msz_comments_categories` (`category_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `comments_posts_user_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE SET NULL + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_comments_votes` ( + `comment_id` INT(10) UNSIGNED NOT NULL, + `user_id` INT(10) UNSIGNED NOT NULL, + `comment_vote` TINYINT(4) NOT NULL DEFAULT '0', + UNIQUE INDEX `comments_vote_unique` (`comment_id`, `user_id`), + INDEX `comments_vote_user_foreign` (`user_id`), + INDEX `comments_vote_index` (`comment_vote`), + CONSTRAINT `comment_vote_id` + FOREIGN KEY (`comment_id`) + REFERENCES `msz_comments_posts` (`comment_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `comment_vote_user` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_news_categories` ( + `category_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `category_name` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `category_description` TEXT NOT NULL COLLATE 'utf8mb4_bin', + `category_is_hidden` TINYINT(1) NOT NULL DEFAULT '0', + `category_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`category_id`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_news_posts` ( + `post_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `category_id` INT(10) UNSIGNED NOT NULL, + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `comment_section_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `post_is_featured` TINYINT(1) NOT NULL DEFAULT '0', + `post_title` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `post_text` TEXT NOT NULL COLLATE 'utf8mb4_bin', + `post_scheduled` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `post_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `post_updated` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `post_deleted` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`post_id`), + INDEX `news_posts_category_id_foreign` (`category_id`), + INDEX `news_posts_user_id_foreign` (`user_id`), + INDEX `news_posts_comment_section` (`comment_section_id`), + INDEX `news_posts_featured_index` (`post_is_featured`), + INDEX `news_posts_scheduled_index` (`post_scheduled`), + INDEX `news_posts_created_index` (`post_created`), + INDEX `news_posts_updated_index` (`post_updated`), + INDEX `news_posts_deleted_index` (`post_deleted`), + FULLTEXT INDEX `news_posts_fulltext` (`post_title`, `post_text`), + CONSTRAINT `news_posts_category_id_foreign` + FOREIGN KEY (`category_id`) + REFERENCES `msz_news_categories` (`category_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `news_posts_comment_section` + FOREIGN KEY (`comment_section_id`) + REFERENCES `msz_comments_categories` (`category_id`) + ON UPDATE CASCADE + ON DELETE SET NULL, + CONSTRAINT `news_posts_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE SET NULL + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_changelog_tags` ( + `tag_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `tag_name` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `tag_description` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `tag_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `tag_archived` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`tag_id`), + UNIQUE INDEX `tag_name` (`tag_name`), + INDEX `tag_archived` (`tag_archived`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_changelog_changes` ( + `change_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `change_action` INT(10) UNSIGNED NULL DEFAULT NULL, + `change_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `change_log` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `change_text` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + PRIMARY KEY (`change_id`), + INDEX `changes_user_foreign` (`user_id`), + INDEX `changes_action_index` (`change_action`), + INDEX `changes_created_index` (`change_created`), + CONSTRAINT `changes_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE SET NULL + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_changelog_change_tags` ( + `change_id` INT(10) UNSIGNED NOT NULL, + `tag_id` INT(10) UNSIGNED NOT NULL, + UNIQUE INDEX `change_tag_unique` (`change_id`, `tag_id`), + INDEX `tag_id_foreign_key` (`tag_id`), + CONSTRAINT `change_id_foreign_key` + FOREIGN KEY (`change_id`) + REFERENCES `msz_changelog_changes` (`change_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `tag_id_foreign_key` + FOREIGN KEY (`tag_id`) + REFERENCES `msz_changelog_tags` (`tag_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_polls` ( + `poll_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `poll_max_votes` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', + `poll_expires` TIMESTAMP NULL DEFAULT NULL, + `poll_preview_results` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', + `poll_change_vote` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0', + PRIMARY KEY (`poll_id`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_polls_options` ( + `option_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `poll_id` INT(10) UNSIGNED NOT NULL, + `option_text` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + PRIMARY KEY (`option_id`), + INDEX `polls_options_poll_foreign` (`poll_id`), + CONSTRAINT `polls_options_poll_foreign` + FOREIGN KEY (`poll_id`) + REFERENCES `msz_forum_polls` (`poll_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_polls_answers` ( + `user_id` INT(10) UNSIGNED NOT NULL, + `poll_id` INT(10) UNSIGNED NOT NULL, + `option_id` INT(10) UNSIGNED NOT NULL, + UNIQUE INDEX `polls_answers_unique` (`user_id`, `poll_id`, `option_id`), + INDEX `polls_answers_user_foreign` (`user_id`), + INDEX `polls_answers_poll_foreign` (`poll_id`), + INDEX `polls_answers_option_foreign` (`option_id`), + CONSTRAINT `polls_answers_option_foreign` + FOREIGN KEY (`option_id`) + REFERENCES `msz_forum_polls_options` (`option_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `polls_answers_poll_foreign` + FOREIGN KEY (`poll_id`) + REFERENCES `msz_forum_polls` (`poll_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `polls_answers_user_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_categories` ( + `forum_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `forum_order` INT(10) UNSIGNED NOT NULL DEFAULT '1', + `forum_parent` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `forum_name` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `forum_type` TINYINT(4) NOT NULL DEFAULT '0', + `forum_description` TEXT NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `forum_colour` INT(10) UNSIGNED NULL DEFAULT NULL, + `forum_link` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', + `forum_link_clicks` INT(10) UNSIGNED NULL DEFAULT NULL, + `forum_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `forum_archived` TINYINT(1) NOT NULL DEFAULT '0', + `forum_hidden` TINYINT(1) NOT NULL DEFAULT '0', + `forum_count_topics` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `forum_count_posts` INT(10) UNSIGNED NOT NULL DEFAULT '0', + PRIMARY KEY (`forum_id`), + INDEX `forum_order_index` (`forum_order`), + INDEX `forum_parent_index` (`forum_parent`), + INDEX `forum_type_index` (`forum_type`) + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_permissions` ( + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `role_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `forum_id` INT(10) UNSIGNED NOT NULL, + `forum_perms_allow` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `forum_perms_deny` INT(10) UNSIGNED NOT NULL DEFAULT '0', + UNIQUE INDEX `forum_permissions_unique` (`user_id`, `role_id`, `forum_id`), + INDEX `forum_permissions_forum_id` (`forum_id`), + INDEX `forum_permissions_role_id` (`role_id`), + CONSTRAINT `forum_permissions_forum_id_foreign` + FOREIGN KEY (`forum_id`) + REFERENCES `msz_forum_categories` (`forum_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `forum_permissions_role_id_foreign` + FOREIGN KEY (`role_id`) + REFERENCES `msz_roles` (`role_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `forum_permissions_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_topics` ( + `topic_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `forum_id` INT(10) UNSIGNED NOT NULL, + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `poll_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `topic_type` TINYINT(4) NOT NULL DEFAULT '0', + `topic_title` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_bin', + `topic_count_views` INT(10) UNSIGNED NOT NULL DEFAULT '0', + `topic_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `topic_bumped` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `topic_deleted` TIMESTAMP NULL DEFAULT NULL, + `topic_locked` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`topic_id`), + INDEX `topics_forum_id_foreign` (`forum_id`), + INDEX `topics_user_id_foreign` (`user_id`), + INDEX `topics_type_index` (`topic_type`), + INDEX `topics_created_index` (`topic_created`), + INDEX `topics_bumped_index` (`topic_bumped`), + INDEX `topics_deleted_index` (`topic_deleted`), + INDEX `topics_locked_index` (`topic_locked`), + INDEX `posts_poll_id_foreign` (`poll_id`), + FULLTEXT INDEX `topics_fulltext` (`topic_title`), + CONSTRAINT `posts_poll_id_foreign` + FOREIGN KEY (`poll_id`) + REFERENCES `msz_forum_polls` (`poll_id`) + ON UPDATE CASCADE + ON DELETE SET NULL, + CONSTRAINT `topics_forum_id_foreign` + FOREIGN KEY (`forum_id`) + REFERENCES `msz_forum_categories` (`forum_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `topics_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_topics_track` ( + `user_id` INT(10) UNSIGNED NOT NULL, + `topic_id` INT(10) UNSIGNED NOT NULL, + `forum_id` INT(10) UNSIGNED NOT NULL, + `track_last_read` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + UNIQUE INDEX `topics_track_unique` (`user_id`, `topic_id`), + INDEX `topics_track_topic_id_foreign` (`topic_id`), + INDEX `topics_track_user_id_foreign` (`user_id`), + INDEX `topics_track_forum_id_foreign` (`forum_id`), + INDEX `forum_track_last_read` (`track_last_read`), + CONSTRAINT `topics_track_forum_id_foreign` + FOREIGN KEY (`forum_id`) + REFERENCES `msz_forum_categories` (`forum_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `topics_track_topic_id_foreign` + FOREIGN KEY (`topic_id`) + REFERENCES `msz_forum_topics` (`topic_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `topics_track_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE CASCADE + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); + + $conn->exec(" + CREATE TABLE `msz_forum_posts` ( + `post_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `topic_id` INT(10) UNSIGNED NOT NULL, + `forum_id` INT(10) UNSIGNED NOT NULL, + `user_id` INT(10) UNSIGNED NULL DEFAULT NULL, + `post_ip` VARBINARY(16) NOT NULL, + `post_text` TEXT NOT NULL COLLATE 'utf8mb4_bin', + `post_parse` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0', + `post_display_signature` TINYINT(4) UNSIGNED NOT NULL DEFAULT '1', + `post_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `post_edited` TIMESTAMP NULL DEFAULT NULL, + `post_deleted` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`post_id`), + INDEX `posts_topic_id_foreign` (`topic_id`), + INDEX `posts_forum_id_foreign` (`forum_id`), + INDEX `posts_user_id_foreign` (`user_id`), + INDEX `posts_created_index` (`post_created`), + INDEX `posts_deleted_index` (`post_deleted`), + INDEX `posts_parse_index` (`post_parse`), + INDEX `posts_edited_index` (`post_edited`), + INDEX `posts_display_signature_index` (`post_display_signature`), + INDEX `posts_ip_index` (`post_ip`), + FULLTEXT INDEX `posts_fulltext` (`post_text`), + CONSTRAINT `posts_forum_id_foreign` + FOREIGN KEY (`forum_id`) + REFERENCES `msz_forum_categories` (`forum_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `posts_topic_id_foreign` + FOREIGN KEY (`topic_id`) + REFERENCES `msz_forum_topics` (`topic_id`) + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT `posts_user_id_foreign` + FOREIGN KEY (`user_id`) + REFERENCES `msz_users` (`user_id`) + ON UPDATE CASCADE + ON DELETE SET NULL + ) COLLATE='utf8mb4_bin' ENGINE=InnoDB; + "); +} + +function migrate_down(PDO $conn): void +{ + $conn->exec("DROP TABLE `msz_forum_posts`"); + $conn->exec("DROP TABLE `msz_forum_topics_track`"); + $conn->exec("DROP TABLE `msz_forum_topics`"); + $conn->exec("DROP TABLE `msz_forum_permissions`"); + $conn->exec("DROP TABLE `msz_forum_categories`"); + $conn->exec("DROP TABLE `msz_forum_polls_answers`"); + $conn->exec("DROP TABLE `msz_forum_polls_options`"); + $conn->exec("DROP TABLE `msz_forum_polls`"); + $conn->exec("DROP TABLE `msz_changelog_change_tags`"); + $conn->exec("DROP TABLE `msz_changelog_changes`"); + $conn->exec("DROP TABLE `msz_changelog_tags`"); + $conn->exec("DROP TABLE `msz_news_posts`"); + $conn->exec("DROP TABLE `msz_news_categories`"); + $conn->exec("DROP TABLE `msz_comments_votes`"); + $conn->exec("DROP TABLE `msz_comments_posts`"); + $conn->exec("DROP TABLE `msz_comments_categories`"); + $conn->exec("DROP TABLE `msz_login_attempts`"); + $conn->exec("DROP TABLE `msz_auth_tfa`"); + $conn->exec("DROP TABLE `msz_audit_log`"); + $conn->exec("DROP TABLE `msz_permissions`"); + $conn->exec("DROP TABLE `msz_sessions`"); + $conn->exec("DROP TABLE `msz_user_warnings`"); + $conn->exec("DROP TABLE `msz_user_relations`"); + $conn->exec("DROP TABLE `msz_users_password_resets`"); + $conn->exec("DROP TABLE `msz_user_roles`"); + $conn->exec("DROP TABLE `msz_users`"); + $conn->exec("DROP TABLE `msz_roles`"); + $conn->exec("DROP TABLE `msz_ip_blacklist`"); +}