This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
otter-space-sdk/pkg/database/migrations/001_inital_database.sql
SoXX 5aa1542074 feat(db): corrected tables
Signed-off-by: SoXX <soxx@fenpa.ws>
2024-06-04 14:00:00 +02:00

93 lines
1.8 KiB
SQL

-- +migrate Up
CREATE TYPE Rating AS ENUM (
'safe',
'questionable',
'explicit'
);
CREATE TYPE TagType AS ENUM (
'general',
'species',
'character',
'artist',
'lore',
'meta',
'invalid'
);
CREATE TABLE "Post"
(
id VARCHAR(25) UNIQUE PRIMARY KEY,
rating Rating,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE "Source"
(
id VARCHAR(25) UNIQUE PRIMARY KEY,
display_name TEXT,
domain TEXT NOT NULL UNIQUE
);
CREATE TABLE "Tag"
(
name TEXT PRIMARY KEY,
type TagType
);
CREATE TABLE "User"
(
id TEXT UNIQUE PRIMARY KEY,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE "PostReference"
(
post_id TEXT REFERENCES "Post" (id),
source_id TEXT REFERENCES "Source" (id),
url TEXT NOT NULL UNIQUE,
source_post_id TEXT,
PRIMARY KEY (post_id, source_id)
);
CREATE TABLE "TagAlias"
(
name TEXT PRIMARY KEY,
tag_id TEXT REFERENCES "Tag" (name)
);
CREATE TABLE "TagGroup"
(
name TEXT PRIMARY KEY,
tag_id TEXT REFERENCES "Tag" (name)
);
CREATE TABLE "UserFavorites"
(
user_id TEXT REFERENCES "User" (id),
post_id TEXT REFERENCES "Post" (id),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (user_id, post_id)
);
CREATE TABLE "UserSource"
(
user_id TEXT REFERENCES "User" (id),
source_id TEXT REFERENCES "Source" (id),
account_username TEXT,
account_id TEXT,
PRIMARY KEY (user_id, source_id)
);
-- +migrate Down
DROP TYPE Rating;
DROP TYPE TagType;
DROP TYPE Post;
DROP TYPE Source;
DROP TYPE Tag;
DROP TYPE User;
DROP TYPE PostReference;
DROP TYPE TagAlias;
DROP TYPE TagGroup;
DROP TYPE UserFavorites;
DROP TYPE UserSource;