Final changes to correct primary key and uniqueness rules.
This commit is contained in:
@@ -2,32 +2,34 @@ CREATE DATABASE highscores;
|
|||||||
use highscores;
|
use highscores;
|
||||||
|
|
||||||
CREATE TABLE Guilds(
|
CREATE TABLE Guilds(
|
||||||
GuildId bigint unsigned not null,
|
GuildId bigint unsigned not null unique,
|
||||||
SubmissionChannel bigint unsigned,
|
SubmissionChannel bigint unsigned,
|
||||||
UsernameLength smallint DEFAULT 12,
|
UsernameLength smallint DEFAULT 12,
|
||||||
VerificationChannel bigint unsigned,
|
VerificationChannel bigint unsigned,
|
||||||
PRIMARY KEY (GuildId)
|
PRIMARY KEY (GuildId)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE Groups(
|
CREATE TABLE CategoryGroups(
|
||||||
ChannelId bigint unsigned,
|
ChannelId bigint unsigned,
|
||||||
GroupId int not null AUTO_INCREMENT,
|
GroupId int unsigned not null unique AUTO_INCREMENT,
|
||||||
GroupName varchar(50) not null,
|
GroupName varchar(50) not null,
|
||||||
GuildId int not null,
|
GuildId bigint unsigned not null,
|
||||||
MessageId bigint unsigned,
|
MessageId bigint unsigned,
|
||||||
PadLength smallint not null DEFAULT 26,
|
PadLength smallint not null DEFAULT 26,
|
||||||
Size smallint not null, -- unsure if I like this name. Also unsure belong here or in Category
|
Size smallint not null, -- unsure if I like this name. Also unsure belong here or in Category
|
||||||
|
CONSTRAINT UniqueGuildCategoryGroup UNIQUE (GuildId, GroupName),
|
||||||
FOREIGN KEY (GuildId) REFERENCES Guilds(GuildId),
|
FOREIGN KEY (GuildId) REFERENCES Guilds(GuildId),
|
||||||
PRIMARY KEY (GroupId)
|
PRIMARY KEY (GroupId)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE Categories(
|
CREATE TABLE Categories(
|
||||||
CategoryId int not null AUTO_INCREMENT,
|
CategoryId int unsigned not null unique AUTO_INCREMENT,
|
||||||
CategoryName varchar(30) not null,
|
CategoryName varchar(30) not null,
|
||||||
GroupId int not null,
|
GroupId int unsigned not null,
|
||||||
IsAscending boolean not null DEFAULT true,
|
IsAscending boolean not null DEFAULT true,
|
||||||
IsTimeRecord boolean not null DEFAULT false,
|
IsTimeRecord boolean not null DEFAULT false,
|
||||||
IsValidated boolean not null DEFAULT true,
|
IsValidated boolean not null DEFAULT true,
|
||||||
|
CONSTRAINT UniqueCategoryInGroup UNIQUE (GroupId, CategoryName),
|
||||||
FOREIGN KEY (GroupId) REFERENCES CategoryGroups(GroupId),
|
FOREIGN KEY (GroupId) REFERENCES CategoryGroups(GroupId),
|
||||||
PRIMARY Key (CategoryId)
|
PRIMARY Key (CategoryId)
|
||||||
);
|
);
|
||||||
@@ -35,7 +37,7 @@ CREATE TABLE Categories(
|
|||||||
CREATE TABLE Scores(
|
CREATE TABLE Scores(
|
||||||
UserName varchar(30) not null,
|
UserName varchar(30) not null,
|
||||||
Score float not null, -- Maybe should have time and int scores?? timestamp type?
|
Score float not null, -- Maybe should have time and int scores?? timestamp type?
|
||||||
CategoryId int not null,
|
CategoryId int unsigned not null,
|
||||||
FOREIGN KEY (CategoryId) REFERENCES Categories(CategoryId),
|
FOREIGN KEY (CategoryId) REFERENCES Categories(CategoryId),
|
||||||
CONSTRAINT PKScore PRIMARY KEY (CategoryId, UserName) -- i think this means there isnt a column for this key but the key is made up of categoryid and username
|
PRIMARY KEY (CategoryId, UserName)
|
||||||
);
|
);
|
||||||
Reference in New Issue
Block a user