diff --git a/_database/sql/migrations/2026-06-03-022928-0000_user_email_changes/down.sql b/_database/sql/migrations/2026-06-03-022928-0000_user_email_changes/down.sql new file mode 100644 index 0000000000..a3b0a074e2 --- /dev/null +++ b/_database/sql/migrations/2026-06-03-022928-0000_user_email_changes/down.sql @@ -0,0 +1,5 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +DROP TABLE IF EXISTS user_email_changes; diff --git a/_database/sql/migrations/2026-06-03-022928-0000_user_email_changes/up.sql b/_database/sql/migrations/2026-06-03-022928-0000_user_email_changes/up.sql new file mode 100644 index 0000000000..58923e125c --- /dev/null +++ b/_database/sql/migrations/2026-06-03-022928-0000_user_email_changes/up.sql @@ -0,0 +1,35 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +CREATE TABLE user_email_changes ( + id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, + + -- The user whose email was changed. + user_token VARCHAR(32) NOT NULL, + + -- The email address before the change. + old_email VARCHAR(255) NOT NULL, + + -- The email address after the change. + new_email VARCHAR(255) NOT NULL, + + -- The IP address the change was made from. + -- Wide enough for IPv4/6. + ip_address VARCHAR(40) NOT NULL, + + -- The user that performed the change, if known. NULL when the change was + -- performed by the user themselves, by an automated process, or in any + -- other context where there is no acting user. + maybe_changed_by_user_token VARCHAR(32) DEFAULT NULL, + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + + -- INDICES -- + PRIMARY KEY (id), + KEY index_user_token (user_token), + KEY index_old_email (old_email), + KEY index_new_email (new_email), + KEY index_created_at (created_at) + +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; diff --git a/_database/sql/migrations_squashed/user_tables/user_email_changes.sql b/_database/sql/migrations_squashed/user_tables/user_email_changes.sql new file mode 100644 index 0000000000..14eb8c7c39 --- /dev/null +++ b/_database/sql/migrations_squashed/user_tables/user_email_changes.sql @@ -0,0 +1,38 @@ +-- NB: This is a manually squashed view of all the CREATE and ALTER statements, +-- with comments attached to the fields for centralized documentation. + +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +CREATE TABLE user_email_changes ( + id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, + + -- The user whose email was changed. + user_token VARCHAR(32) NOT NULL, + + -- The email address before the change. + old_email VARCHAR(255) NOT NULL, + + -- The email address after the change. + new_email VARCHAR(255) NOT NULL, + + -- The IP address the change was made from. + -- Wide enough for IPv4/6. + ip_address VARCHAR(40) NOT NULL, + + -- The user that performed the change, if known. NULL when the change was + -- performed by the user themselves, by an automated process, or in any + -- other context where there is no acting user. + maybe_changed_by_user_token VARCHAR(32) DEFAULT NULL, + + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + + -- INDICES -- + PRIMARY KEY (id), + KEY index_user_token (user_token), + KEY index_old_email (old_email), + KEY index_new_email (new_email), + KEY index_created_at (created_at) + +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;