Mineplex2018-withcommit/Plugins/Mineplex.ReportSite/sql/upgrade.sql

129 lines
4.8 KiB
SQL

/**
These queries must be executed before attempting to use the report-v2 branch otherwise the software
will not function at all.
*/
/**
Drop old tables created by previous developers of the report and chatsnap system.
*/
DROP TABLE IF EXISTS reportTickets;
DROP TABLE IF EXISTS chatsnap;
/**
Create new schema used for v2
*/
CREATE TABLE reportCategoryTypes
(
id TINYINT(4) unsigned PRIMARY KEY NOT NULL,
name VARCHAR(16) NOT NULL
);
CREATE TABLE reports
(
id INT(11) unsigned PRIMARY KEY NOT NULL AUTO_INCREMENT,
suspectId INT(11) NOT NULL,
categoryId TINYINT(4) unsigned NOT NULL,
CONSTRAINT accounts_accountsId_id_fk FOREIGN KEY (suspectId) REFERENCES accounts (id),
CONSTRAINT reportCategoryTypes_categoryId_id_fk FOREIGN KEY (categoryId) REFERENCES reportCategoryTypes (id)
);
CREATE INDEX reportCategoryTypes_categoryId_id_fk ON reports (categoryId);
CREATE INDEX reports_suspect_id_index ON reports (suspectId);
CREATE TABLE reportHandlers
(
reportId INT(10) unsigned PRIMARY KEY NOT NULL,
handlerId INT(11) NOT NULL,
CONSTRAINT reportHandlers_reports_id_fk FOREIGN KEY (reportId) REFERENCES reports (id),
CONSTRAINT reportHandlers_accountStat_accountId_fk FOREIGN KEY (handlerId) REFERENCES accounts (id)
);
CREATE INDEX reportHandlers_accountStat_accountId_fk ON reportHandlers (handlerId);
CREATE TABLE reportReasons
(
reportId INT(11) unsigned NOT NULL,
reporterId INT(11) NOT NULL,
reason VARCHAR(100) NOT NULL,
server VARCHAR(50) NOT NULL,
weight INT(11) DEFAULT '0' NOT NULL,
time DATETIME NOT NULL,
CONSTRAINT `PRIMARY` PRIMARY KEY (reportId, reporterId),
CONSTRAINT reportReasons_reports_id_fk FOREIGN KEY (reportId) REFERENCES reports (id),
CONSTRAINT reportReasons_accounts_id_fk FOREIGN KEY (reporterId) REFERENCES accounts (id)
);
CREATE INDEX reportReasons_accounts_id_fk ON reportReasons (reporterId);
CREATE TABLE reportResultTypes
(
id TINYINT(4) unsigned PRIMARY KEY NOT NULL,
globalStat TINYINT(1) NOT NULL,
name VARCHAR(16) NOT NULL
);
CREATE TABLE reportResults
(
reportId INT(11) unsigned PRIMARY KEY NOT NULL,
resultId TINYINT(4) NOT NULL,
reason VARCHAR(50),
closedTime DATETIME NOT NULL,
CONSTRAINT reportResults_reports_id_fk FOREIGN KEY (reportId) REFERENCES reports (id)
);
CREATE INDEX reportResults_reportResultTypes_id_fk ON reportResults (resultId);
CREATE TABLE snapshotTypes
(
id TINYINT(3) unsigned PRIMARY KEY NOT NULL,
name VARCHAR(25) NOT NULL
);
CREATE UNIQUE INDEX reportMessageTypes_id_uindex ON snapshotTypes (id);
CREATE TABLE messages
(
id BIGINT(20) unsigned PRIMARY KEY NOT NULL AUTO_INCREMENT,
senderId INT(11) NOT NULL,
server VARCHAR(25) NOT NULL,
time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
message VARCHAR(150) NOT NULL,
snapshotType TINYINT(3) unsigned NOT NULL,
CONSTRAINT reportChatLog_accounts_id_fk FOREIGN KEY (senderId) REFERENCES accounts (id),
CONSTRAINT reportChatMessages_reportMessageTypes_id_fk FOREIGN KEY (snapshotType) REFERENCES snapshotTypes (id)
);
CREATE INDEX reportChatLog_accounts_id_fk ON snapshotMessages (senderId);
CREATE INDEX reportChatMessages_reportMessageTypes_id_fk ON snapshotMessages (snapshotType);
CREATE TABLE snapshotRecipients
(
snapshotId BIGINT(20) unsigned NOT NULL,
recipientId INT(11) NOT NULL,
CONSTRAINT `PRIMARY` PRIMARY KEY (snapshotId, recipientId),
CONSTRAINT reportMessageRecipients_reportMessages_id_fk FOREIGN KEY (snapshotId) REFERENCES snapshotMessages (id),
CONSTRAINT reportMessageRecipients_accounts_id_fk FOREIGN KEY (recipientId) REFERENCES accounts (id)
);
CREATE INDEX reportMessageRecipients_accounts_id_fk ON snapshotRecipients (recipientId);
CREATE TABLE reportSnapshots
(
reportId INT(10) unsigned NOT NULL,
snapshotId BIGINT(20) unsigned NOT NULL,
CONSTRAINT `PRIMARY` PRIMARY KEY (reportId, snapshotId),
CONSTRAINT reportSnapshots_reports_id_fk FOREIGN KEY (reportId) REFERENCES reports (id),
CONSTRAINT reportSnapshots_snapshots_id_fk FOREIGN KEY (snapshotId) REFERENCES snapshotMessages (id)
);
CREATE INDEX reportSnapshots_snapshots_id_fk ON reportSnapshots (snapshotId);
/**
Insert "enums"
*/
INSERT INTO Account.reportResultTypes (id, globalStat, name) VALUES (0, 0, 'ACCEPTED');
INSERT INTO Account.reportResultTypes (id, globalStat, name) VALUES (1, 0, 'DENIED');
INSERT INTO Account.reportResultTypes (id, globalStat, name) VALUES (2, 1, 'ABUSIVE');
INSERT INTO Account.reportResultTypes (id, globalStat, name) VALUES (3, 1, 'EXPIRED');
INSERT INTO Account.reportCategoryTypes (id, name) VALUES (0, 'GLOBAL');
INSERT INTO Account.reportCategoryTypes (id, name) VALUES (1, 'HACKING');
INSERT INTO Account.reportCategoryTypes (id, name) VALUES (2, 'CHAT_ABUSE');
INSERT INTO Account.reportCategoryTypes (id, name) VALUES (3, 'GAMEPLAY');
INSERT INTO Account.snapshotTypes (id, name) VALUES (0, 'CHAT');
INSERT INTO Account.snapshotTypes (id, name) VALUES (1, 'PM');