From 1372d4d285509addaaffce5127c53e0309ed4dc4 Mon Sep 17 00:00:00 2001 From: ajdj100 Date: Thu, 12 Feb 2026 00:03:05 -0500 Subject: [PATCH] added writing initial state history --- ...204140912-state-history-suspensions-up.sql | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/api/migrations/sqls/20260204140912-state-history-suspensions-up.sql b/api/migrations/sqls/20260204140912-state-history-suspensions-up.sql index d0c060a..650645a 100644 --- a/api/migrations/sqls/20260204140912-state-history-suspensions-up.sql +++ b/api/migrations/sqls/20260204140912-state-history-suspensions-up.sql @@ -6,7 +6,6 @@ CREATE TABLE IF NOT EXISTS account_states ( updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, UNIQUE KEY uq_account_states_name (name) ); - INSERT IGNORE INTO account_states (name) VALUES ('guest'), ('applicant'), @@ -16,15 +15,12 @@ VALUES ('guest'), ('suspended'), ('banned'), ('denied'); - ALTER TABLE members RENAME COLUMN state TO state_legacy; - ALTER TABLE members ADD COLUMN state INT NOT NULL DEFAULT 1, ADD INDEX idx_members_state (state), ADD CONSTRAINT fk_members_state_id FOREIGN KEY (state) REFERENCES account_states(id); - CREATE TABLE IF NOT EXISTS member_state_history ( id INT AUTO_INCREMENT PRIMARY KEY, member_id INT NOT NULL, @@ -40,8 +36,22 @@ CREATE TABLE IF NOT EXISTS member_state_history ( CONSTRAINT fk_member_state_type FOREIGN KEY (state_id) REFERENCES account_states(id), CONSTRAINT fk_member_state_history_created_by FOREIGN KEY (created_by_id) REFERENCES members(id) ); - -- Convert member states to new system UPDATE members m JOIN account_states s ON m.state_legacy = s.name -SET m.state = s.id; \ No newline at end of file +SET m.state = s.id; + +-- Initial history population +INSERT INTO member_state_history ( + member_id, + state_id, + reason, + start_date, + created_at + ) +SELECT id, + state, + 'history start', + CURDATE(), + NOW() +FROM members; \ No newline at end of file