vgquotes/Tests/VideoGameQuotes.Api.Tests/NHibernate/schema.sql
2011-02-10 04:39:59 +00:00

190 lines
4.6 KiB
SQL

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 drop foreign key fk_game_publisher
;
alter table game_system_map drop foreign key FK5B40970FD86811D9
;
alter table game_system_map drop foreign key FK5B40970FD968AB11
;
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
;
drop table if exists vote;
drop table if exists game;
drop table if exists game_system_map;
drop table if exists publisher;
drop table if exists system;
drop table if exists vgquote_user;
drop table if exists quote_flag;
drop table if exists game_quote;
create table vote (
vote_id INTEGER NOT NULL AUTO_INCREMENT,
created DATETIME not null,
point_value 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 TEXT not null,
created DATETIME not null,
screenshot BLOB,
game_region INTEGER not null,
creator INTEGER not null,
publisher_id INTEGER,
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 publisher (
publisher_id INTEGER NOT NULL AUTO_INCREMENT,
publisher_name TEXT not null,
website TEXT,
created DATETIME not null,
primary key (publisher_id)
);
create table system (
system_id INTEGER NOT NULL AUTO_INCREMENT,
system_name TEXT not null,
system_abbreviation VARCHAR(12),
created DATETIME not null,
release_date DATETIME,
primary key (system_id)
);
create table vgquote_user (
user_id INTEGER NOT NULL AUTO_INCREMENT,
username VARCHAR(50) not null unique,
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,
primary key (quote_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
add index (publisher_id),
add constraint fk_game_publisher
foreign key (publisher_id)
references publisher (publisher_id);
alter table game_system_map
add index (system_id),
add constraint FK5B40970FD86811D9
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 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);
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);