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',
|
2024-06-21 13:18:40 +00:00
|
|
|
'invalid',
|
|
|
|
'copyright'
|
2024-06-04 11:35:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "Post"
|
|
|
|
(
|
2024-06-20 20:45:03 +00:00
|
|
|
id CHAR(25) 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-28 08:43:55 +00:00
|
|
|
id CHAR(25) 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-20 20:45:03 +00:00
|
|
|
id TEXT 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),
|
2024-06-21 13:52:59 +00:00
|
|
|
url TEXT NOT NULL,
|
2024-06-14 10:24:14 +00:00
|
|
|
full_file_url TEXT,
|
|
|
|
preview_file_url TEXT,
|
|
|
|
sample_file_url TEXT,
|
|
|
|
source_post_id TEXT,
|
2024-06-21 13:25:22 +00:00
|
|
|
PRIMARY KEY (post_id, source_id, url)
|
2024-06-04 11:35:14 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
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-20 20:45:03 +00:00
|
|
|
user_id TEXT REFERENCES "User" (id),
|
|
|
|
post_id TEXT 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"
|
|
|
|
(
|
2024-06-28 08:43:55 +00:00
|
|
|
user_id TEXT REFERENCES "User" (id),
|
|
|
|
source_id TEXT REFERENCES "Source" (id),
|
|
|
|
scrape_time_interval INT,
|
|
|
|
account_username TEXT,
|
|
|
|
account_id TEXT,
|
|
|
|
last_scrape_time TIMESTAMP,
|
|
|
|
account_validate BOOL DEFAULT FALSE,
|
|
|
|
account_validation_key CHAR(25),
|
2024-06-04 21:14:02 +00:00
|
|
|
PRIMARY KEY (user_id, source_id),
|
2024-06-26 14:12:10 +00:00
|
|
|
UNIQUE (source_id, account_username, account_id)
|
2024-06-04 21:14:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "post_tags"
|
|
|
|
(
|
|
|
|
post_id TEXT REFERENCES "Post" (id),
|
|
|
|
tag_name TEXT REFERENCES "Tag" (name),
|
|
|
|
PRIMARY KEY (post_id, tag_name)
|
2024-06-28 08:43:55 +00:00
|
|
|
);
|