2024-07-19 08:03:35 +00:00
|
|
|
-- +migrate Up
|
|
|
|
CREATE TYPE Rating AS ENUM (
|
|
|
|
'safe',
|
|
|
|
'questionable',
|
|
|
|
'explicit'
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TYPE TagType AS ENUM (
|
|
|
|
'general',
|
|
|
|
'species',
|
|
|
|
'character',
|
|
|
|
'artist',
|
|
|
|
'lore',
|
|
|
|
'meta',
|
|
|
|
'invalid',
|
|
|
|
'copyright'
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "Post"
|
|
|
|
(
|
2024-08-09 19:37:27 +00:00
|
|
|
id CHAR(25) PRIMARY KEY,
|
2024-07-19 08:03:35 +00:00
|
|
|
rating Rating,
|
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
deleted_at TIMESTAMP NULL NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "Source"
|
|
|
|
(
|
|
|
|
id CHAR(25) PRIMARY KEY,
|
2024-08-09 19:37:27 +00:00
|
|
|
display_name TEXT NULL,
|
|
|
|
icon TEXT NULL,
|
|
|
|
domain TEXT NOT NULL UNIQUE,
|
2024-07-19 08:03:35 +00:00
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
deleted_at TIMESTAMP NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "Tag"
|
|
|
|
(
|
|
|
|
name TEXT PRIMARY KEY,
|
|
|
|
tag_type TagType,
|
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
deleted_at TIMESTAMP NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "User"
|
|
|
|
(
|
2024-08-09 19:37:27 +00:00
|
|
|
id TEXT PRIMARY KEY,
|
2024-07-19 08:03:35 +00:00
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
deleted_at TIMESTAMP NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "PostReference"
|
|
|
|
(
|
|
|
|
post_id TEXT REFERENCES "Post" (id),
|
|
|
|
source_id TEXT REFERENCES "Source" (id),
|
2024-08-09 19:37:27 +00:00
|
|
|
url TEXT NOT NULL,
|
2024-07-19 08:03:35 +00:00
|
|
|
full_file_url TEXT,
|
|
|
|
preview_file_url TEXT,
|
|
|
|
sample_file_url TEXT,
|
|
|
|
source_post_id TEXT,
|
|
|
|
PRIMARY KEY (post_id, source_id, url)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "TagAlias"
|
|
|
|
(
|
|
|
|
name TEXT PRIMARY KEY,
|
|
|
|
tag_id TEXT REFERENCES "Tag" (name),
|
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "TagGroup"
|
|
|
|
(
|
|
|
|
name TEXT PRIMARY KEY,
|
|
|
|
tag_id TEXT REFERENCES "Tag" (name),
|
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "UserSource"
|
|
|
|
(
|
2024-08-09 19:37:27 +00:00
|
|
|
id CHAR(25) PRIMARY KEY,
|
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
deleted_at TIMESTAMP NULL NULL,
|
2024-07-19 08:03:35 +00:00
|
|
|
user_id TEXT REFERENCES "User" (id),
|
|
|
|
source_id TEXT REFERENCES "Source" (id),
|
2024-08-13 12:00:16 +00:00
|
|
|
scrape_time_interval TEXT,
|
2024-07-19 08:03:35 +00:00
|
|
|
account_username TEXT,
|
|
|
|
account_id TEXT,
|
|
|
|
last_scrape_time TIMESTAMP,
|
|
|
|
account_validate BOOL DEFAULT FALSE,
|
|
|
|
account_validation_key CHAR(25),
|
|
|
|
UNIQUE (source_id, account_username, account_id)
|
|
|
|
);
|
|
|
|
|
2024-08-09 19:37:27 +00:00
|
|
|
CREATE TABLE "UserFavorites"
|
|
|
|
(
|
|
|
|
id CHAR(25) PRIMARY KEY,
|
|
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
deleted_at TIMESTAMP NULL NULL,
|
|
|
|
user_id TEXT REFERENCES "User" (id),
|
|
|
|
post_id TEXT REFERENCES "Post" (id),
|
|
|
|
user_source_id CHAR(25) REFERENCES "UserSource" (id)
|
|
|
|
);
|
|
|
|
|
2024-07-19 08:03:35 +00:00
|
|
|
CREATE TABLE "post_tags"
|
|
|
|
(
|
|
|
|
post_id TEXT REFERENCES "Post" (id),
|
|
|
|
tag_name TEXT REFERENCES "Tag" (name),
|
|
|
|
PRIMARY KEY (post_id, tag_name)
|
|
|
|
);
|