From b66e0fd6901847dc21cd3b2c5248971ada6798a7 Mon Sep 17 00:00:00 2001 From: meepen Date: Thu, 4 Apr 2024 10:59:35 -0400 Subject: [PATCH] update init.sql --- init.sql | 91 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/init.sql b/init.sql index 5d3841e..de896e9 100644 --- a/init.sql +++ b/init.sql @@ -1,44 +1,55 @@ -CREATE TABLE accounts ( - uuid BINARY(16) NOT NULL PRIMARY KEY, - username VARCHAR(16) NOT NULL, - hash BINARY(32) NOT NULL, - salt BINARY(16) NOT NULL, - registered DATETIME NOT NULL DEFAULT NOW(), - lastActivity DATETIME NOT NULL DEFAULT NOW(), - lastLoggedIn DATETIME NULL, - INDEX (lastActivity), - INDEX (username), - UNIQUE (username) -); +CREATE TABLE `accounts` ( + `uuid` binary(16) NOT NULL, + `username` varchar(16) NOT NULL, + `hash` binary(32) NOT NULL, + `salt` binary(16) NOT NULL, + `registered` timestamp NOT NULL, + `lastLoggedIn` timestamp NULL DEFAULT NULL, + `lastActivity` timestamp NULL DEFAULT NULL, + `banned` tinyint(2) NOT NULL DEFAULT 0, + PRIMARY KEY (`uuid`), + UNIQUE KEY `username` (`username`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci -CREATE TABLE sessions ( - token BINARY(32) NOT NULL PRIMARY KEY, - uuid BINARY(16) NOT NULL, - expire DATETIME NOT NULL, - FOREIGN KEY (uuid) REFERENCES accounts(uuid) ON DELETE CASCADE -); -CREATE TABLE dailyRuns ( - seed VARCHAR(255) NOT NULL, - date DATE NOT NULL PRIMARY KEY -); +CREATE TABLE `sessions` ( + `token` binary(32) NOT NULL, + `uuid` binary(16) NOT NULL, + `expire` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`token`), + KEY `uuid` (`uuid`), + CONSTRAINT `uuid` FOREIGN KEY (`uuid`) REFERENCES `accounts` (`uuid`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci -CREATE TABLE accountDailyRuns ( - uuid BINARY(16) NOT NULL PRIMARY KEY, - date DATE NOT NULL, - score INT NOT NULL, - wave INT NOT NULL, - timestamp DATETIME, - FOREIGN KEY (date) REFERENCES dailyRuns(date), - FOREIGN KEY (uuid) REFERENCES accounts(uuid) ON DELETE CASCADE, - UNIQUE (uuid, date) -); -CREATE TABLE seedCompletions ( - uuid BINARY(16) NOT NULL PRIMARY KEY, - seed VARCHAR(255) NOT NULL, - mode INT NOT NULL, - timestamp DATETIME NOT NULL DEFAULT NOW(), - FOREIGN KEY (uuid) REFERENCES accounts(uuid) ON DELETE CASCADE, - UNIQUE (seed, mode, uuid) -); +CREATE TABLE `seedCompletions` ( + `uuid` binary(16) NOT NULL, + `seed` char(24) NOT NULL, + `mode` int(11) NOT NULL DEFAULT 0, + `timestamp` timestamp NOT NULL, + `score` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`uuid`,`seed`), + KEY `uuid` (`uuid`), + CONSTRAINT `seedCompletions_ibfk_1` FOREIGN KEY (`uuid`) REFERENCES `accounts` (`uuid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci + + +CREATE TABLE `dailyRuns` ( + `date` date NOT NULL, + `seed` char(24) NOT NULL, + PRIMARY KEY (`date`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci + + +CREATE TABLE `accountDailyRuns` ( + `uuid` binary(16) NOT NULL, + `date` date NOT NULL, + `timestamp` timestamp NOT NULL, + `score` int(11) NOT NULL DEFAULT 0, + `wave` int(11) NOT NULL, + PRIMARY KEY (`uuid`,`date`), + KEY `uuid` (`uuid`), + KEY `date` (`date`), + CONSTRAINT `accountDailyRuns_ibfk_1` FOREIGN KEY (`uuid`) REFERENCES `accounts` (`uuid`), + CONSTRAINT `accountDailyRuns_ibfk_2` FOREIGN KEY (`date`) REFERENCES `dailyRuns` (`date`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci \ No newline at end of file