mirror of
https://git.sr.ht/~iwakuralain/text0Nly
synced 2025-07-27 15:36:11 +00:00
migrate optimise
This commit is contained in:
parent
596ce57099
commit
e4ef0e051d
52
main/db.sql
52
main/db.sql
@ -27,3 +27,55 @@ CREATE TABLE registrations (
|
|||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
INDEX idx_created_at (created_at)
|
INDEX idx_created_at (created_at)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DELIMITER //
|
||||||
|
CREATE PROCEDURE migrate_if_needed()
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'messages') THEN
|
||||||
|
CREATE TABLE messages (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
username VARCHAR(50) NOT NULL,
|
||||||
|
message TEXT NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
signature TEXT,
|
||||||
|
is_encrypted BOOLEAN DEFAULT FALSE,
|
||||||
|
INDEX idx_created_at (created_at)
|
||||||
|
);
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'users') THEN
|
||||||
|
CREATE TABLE users (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
username VARCHAR(50) NOT NULL UNIQUE,
|
||||||
|
password VARCHAR(255) NOT NULL,
|
||||||
|
pgp_key TEXT,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
is_moderator TINYINT(1) NOT NULL DEFAULT 0,
|
||||||
|
login_attempts INT NOT NULL DEFAULT 0,
|
||||||
|
last_attempt TIMESTAMP NULL,
|
||||||
|
is_blocked TINYINT(1) NOT NULL DEFAULT 0,
|
||||||
|
block_reason TEXT,
|
||||||
|
INDEX idx_username (username)
|
||||||
|
);
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = 'registrations') THEN
|
||||||
|
CREATE TABLE registrations (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
INDEX idx_created_at (created_at)
|
||||||
|
);
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF EXISTS (
|
||||||
|
SELECT * FROM information_schema.columns
|
||||||
|
WHERE table_name = 'registrations' AND column_name = 'ip'
|
||||||
|
) THEN
|
||||||
|
DROP INDEX IF EXISTS idx_ip_created ON registrations;
|
||||||
|
ALTER TABLE registrations DROP COLUMN ip;
|
||||||
|
END IF;
|
||||||
|
END //
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
|
CALL migrate_if_needed();
|
||||||
|
DROP PROCEDURE IF EXISTS migrate_if_needed;
|
Loading…
x
Reference in New Issue
Block a user