2024-06-04 11:35:14 +00:00
|
|
|
-- +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"
|
|
|
|
(
|
2024-06-04 21:14:02 +00:00
|
|
|
id CHAR(25) UNIQUE PRIMARY KEY,
|
2024-06-04 11:35:14 +00:00
|
|
|
rating Rating,
|
2024-06-04 21:14:02 +00:00
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
deleted_at TIMESTAMP NULL NULL
|
2024-06-04 11:35:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "Source"
|
|
|
|
(
|
2024-06-04 21:14:02 +00:00
|
|
|
id CHAR(25) UNIQUE PRIMARY KEY,
|
2024-06-14 10:24:14 +00:00
|
|
|
display_name TEXT NULL,
|
|
|
|
icon TEXT NULL,
|
|
|
|
domain TEXT NOT NULL UNIQUE,
|
2024-06-04 21:14:02 +00:00
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
deleted_at TIMESTAMP NULL
|
2024-06-04 11:35:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "Tag"
|
|
|
|
(
|
2024-06-04 21:14:02 +00:00
|
|
|
name TEXT PRIMARY KEY,
|
|
|
|
tag_type TagType,
|
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
deleted_at TIMESTAMP NULL
|
2024-06-04 11:35:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "User"
|
|
|
|
(
|
2024-06-04 12:00:00 +00:00
|
|
|
id TEXT UNIQUE PRIMARY KEY,
|
2024-06-04 21:14:02 +00:00
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
deleted_at TIMESTAMP NULL
|
2024-06-04 11:35:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "PostReference"
|
|
|
|
(
|
2024-06-14 10:24:14 +00:00
|
|
|
post_id TEXT REFERENCES "Post" (id),
|
|
|
|
source_id TEXT REFERENCES "Source" (id),
|
|
|
|
url TEXT NOT NULL UNIQUE,
|
|
|
|
full_file_url TEXT,
|
|
|
|
preview_file_url TEXT,
|
|
|
|
sample_file_url TEXT,
|
|
|
|
source_post_id TEXT,
|
2024-06-04 11:35:14 +00:00
|
|
|
PRIMARY KEY (post_id, source_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "TagAlias"
|
|
|
|
(
|
2024-06-04 21:14:02 +00:00
|
|
|
name TEXT PRIMARY KEY,
|
|
|
|
tag_id TEXT REFERENCES "Tag" (name),
|
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
2024-06-04 11:35:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "TagGroup"
|
|
|
|
(
|
2024-06-04 21:14:02 +00:00
|
|
|
name TEXT PRIMARY KEY,
|
|
|
|
tag_id TEXT REFERENCES "Tag" (name),
|
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
2024-06-04 11:35:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "UserFavorites"
|
|
|
|
(
|
2024-06-14 10:24:14 +00:00
|
|
|
user_id TEXT UNIQUE REFERENCES "User" (id),
|
|
|
|
post_id TEXT UNIQUE REFERENCES "Post" (id),
|
2024-06-04 12:00:00 +00:00
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
2024-06-04 11:35:14 +00:00
|
|
|
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,
|
2024-06-04 21:14:02 +00:00
|
|
|
PRIMARY KEY (user_id, source_id),
|
|
|
|
UNIQUE (account_username, account_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "post_tags"
|
|
|
|
(
|
|
|
|
post_id TEXT REFERENCES "Post" (id),
|
|
|
|
tag_name TEXT REFERENCES "Tag" (name),
|
|
|
|
PRIMARY KEY (post_id, tag_name)
|
2024-06-04 11:35:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
-- +migrate Down
|
|
|
|
DROP TYPE Rating;
|
|
|
|
DROP TYPE TagType;
|
2024-06-04 21:14:02 +00:00
|
|
|
DROP TABLE Post;
|
|
|
|
DROP TABLE Source;
|
|
|
|
DROP TABLE Tag;
|
|
|
|
DROP TABLE User;
|
|
|
|
DROP TABLE PostReference;
|
|
|
|
DROP TABLE TagAlias;
|
|
|
|
DROP TABLE TagGroup;
|
|
|
|
DROP TABLE UserFavorites;
|
|
|
|
DROP TABLE UserSource;
|