238 lines
5.6 KiB
MySQL
238 lines
5.6 KiB
MySQL
|
--Create roles table
|
||
|
CREATE TABLE Roles
|
||
|
(
|
||
|
RoleID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
RoleName VARCHAR(255) Not Null
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create users table
|
||
|
CREATE TABLE Users
|
||
|
(
|
||
|
UserID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
UserName VARCHAR(25) NOT NULL,
|
||
|
LikeCount int NOT NULL,
|
||
|
UserDescription TEXT
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
|
||
|
--Create profilepicture table
|
||
|
CREATE TABLE ProfilePicture
|
||
|
(
|
||
|
PictureID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
UserID int NOT NULL FOREIGN KEY REFERENCES Users(UserID),
|
||
|
PictureFileName VARCHAR(255) NOT NULL,
|
||
|
Height int NOT NULL,
|
||
|
Width int NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create airedtypes table
|
||
|
CREATE TABLE AiredTypes
|
||
|
(
|
||
|
AiredTypeID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
AiredType VARCHAR(255) NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create videofiletypes table
|
||
|
CREATE TABLE VideoFileTypes
|
||
|
(
|
||
|
FileTypeID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
TypeName VARCHAR(255) NOT NULL,
|
||
|
TypeExtension VARCHAR(10) NOT NULL,
|
||
|
Codec VARCHAR(255) NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create table videoencode
|
||
|
CREATE TABLE VideoEncode
|
||
|
(
|
||
|
EncodeID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
EncodeName VARCHAR(255) NOT NULL,
|
||
|
Width int NOT NULL,
|
||
|
Height int NOT NULL,
|
||
|
Framerate int NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create category table
|
||
|
CREATE TABLE Category
|
||
|
(
|
||
|
CategoryID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
CategoryName VARCHAR(255) NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create production table
|
||
|
CREATE TABLE Production
|
||
|
(
|
||
|
ProductionID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
ProductionName VARCHAR(255) NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
|
||
|
--Create audiogenre table
|
||
|
CREATE TABLE AudioGenre
|
||
|
(
|
||
|
GenreID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
GenreName VARCHAR(255) NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create releasetype table
|
||
|
CREATE TABLE ReleaseType
|
||
|
(
|
||
|
ReleaseTypeID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
TypeName VARCHAR(255) NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create audiofiletypes table
|
||
|
CREATE TABLE AudioFileTypes
|
||
|
(
|
||
|
FileTypeID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
TypeName VARCHAR(255) NOT NULL,
|
||
|
TypeExtention VARCHAR(10) NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create imagefiletypes table
|
||
|
CREATE TABLE ImageFileTypes
|
||
|
(
|
||
|
FileTypeID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
FileTypeName VARCHAR(255) NOT NULL,
|
||
|
FileTypeExtension VARCHAR(10) NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create roleallocation table
|
||
|
CREATE TABLE RoleAllocation
|
||
|
(
|
||
|
RoleAllocationID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
UserID int NOT NULL FOREIGN KEY REFERENCES Users(UserID),
|
||
|
RoleID int NOT NULL FOREIGN KEY REFERENCES Roles(RoleID)
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create mediaentry table (INTERESTING TABLE)
|
||
|
CREATE TABLE MediaEntry
|
||
|
(
|
||
|
EntryID int NOT NULL IDENTITY PRIMARY KEY,
|
||
|
CategoryID int NOT NULL FOREIGN KEY REFERENCES Category(CategoryID),
|
||
|
UserID int NOT NULL FOREIGN KEY REFERENCES Users(UserID),
|
||
|
ProductionID int FOREIGN KEY REFERENCES Production(ProductionID), --Entry may not have a production, can be null
|
||
|
Title VARCHAR(255) NOT NULL,
|
||
|
EntryDescription TEXT,
|
||
|
UploadDate DATETIME NOT NULL,
|
||
|
Premium BIT NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create contentpage table
|
||
|
CREATE TABLE ContentPage
|
||
|
(
|
||
|
PageID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
EntryID int NOT NULL FOREIGN KEY REFERENCES MediaEntry(EntryID),
|
||
|
Likes int NOT NULL,
|
||
|
Dislikes int NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create comment table
|
||
|
CREATE TABLE Comment
|
||
|
(
|
||
|
CommentID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
UserID int NOT NULL FOREIGN KEY REFERENCES Users(UserID),
|
||
|
PageID int NOT NULL FOREIGN KEY REFERENCES ContentPage(PageID),
|
||
|
Content TEXT NOT NULL,
|
||
|
ParentComment int
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create thumbnail table
|
||
|
CREATE TABLE Thumbnail
|
||
|
(
|
||
|
ThumbnailID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
EntryID int NOT NULL FOREIGN KEY REFERENCES MediaEntry(EntryID),
|
||
|
ThumbnailFileName VARCHAR(255) NOT NULL,
|
||
|
Height int NOT NULL,
|
||
|
Width int NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create imageentry table
|
||
|
CREATE TABLE ImageEntry
|
||
|
(
|
||
|
ImageID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
EntryID int NOT NULL FOREIGN KEY REFERENCES MediaEntry(EntryID),
|
||
|
FileTypeID int NOT NULL FOREIGN KEY REFERENCES ImageFileTypes(FileTypeID),
|
||
|
ImageFileName VARCHAR(255) NOT NULL,
|
||
|
Height int NOT NULL,
|
||
|
Width int NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create audioentry table
|
||
|
CREATE TABLE AudioEntry
|
||
|
(
|
||
|
AudioID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
EntryID int NOT NULL FOREIGN KEY REFERENCES MediaEntry(EntryID),
|
||
|
FileTypeID int NOT NULL FOREIGN KEY REFERENCES AudioFileTypes(FileTypeID),
|
||
|
ReleaseTypeID int NOT NULL FOREIGN KEY REFERENCES ReleaseType(ReleaseTypeID),
|
||
|
AudioLength int NOT NULL,
|
||
|
BitRate int NOT NULL,
|
||
|
AudioFileName VARCHAR(255) NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create audiopreview table
|
||
|
CREATE TABLE AudioPreview
|
||
|
(
|
||
|
PreviewID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
AudioID int NOT NULL FOREIGN KEY REFERENCES AudioEntry(AudioID),
|
||
|
FileTypeID int NOT NULL FOREIGN KEY REFERENCES AudioFileTypes(FileTypeID),
|
||
|
AudioLength int NOT NULL,
|
||
|
BitRate int NOT NULL,
|
||
|
AudioFileName VARCHAR(255) NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create videoentry table
|
||
|
CREATE TABLE VideoEntry
|
||
|
(
|
||
|
VideoID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
EntryID int NOT NULL FOREIGN KEY REFERENCES MediaEntry(EntryID),
|
||
|
EncodeID int NOT NULL FOREIGN KEY REFERENCES VideoEncode(EncodeID),
|
||
|
FileTypeID int NOT NULL FOREIGN KEY REFERENCES VideoFileTypes(FileTypeID),
|
||
|
AiredTypeID int FOREIGN KEY REFERENCES AiredTypes(AiredTypeID),
|
||
|
VideoFileName VARCHAR(255) NOT NULL,
|
||
|
AiredOn DATETIME,
|
||
|
Length int NOT NULL
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create videopreview table
|
||
|
CREATE TABLE VideoPreview
|
||
|
(
|
||
|
PreviewID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
VideoID int NOT NULL FOREIGN KEY REFERENCES MediaEntry(EntryID),
|
||
|
EncodeID int NOT NULL FOREIGN KEY REFERENCES VideoEncode(EncodeID),
|
||
|
FileTypeID int NOT NULL FOREIGN KEY REFERENCES VideoFileTypes(FileTypeID),
|
||
|
VideoFileName VARCHAR(255) NOT NULL,
|
||
|
AiredOn DATETIME,
|
||
|
Length int NOT NULL,
|
||
|
);
|
||
|
GO
|
||
|
|
||
|
--Create audiogenreentry table (solve many to many relationship)
|
||
|
CREATE TABLE AudioGenreEntry
|
||
|
(
|
||
|
GenreEntryID int IDENTITY NOT NULL PRIMARY KEY,
|
||
|
AudioID int NOT NULL FOREIGN KEY REFERENCES AudioEntry(AudioID),
|
||
|
GenreID int NOT NULL FOREIGN KEY REFERENCES AudioGenre(GenreID)
|
||
|
);
|
||
|
GO
|