-- Automatically generated by JPA

-- Hibernate sequence
create sequence HIBERNATE_SEQUENCE start with 1 increment by 1;

-- Detected Games
create table DETECTED_GAME
(
    slug            varchar(255) not null,
    category        varchar(255),
    confirmed_match boolean default false,
    cover_id        varchar(255) not null,
    critics_rating  integer,
    disk_size       bigint       not null,
    lan_support     boolean      not null,
    max_players     integer      not null,
    offline_coop    boolean      not null,
    online_coop     boolean      not null,
    path            varchar(255) not null,
    release_date    timestamp,
    summary         CLOB,
    title           varchar(255) not null,
    total_rating    integer,
    user_rating     integer,
    primary key (slug)
);

-- Companies
create table COMPANY
(
    slug    varchar(255) not null,
    logo_id varchar(255),
    name    varchar(255) not null,
    primary key (slug)
);

-- Genres
create table GENRE
(
    slug varchar(255) not null,
    name varchar(255),
    primary key (slug)
);

-- Themes
create table THEME
(
    slug varchar(255) not null,
    name varchar(255),
    primary key (slug)
);

-- Keywords
create table KEYWORD
(
    slug varchar(255) not null,
    name varchar(255),
    primary key (slug)
);

-- Player Perspectives
create table PLAYER_PERSPECTIVE
(
    slug varchar(255) not null,
    name varchar(255),
    primary key (slug)
);

-- Unmappable files
create table UNMAPPABLE_FILE
(
    id   bigint not null,
    path varchar(255),
    primary key (id)
);

-- Game <-> Companies
create table DETECTED_GAME_COMPANIES
(
    detected_game_slug varchar(255) not null,
    companies_slug     varchar(255) not null
);
alter table DETECTED_GAME_COMPANIES
    add constraint companies_company_slug foreign key (companies_slug) references company;
alter table DETECTED_GAME_COMPANIES
    add constraint companies_detected_game_slug foreign key (detected_game_slug) references detected_game;

-- Game <-> Genres
create table DETECTED_GAME_GENRES
(
    detected_game_slug varchar(255) not null,
    genres_slug        varchar(255) not null
);
alter table DETECTED_GAME_GENRES
    add constraint genres_genre_slug foreign key (genres_slug) references genre;
alter table DETECTED_GAME_GENRES
    add constraint genres_detected_game_slug foreign key (detected_game_slug) references detected_game;

-- Game <-> Themes
create table DETECTED_GAME_THEMES
(
    detected_game_slug varchar(255) not null,
    themes_slug        varchar(255) not null
);
alter table DETECTED_GAME_THEMES
    add constraint themes_theme_slug foreign key (themes_slug) references theme;
alter table DETECTED_GAME_THEMES
    add constraint themes_detected_game_slug foreign key (detected_game_slug) references detected_game;

-- Game <-> Keywords
create table DETECTED_GAME_KEYWORDS
(
    detected_game_slug varchar(255) not null,
    keywords_slug      varchar(255) not null
);
alter table DETECTED_GAME_KEYWORDS
    add constraint keywords_keyword_slug foreign key (keywords_slug) references keyword;
alter table DETECTED_GAME_KEYWORDS
    add constraint keywords_detected_game_slug foreign key (detected_game_slug) references detected_game;

-- Game <-> Player Perspectives
create table DETECTED_GAME_PLAYER_PERSPECTIVES
(
    detected_game_slug       varchar(255) not null,
    player_perspectives_slug varchar(255) not null
);
alter table DETECTED_GAME_PLAYER_PERSPECTIVES
    add constraint player_perspectives_player_perspective_slug foreign key (player_perspectives_slug) references player_perspective;
alter table DETECTED_GAME_PLAYER_PERSPECTIVES
    add constraint player_perspectives_detected_game_slug foreign key (detected_game_slug) references detected_game;

-- Game <-> Videos
create table DETECTED_GAME_VIDEO_IDS
(
    detected_game_slug varchar(255) not null,
    video_ids          varchar(255)
);
alter table DETECTED_GAME_VIDEO_IDS
    add constraint video_ids_detected_game_slug foreign key (detected_game_slug) references detected_game;

-- Game <-> Screenshots
create table DETECTED_GAME_SCREENSHOT_IDS
(
    detected_game_slug varchar(255) not null,
    screenshot_ids     varchar(255)
);
alter table DETECTED_GAME_SCREENSHOT_IDS
    add constraint screenshot_ids_detected_game_slug foreign key (detected_game_slug) references detected_game;
