mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-09 14:23:44 +00:00
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>
23 lines
1.3 KiB
SQL
23 lines
1.3 KiB
SQL
/* 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 (
|
|
token_hash CHAR(64) NOT NULL PRIMARY KEY,
|
|
account_id INT NOT NULL,
|
|
purpose VARCHAR(16) NOT NULL,
|
|
data VARCHAR(255) NOT NULL DEFAULT '',
|
|
expires_at BIGINT NOT NULL,
|
|
INDEX account_tokens_account (account_id, purpose)
|
|
);
|