feat(db): reduce to one migration file
Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
parent
b65e942f24
commit
ebd25580fe
@ -1,9 +0,0 @@
|
||||
-- +migrate Up
|
||||
CREATE TYPE Rating AS ENUM (
|
||||
'safe',
|
||||
'questionable',
|
||||
'explicit'
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TYPE Rating;
|
93
pkg/database/migrations/001_inital_database.sql
Normal file
93
pkg/database/migrations/001_inital_database.sql
Normal file
@ -0,0 +1,93 @@
|
||||
-- +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) PRIMARY KEY,
|
||||
rating Rating,
|
||||
created_at TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE "Source"
|
||||
(
|
||||
id VARCHAR(25) PRIMARY KEY,
|
||||
display_name TEXT,
|
||||
domain TEXT NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE "Tag"
|
||||
(
|
||||
name TEXT PRIMARY KEY,
|
||||
type TagType
|
||||
);
|
||||
|
||||
CREATE TABLE "User"
|
||||
(
|
||||
id TEXT PRIMARY KEY,
|
||||
created_at 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,
|
||||
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;
|
@ -1,13 +0,0 @@
|
||||
-- +migrate Up
|
||||
CREATE TYPE TagType AS ENUM (
|
||||
'general',
|
||||
'species',
|
||||
'character',
|
||||
'artist',
|
||||
'lore',
|
||||
'meta',
|
||||
'invalid'
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TYPE TagType;
|
@ -1,10 +0,0 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE "Post"
|
||||
(
|
||||
id VARCHAR(25) PRIMARY KEY,
|
||||
rating Rating,
|
||||
created_at TIMESTAMP
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TYPE Post;
|
@ -1,11 +0,0 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE "Source"
|
||||
(
|
||||
id VARCHAR(25) PRIMARY KEY,
|
||||
display_name TEXT,
|
||||
domain TEXT NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE "Source";
|
@ -1,9 +0,0 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE "Tag"
|
||||
(
|
||||
name TEXT PRIMARY KEY,
|
||||
type TagType
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE "Tag";
|
@ -1,9 +0,0 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE "User"
|
||||
(
|
||||
id TEXT PRIMARY KEY,
|
||||
created_at TIMESTAMP
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE "User";
|
@ -1,12 +0,0 @@
|
||||
-- +migrate Up
|
||||
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)
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE "PostReference";
|
@ -1,8 +0,0 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE "TagAlias"
|
||||
(
|
||||
name TEXT PRIMARY KEY,
|
||||
tag_id TEXT REFERENCES "Tag" (name)
|
||||
);
|
||||
-- +migrate Down
|
||||
DROP TABLE "TagAlias";
|
@ -1,9 +0,0 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE "TagGroup"
|
||||
(
|
||||
name TEXT PRIMARY KEY,
|
||||
tag_id TEXT REFERENCES "Tag" (name)
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE "TagGroup";
|
@ -1,11 +0,0 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE "UserFavorites"
|
||||
(
|
||||
user_id TEXT REFERENCES "User" (id),
|
||||
post_id TEXT REFERENCES "Post" (id),
|
||||
created_at TIMESTAMP,
|
||||
PRIMARY KEY (user_id, post_id)
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE "UserFavorites";
|
@ -1,13 +0,0 @@
|
||||
-- +migrate Up
|
||||
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 TABLE "UserSource";
|
Reference in New Issue
Block a user