vgquotes/Tests/VideoGameQuotes.Api.Tests/NHibernate/schema.sql

253 lines
6.3 KiB
MySQL
Raw Normal View History

alter table vote drop foreign key fk_vote_user
;
alter table vote drop foreign key fk_vote_quote
;
alter table game drop foreign key fk_game_user
;
alter table game_system_map drop foreign key FK5B40970FE5573E38
;
alter table game_system_map drop foreign key FK5B40970FD968AB11
;
alter table game_publisher_map drop foreign key FKC48C1B2A6659BAD
;
alter table game_publisher_map drop foreign key FKC48C1B2D968AB11
;
alter table quote_flag drop foreign key fk_flag_user
;
alter table quote_flag drop foreign key fk_flag_quote
;
alter table game_quote drop foreign key fk_quote_user
;
alter table game_quote drop foreign key fk_quote_game
;
alter table quote_category_map drop foreign key FK5892F84657AD8111
;
alter table quote_category_map drop foreign key FK5892F846C2AA09DD
;
drop table if exists vote;
drop table if exists game;
drop table if exists game_system_map;
drop table if exists game_publisher_map;
drop table if exists publisher;
2011-02-19 23:15:36 +00:00
drop table if exists category;
drop table if exists vgquote_user;
drop table if exists quote_flag;
drop table if exists game_quote;
drop table if exists quote_category_map;
drop table if exists system;
create table vote (
vote_id INTEGER NOT NULL AUTO_INCREMENT,
created DATETIME not null,
2011-02-10 21:05:53 +00:00
direction INTEGER not null,
voter_id INTEGER not null,
quote_id INTEGER not null,
primary key (vote_id)
);
create table game (
game_id INTEGER NOT NULL AUTO_INCREMENT,
game_name VARCHAR(255) not null,
website VARCHAR(255),
created DATETIME not null,
icon BLOB,
game_region INTEGER not null,
creator INTEGER not null,
primary key (game_id)
);
create table game_system_map (
game_id INTEGER not null,
system_id INTEGER not null,
primary key (game_id, system_id)
);
create table game_publisher_map (
game_id INTEGER not null,
publisher_id INTEGER not null,
primary key (game_id, publisher_id)
);
create table publisher (
publisher_id INTEGER NOT NULL AUTO_INCREMENT,
publisher_name TEXT not null,
website TEXT,
created DATETIME not null,
primary key (publisher_id)
);
2011-02-19 23:15:36 +00:00
create table category (
category_id INTEGER NOT NULL AUTO_INCREMENT,
category_name VARCHAR(255) not null unique,
created DATETIME not null,
primary key (category_id)
);
create table vgquote_user (
user_id INTEGER NOT NULL AUTO_INCREMENT,
username VARCHAR(50),
ip_address VARCHAR(40),
created DATETIME not null,
user_group INTEGER not null,
user_password VARCHAR(100),
salt VARCHAR(100),
primary key (user_id)
);
create table quote_flag (
quote_flag_id INTEGER NOT NULL AUTO_INCREMENT,
flag_comment TEXT,
created DATETIME not null,
flag_type INTEGER not null,
user_id INTEGER not null,
quote_id INTEGER not null,
primary key (quote_flag_id)
);
create table game_quote (
quote_id INTEGER NOT NULL AUTO_INCREMENT,
quote_text TEXT not null,
created DATETIME not null,
modified DATETIME,
creator INTEGER not null,
game_id INTEGER not null,
score INTEGER not null,
upvotes INTEGER not null,
downvotes INTEGER not null,
flag_count INTEGER not null,
primary key (quote_id)
);
create table quote_category_map (
quote_id INTEGER not null,
category_id INTEGER not null,
primary key (quote_id, category_id)
);
create table system (
system_id INTEGER NOT NULL AUTO_INCREMENT,
system_name VARCHAR(255) not null unique,
system_abbreviation VARCHAR(12) unique,
created DATETIME not null,
release_date DATETIME,
2011-02-27 08:47:16 +00:00
icon BLOB,
primary key (system_id)
);
alter table vote
add index (voter_id),
add constraint fk_vote_user
foreign key (voter_id)
references vgquote_user (user_id);
alter table vote
add index (quote_id),
add constraint fk_vote_quote
foreign key (quote_id)
references game_quote (quote_id);
alter table game
add index (creator),
add constraint fk_game_user
foreign key (creator)
references vgquote_user (user_id);
alter table game_system_map
add index (system_id),
add constraint FK5B40970FE5573E38
foreign key (system_id)
references system (system_id);
alter table game_system_map
add index (game_id),
add constraint FK5B40970FD968AB11
foreign key (game_id)
references game (game_id);
alter table game_publisher_map
add index (publisher_id),
add constraint FKC48C1B2A6659BAD
foreign key (publisher_id)
references publisher (publisher_id);
alter table game_publisher_map
add index (game_id),
add constraint FKC48C1B2D968AB11
foreign key (game_id)
references game (game_id);
alter table quote_flag
add index (user_id),
add constraint fk_flag_user
foreign key (user_id)
references vgquote_user (user_id);
alter table quote_flag
add index (quote_id),
add constraint fk_flag_quote
foreign key (quote_id)
references game_quote (quote_id);
create index idx_score_upvotes on game_quote (score, upvotes);
alter table game_quote
add index (creator),
add constraint fk_quote_user
foreign key (creator)
references vgquote_user (user_id);
alter table game_quote
add index (game_id),
add constraint fk_quote_game
foreign key (game_id)
references game (game_id);
alter table quote_category_map
add index (category_id),
add constraint FK5892F84657AD8111
foreign key (category_id)
references category (category_id);
alter table quote_category_map
add index (quote_id),
add constraint FK5892F846C2AA09DD
foreign key (quote_id)
references game_quote (quote_id);