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-20 20:45:03 +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-22 20:06:36 +00:00
|
|
|
user_id TEXT REFERENCES "User" (id),
|
|
|
|
source_id TEXT REFERENCES "Source" (id),
|
2024-06-22 23:18:23 +00:00
|
|
|
scrape_time_interval TEXT,
|
|
|
|
account_username TEXT,
|
2024-06-22 20:06:36 +00:00
|
|
|
account_id TEXT,
|
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-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;
|