128 lines
6.3 KiB
PHP
128 lines
6.3 KiB
PHP
|
<?php
|
||
|
use Index\Db\DbConnection;
|
||
|
use Index\Db\Migration\DbMigration;
|
||
|
|
||
|
final class MakeColumnNamesConsistent_20250207_215843 implements DbMigration {
|
||
|
public function migrate(DbConnection $conn): void {
|
||
|
$conn->execute(<<<SQL
|
||
|
ALTER TABLE msz_audit_log
|
||
|
CHANGE COLUMN log_ip log_remote_addr VARBINARY(16) NULL DEFAULT NULL AFTER log_created;
|
||
|
SQL);
|
||
|
|
||
|
$conn->execute(<<<SQL
|
||
|
ALTER TABLE msz_comments_categories
|
||
|
DROP FOREIGN KEY comments_categories_owner_foreign;
|
||
|
SQL);
|
||
|
$conn->execute(<<<SQL
|
||
|
ALTER TABLE msz_comments_categories
|
||
|
CHANGE COLUMN owner_id user_id INT(10) UNSIGNED NULL DEFAULT NULL AFTER category_name,
|
||
|
DROP INDEX comments_categories_owner_foreign,
|
||
|
ADD INDEX comments_categories_user_foreign (user_id),
|
||
|
ADD CONSTRAINT comments_categories_user_foreign
|
||
|
FOREIGN KEY (user_id)
|
||
|
REFERENCES msz_users (user_id)
|
||
|
ON UPDATE CASCADE
|
||
|
ON DELETE SET NULL;
|
||
|
SQL);
|
||
|
|
||
|
$conn->execute(<<<SQL
|
||
|
ALTER TABLE msz_emoticons
|
||
|
CHANGE COLUMN emote_hierarchy emote_rank INT(11) NOT NULL DEFAULT '0' AFTER emote_order,
|
||
|
DROP INDEX emotes_hierarchy,
|
||
|
ADD INDEX emotes_rank (emote_rank);
|
||
|
SQL);
|
||
|
|
||
|
$conn->execute(<<<SQL
|
||
|
ALTER TABLE msz_forum_posts
|
||
|
CHANGE COLUMN post_ip post_remote_addr VARBINARY(16) NOT NULL AFTER user_id,
|
||
|
DROP INDEX posts_ip_index,
|
||
|
ADD INDEX posts_remote_addr_index (post_remote_addr);
|
||
|
SQL);
|
||
|
|
||
|
$conn->execute(<<<SQL
|
||
|
ALTER TABLE msz_forum_topics_redirects
|
||
|
CHANGE COLUMN topic_redir_url redir_url VARCHAR(255) NOT NULL COLLATE 'ascii_bin' AFTER user_id,
|
||
|
CHANGE COLUMN topic_redir_created redir_created TIMESTAMP NOT NULL DEFAULT current_timestamp() AFTER redir_url;
|
||
|
SQL);
|
||
|
|
||
|
$conn->execute(<<<SQL
|
||
|
ALTER TABLE msz_login_attempts
|
||
|
ADD COLUMN attempt_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT FIRST,
|
||
|
CHANGE COLUMN attempt_ip attempt_remote_addr VARBINARY(16) NOT NULL AFTER attempt_success,
|
||
|
DROP INDEX login_attempts_ip_index,
|
||
|
ADD INDEX login_attempts_remote_addr_index (attempt_remote_addr),
|
||
|
ADD PRIMARY KEY (attempt_id);
|
||
|
SQL);
|
||
|
|
||
|
$conn->execute(<<<SQL
|
||
|
ALTER TABLE msz_news_categories
|
||
|
CHANGE COLUMN category_is_hidden category_hidden TINYINT(1) NOT NULL DEFAULT '0' AFTER category_description,
|
||
|
DROP INDEX news_categories_is_hidden_index,
|
||
|
ADD INDEX news_categories_hidden_index (category_hidden);
|
||
|
SQL);
|
||
|
|
||
|
$conn->execute(<<<SQL
|
||
|
ALTER TABLE msz_news_posts
|
||
|
CHANGE COLUMN post_is_featured post_featured TINYINT(1) NOT NULL DEFAULT '0' AFTER comment_section_id,
|
||
|
DROP INDEX news_posts_featured_index,
|
||
|
ADD INDEX news_posts_featured_index (post_featured);
|
||
|
SQL);
|
||
|
|
||
|
$conn->execute(<<<SQL
|
||
|
ALTER TABLE msz_roles
|
||
|
CHANGE COLUMN role_hierarchy role_rank INT(11) NOT NULL DEFAULT '1' AFTER role_string,
|
||
|
DROP INDEX roles_hierarchy_index,
|
||
|
ADD INDEX roles_rank_index (role_rank);
|
||
|
SQL);
|
||
|
|
||
|
$conn->execute(<<<SQL
|
||
|
ALTER TABLE msz_sessions
|
||
|
CHANGE COLUMN session_ip session_remote_addr_first VARBINARY(16) NOT NULL AFTER session_key,
|
||
|
CHANGE COLUMN session_ip_last session_remote_addr_last VARBINARY(16) NULL DEFAULT NULL AFTER session_remote_addr_first;
|
||
|
SQL);
|
||
|
|
||
|
$conn->execute(<<<SQL
|
||
|
ALTER TABLE msz_users
|
||
|
CHANGE COLUMN username user_name VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_520_ci' AFTER user_id,
|
||
|
CHANGE COLUMN password user_password VARCHAR(255) NULL DEFAULT NULL COLLATE 'ascii_bin' AFTER user_name,
|
||
|
CHANGE COLUMN email user_email VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_520_ci' AFTER user_password,
|
||
|
CHANGE COLUMN register_ip user_remote_addr_first VARBINARY(16) NOT NULL AFTER user_email,
|
||
|
CHANGE COLUMN last_ip user_remote_addr_last VARBINARY(16) NOT NULL AFTER user_remote_addr_first,
|
||
|
CHANGE COLUMN display_role user_display_role_id INT(10) UNSIGNED NULL DEFAULT NULL AFTER user_deleted,
|
||
|
DROP INDEX users_indices,
|
||
|
DROP INDEX users_username_unique,
|
||
|
ADD UNIQUE INDEX users_name_unique (user_name),
|
||
|
DROP INDEX users_email_unique,
|
||
|
ADD UNIQUE INDEX users_email_unique (user_email),
|
||
|
DROP INDEX users_display_role_foreign,
|
||
|
ADD INDEX users_display_role_foreign (user_display_role_id),
|
||
|
ADD INDEX users_created_index (user_created),
|
||
|
ADD INDEX users_country_index (user_country),
|
||
|
ADD INDEX users_active_index (user_active),
|
||
|
ADD INDEX users_deleted_index (user_deleted),
|
||
|
ADD INDEX users_birthdate_index (user_birthdate);
|
||
|
SQL);
|
||
|
|
||
|
$conn->execute(<<<SQL
|
||
|
ALTER TABLE msz_users_password_resets
|
||
|
DROP FOREIGN KEY msz_users_password_resets_user_id_foreign;
|
||
|
SQL);
|
||
|
$conn->execute(<<<SQL
|
||
|
ALTER TABLE msz_users_password_resets
|
||
|
ADD COLUMN reset_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT FIRST,
|
||
|
CHANGE COLUMN reset_ip reset_remote_addr VARBINARY(16) NOT NULL AFTER user_id,
|
||
|
CHANGE COLUMN verification_code reset_code CHAR(12) NULL DEFAULT NULL COLLATE 'ascii_general_ci' AFTER reset_requested,
|
||
|
DROP INDEX users_password_resets_user_unique,
|
||
|
ADD UNIQUE INDEX users_password_resets_unique (user_id, reset_remote_addr),
|
||
|
DROP INDEX users_password_resets_token_unique,
|
||
|
ADD UNIQUE INDEX users_password_resets_code_unique (reset_code),
|
||
|
ADD PRIMARY KEY (reset_id),
|
||
|
ADD CONSTRAINT msz_users_password_resets_users_foreign
|
||
|
FOREIGN KEY (user_id)
|
||
|
REFERENCES msz_users (user_id)
|
||
|
ON UPDATE CASCADE
|
||
|
ON DELETE CASCADE;
|
||
|
SQL);
|
||
|
}
|
||
|
}
|