Skip to content

Commit

Permalink
refactor(sql)!: add fulltext indexes for name and accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWasTakenn committed Aug 30, 2024
1 parent 02a6cf5 commit 4b3524f
Showing 1 changed file with 55 additions and 34 deletions.
89 changes: 55 additions & 34 deletions sql/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,41 @@ CREATE TABLE IF NOT EXISTS `users` (
PRIMARY KEY (`userId`)
);

CREATE TABLE IF NOT EXISTS `characters` (
`charId` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`userId` INT UNSIGNED NOT NULL,
`stateId` VARCHAR(7) NOT NULL,
`firstName` VARCHAR(50) NOT NULL,
`lastName` VARCHAR(50) NOT NULL,
`gender` VARCHAR(10) NOT NULL,
`dateOfBirth` DATE NOT NULL,
`phoneNumber` VARCHAR(20) DEFAULT NULL,
`lastPlayed` DATETIME NOT NULL DEFAULT (CURRENT_TIMESTAMP()),
`isDead` TINYINT(1) NOT NULL DEFAULT 0,
`x` FLOAT DEFAULT NULL,
`y` FLOAT DEFAULT NULL,
`z` FLOAT DEFAULT NULL,
`heading` FLOAT DEFAULT NULL,
`health` TINYINT UNSIGNED DEFAULT NULL,
`armour` TINYINT UNSIGNED DEFAULT NULL,
`statuses` JSON NOT NULL DEFAULT (JSON_OBJECT()),
`deleted` DATE NULL DEFAULT NULL,
PRIMARY KEY (`charId`),
KEY `characters_userId_key` (`userId`),
UNIQUE KEY `characters_stateId_unique` (`stateId`),
CONSTRAINT `characters_userId_fk` FOREIGN KEY (`userId`) REFERENCES `users` (`userId`) ON DELETE CASCADE ON UPDATE CASCADE
CREATE TABLE IF NOT EXISTS `characters`
(
`charId` INT UNSIGNED AUTO_INCREMENT
PRIMARY KEY,
`userId` INT UNSIGNED NOT NULL,
`stateId` VARCHAR(7) NOT NULL,
`firstName` VARCHAR(50) NOT NULL,
`lastName` VARCHAR(50) NOT NULL,
`gender` VARCHAR(10) NOT NULL,
`dateOfBirth` DATE NOT NULL,
`phoneNumber` VARCHAR(20) NULL,
`lastPlayed` DATETIME DEFAULT CURRENT_TIMESTAMP() NOT NULL,
`isDead` TINYINT(1) DEFAULT 0 NOT NULL,
`x` FLOAT NULL,
`y` FLOAT NULL,
`z` FLOAT NULL,
`heading` FLOAT NULL,
`health` TINYINT UNSIGNED NULL,
`armour` TINYINT UNSIGNED NULL,
`statuses` LONGTEXT COLLATE utf8mb4_bin DEFAULT JSON_OBJECT() NOT NULL
CHECK (JSON_VALID(`statuses`)),
`deleted` DATE NULL,
CONSTRAINT `characters_stateId_unique`
UNIQUE (`stateId`),
CONSTRAINT `characters_userId_fk`
FOREIGN KEY (`userId`) REFERENCES `users` (`userId`)
ON UPDATE CASCADE ON DELETE CASCADE
);

CREATE FULLTEXT INDEX IF NOT EXISTS `characters_firstName_lastName_index`
ON `characters` (`firstName`, `lastName`);

CREATE INDEX IF NOT EXISTS `characters_userId_key`
ON `characters` (`userId`);

CREATE TABLE IF NOT EXISTS `character_inventory` (
`charId` INT UNSIGNED NOT NULL,
`inventory` JSON NULL DEFAULT NULL,
Expand Down Expand Up @@ -135,19 +145,27 @@ CREATE TABLE IF NOT EXISTS `character_licenses` (
CONSTRAINT `character_licenses_charId_fk` FOREIGN KEY (`charId`) REFERENCES `characters` (`charId`) ON DELETE CASCADE ON UPDATE CASCADE
);

CREATE TABLE IF NOT EXISTS `accounts` (
`id` INT UNSIGNED NOT NULL,
`label` VARCHAR(50) NOT NULL,
`owner` INT UNSIGNED NULL,
`group` VARCHAR(20) NULL,
`balance` INT DEFAULT 0 NOT NULL,
`isDefault` TINYINT (1) DEFAULT 0 NOT NULL,
`type` ENUM ('personal', 'shared', 'group', 'inactive') DEFAULT 'personal' NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `accounts_owner_fk` FOREIGN KEY (`owner`) REFERENCES `characters` (`charId`) ON UPDATE SET NULL ON DELETE SET NULL,
CONSTRAINT `accounts_group_fk` FOREIGN KEY (`group`) REFERENCES `ox_groups` (`name`) ON UPDATE SET NULL ON DELETE SET NULL
CREATE TABLE IF NOT EXISTS `accounts`
(
`id` INT UNSIGNED NOT NULL
PRIMARY KEY,
`label` VARCHAR(50) NOT NULL,
`owner` INT UNSIGNED NULL,
`group` VARCHAR(20) NULL,
`balance` INT DEFAULT 0 NOT NULL,
`isDefault` TINYINT(1) DEFAULT 0 NOT NULL,
`type` ENUM ('personal', 'shared', 'group', 'inactive') DEFAULT 'personal' NOT NULL,
CONSTRAINT `accounts_group_fk`
FOREIGN KEY (`group`) REFERENCES `ox_groups` (`name`)
ON UPDATE SET NULL ON DELETE SET NULL,
CONSTRAINT `accounts_owner_fk`
FOREIGN KEY (`owner`) REFERENCES `characters` (`charId`)
ON UPDATE SET NULL ON DELETE SET NULL
);

CREATE FULLTEXT INDEX IF NOT EXISTS `accounts_label_index`
ON `accounts` (`label`);

CREATE TABLE `account_roles` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL DEFAULT '',
Expand Down Expand Up @@ -233,6 +251,9 @@ CREATE TABLE IF NOT EXISTS `accounts_invoices`
FOREIGN KEY (`actorId`) REFERENCES `characters` (`charId`)
);

CREATE FULLTEXT INDEX IF NOT EXISTS `idx_message_fulltext`
ON `accounts_invoices` (`message`);

/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;

/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
Expand Down

0 comments on commit 4b3524f

Please sign in to comment.