mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-04 19:07:14 +00:00
fix(migrations): skip existing columns and indexes on databases migrated elsewhere
On a database NexusDashboard (or a server's own changes) already migrated, 29, 30 and 40 logged an error for every column that was already there, and 40 and 57 added a second index on columns MariaDB had already indexed for the inline REFERENCES foreign keys of 0_initial.sql. Add those columns and indexes only when information_schema says they are missing. 40 also gives pet_names.owner_id values written before 23_store_character_id_as_objectid.sql the persistent bit, as 23 did for every other character id column, so they match characters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
/* Account email for password resets. email/email_confirmed_at match NexusDashboard's columns so existing data is kept,
|
||||
statements for columns that already exist fail individually and are skipped. */
|
||||
ALTER TABLE accounts ADD COLUMN email VARCHAR(255) NULL DEFAULT '';
|
||||
ALTER TABLE accounts ADD COLUMN email_confirmed_at DATETIME NULL DEFAULT NULL;
|
||||
/* Account email for password resets. email/email_confirmed_at match NexusDashboard's columns so existing data is kept:
|
||||
they are only added when they are not there yet. */
|
||||
SET @dlu_column = (SELECT IF(COUNT(*) = 0, 'ALTER TABLE accounts ADD COLUMN email VARCHAR(255) NULL DEFAULT ''''', 'DO 0') FROM information_schema.columns
|
||||
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'email');
|
||||
PREPARE dlu_column_stmt FROM @dlu_column;
|
||||
EXECUTE dlu_column_stmt;
|
||||
DEALLOCATE PREPARE dlu_column_stmt;
|
||||
SET @dlu_column = (SELECT IF(COUNT(*) = 0, 'ALTER TABLE accounts ADD COLUMN email_confirmed_at DATETIME NULL DEFAULT NULL', 'DO 0') FROM information_schema.columns
|
||||
WHERE table_schema = DATABASE() AND table_name = 'accounts' AND column_name = 'email_confirmed_at');
|
||||
PREPARE dlu_column_stmt FROM @dlu_column;
|
||||
EXECUTE dlu_column_stmt;
|
||||
DEALLOCATE PREPARE dlu_column_stmt;
|
||||
/* Sessions issued before this unix time are rejected, e.g. after a password reset */
|
||||
ALTER TABLE accounts ADD COLUMN sessions_valid_after BIGINT NOT NULL DEFAULT 0;
|
||||
CREATE TABLE IF NOT EXISTS account_tokens (
|
||||
|
||||
Reference in New Issue
Block a user