Modrinth/migrations/20200716160921_init.sql
AppleTheGolden ee69653a83
Switch to Postgres (#39)
* WIP Switch to Postgres

* feat(postgres): more work on porting to postgres, now compiles

* feat(docker-compose): Changed the docker-compose.yml file to use postgres.

* Update docker, documentation, gh actions...

* Remove bson dependency

* Remove bson import

* feat: move mock filehost to trait rather than cargo feature

* feat(postgres): transactions for mod creation, multipart refactor

* fix: Add Cargo.lock so that sqlx functions

* Update sqlx offline build data

* fix: Use SQLX_OFFLINE to force sqlx into offline mode for CI

* Default release channels

* feat(postgres): refactor database models to fit postgres models

* fix: Fix sqlx prepare, fix double allocation in indexing

* Add dockerfile (#40)

Co-authored-by: Charalampos Fanoulis <charalampos.fanoulis@gmail.com>

Co-authored-by: Aeledfyr <aeledfyr@gmail.com>
Co-authored-by: redblueflame <contact@redblueflame.com>
Co-authored-by: Jai A <jai.a@tuta.io>
Co-authored-by: Valentin Ricard <redblueflame1@gmail.Com>
Co-authored-by: Charalampos Fanoulis <charalampos.fanoulis@gmail.com>
2020-07-23 22:46:33 +02:00

103 lines
2.8 KiB
SQL

CREATE TABLE users (
-- TODO
id bigint PRIMARY KEY
);
CREATE TABLE game_versions (
id serial PRIMARY KEY,
version varchar(255) NOT NULL
);
CREATE TABLE loaders (
id serial PRIMARY KEY,
loader varchar(255) NOT NULL
);
CREATE TABLE teams (
id bigint PRIMARY KEY
);
CREATE TABLE release_channel (
id serial PRIMARY KEY,
channel varchar(255)
);
CREATE TABLE mods (
id bigint PRIMARY KEY,
team_id bigint REFERENCES teams NOT NULL,
title varchar(255) NOT NULL,
description varchar(2048) NOT NULL,
body_url varchar(2048) NOT NULL,
published timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL,
downloads integer NOT NULL DEFAULT 0,
icon_url varchar(2048) NULL,
issues_url varchar(2048) NULL,
source_url varchar(2048) NULL,
wiki_url varchar(2048) NULL
);
CREATE TABLE versions (
id bigint PRIMARY KEY,
mod_id bigint REFERENCES mods,
name varchar(255) NOT NULL,
version_number varchar(255) NOT NULL,
changelog_url varchar(255) NULL,
date_published timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL,
downloads integer NOT NULL DEFAULT 0,
release_channel int REFERENCES release_channel ON UPDATE CASCADE NOT NULL
);
CREATE TABLE loaders_versions (
loader_id int REFERENCES loaders ON UPDATE CASCADE NOT NULL,
version_id bigint REFERENCES versions ON UPDATE CASCADE NOT NULL,
PRIMARY KEY (loader_id, version_id)
);
CREATE TABLE game_versions_versions (
game_version_id integer REFERENCES game_versions ON UPDATE CASCADE NOT NULL,
joining_version_id bigint REFERENCES versions ON UPDATE CASCADE NOT NULL,
PRIMARY KEY (game_version_id, joining_version_id)
);
CREATE TABLE files (
id bigint PRIMARY KEY,
version_id bigint REFERENCES versions NOT NULL,
url varchar(2048) NOT NULL
);
CREATE TABLE hashes (
file_id bigint REFERENCES files NOT NULL,
algorithm varchar(255) NOT NULL,
hash bytea NOT NULL,
PRIMARY KEY (file_id, algorithm)
);
CREATE TABLE dependencies (
id serial PRIMARY KEY,
dependent_id bigint REFERENCES versions ON UPDATE CASCADE NOT NULL,
dependency_id bigint REFERENCES versions ON UPDATE CASCADE NOT NULL,
CONSTRAINT valid_dependency CHECK (dependent_id <> dependency_id) -- No dependency on yourself
);
CREATE TABLE team_members (
id bigint PRIMARY KEY,
team_id bigint REFERENCES teams NOT NULL,
user_id bigint REFERENCES users NOT NULL,
member_name varchar(255) NOT NULL,
role varchar(255) NOT NULL
);
CREATE TABLE categories (
id serial PRIMARY KEY,
category varchar(255) UNIQUE
);
CREATE TABLE mods_categories (
joining_mod_id bigint REFERENCES mods ON UPDATE CASCADE NOT NULL,
joining_category_id int REFERENCES categories ON UPDATE CASCADE NOT NULL,
PRIMARY KEY (joining_mod_id, joining_category_id)
);