diff --git a/pkg/database/migrations/001_create_enum_Rating_2024_06_04.sql b/pkg/database/migrations/001_create_enum_Rating_2024_06_04.sql deleted file mode 100644 index 0af65ae..0000000 --- a/pkg/database/migrations/001_create_enum_Rating_2024_06_04.sql +++ /dev/null @@ -1,9 +0,0 @@ --- +migrate Up -CREATE TYPE Rating AS ENUM ( - 'safe', - 'questionable', - 'explicit' - ); - --- +migrate Down -DROP TYPE Rating; diff --git a/pkg/database/migrations/001_inital_database.sql b/pkg/database/migrations/001_inital_database.sql new file mode 100644 index 0000000..896c850 --- /dev/null +++ b/pkg/database/migrations/001_inital_database.sql @@ -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; \ No newline at end of file diff --git a/pkg/database/migrations/002_create_enum_TagType_2024_06_04.sql b/pkg/database/migrations/002_create_enum_TagType_2024_06_04.sql deleted file mode 100644 index 0a95264..0000000 --- a/pkg/database/migrations/002_create_enum_TagType_2024_06_04.sql +++ /dev/null @@ -1,13 +0,0 @@ --- +migrate Up -CREATE TYPE TagType AS ENUM ( - 'general', - 'species', - 'character', - 'artist', - 'lore', - 'meta', - 'invalid' - ); - --- +migrate Down -DROP TYPE TagType; diff --git a/pkg/database/migrations/003_create_table_Post_2024_06_04.sql b/pkg/database/migrations/003_create_table_Post_2024_06_04.sql deleted file mode 100644 index 11957e1..0000000 --- a/pkg/database/migrations/003_create_table_Post_2024_06_04.sql +++ /dev/null @@ -1,10 +0,0 @@ --- +migrate Up -CREATE TABLE "Post" -( - id VARCHAR(25) PRIMARY KEY, - rating Rating, - created_at TIMESTAMP -); - --- +migrate Down -DROP TYPE Post; diff --git a/pkg/database/migrations/004_create_table_Source_2024_06_04.sql b/pkg/database/migrations/004_create_table_Source_2024_06_04.sql deleted file mode 100644 index c52015f..0000000 --- a/pkg/database/migrations/004_create_table_Source_2024_06_04.sql +++ /dev/null @@ -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"; \ No newline at end of file diff --git a/pkg/database/migrations/005_create_table_Tag_2024_06_04.sql b/pkg/database/migrations/005_create_table_Tag_2024_06_04.sql deleted file mode 100644 index 9b25afe..0000000 --- a/pkg/database/migrations/005_create_table_Tag_2024_06_04.sql +++ /dev/null @@ -1,9 +0,0 @@ --- +migrate Up -CREATE TABLE "Tag" -( - name TEXT PRIMARY KEY, - type TagType -); - --- +migrate Down -DROP TABLE "Tag"; \ No newline at end of file diff --git a/pkg/database/migrations/006_create_table_User_2024_06_04.sql b/pkg/database/migrations/006_create_table_User_2024_06_04.sql deleted file mode 100644 index 56216f8..0000000 --- a/pkg/database/migrations/006_create_table_User_2024_06_04.sql +++ /dev/null @@ -1,9 +0,0 @@ --- +migrate Up -CREATE TABLE "User" -( - id TEXT PRIMARY KEY, - created_at TIMESTAMP -); - --- +migrate Down -DROP TABLE "User"; \ No newline at end of file diff --git a/pkg/database/migrations/007_create_table_PostReference_2024_06_04.sql b/pkg/database/migrations/007_create_table_PostReference_2024_06_04.sql deleted file mode 100644 index f0001e7..0000000 --- a/pkg/database/migrations/007_create_table_PostReference_2024_06_04.sql +++ /dev/null @@ -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"; \ No newline at end of file diff --git a/pkg/database/migrations/008_create_table_TagAlias_2024_06_04.sql b/pkg/database/migrations/008_create_table_TagAlias_2024_06_04.sql deleted file mode 100644 index 6e69fad..0000000 --- a/pkg/database/migrations/008_create_table_TagAlias_2024_06_04.sql +++ /dev/null @@ -1,8 +0,0 @@ --- +migrate Up -CREATE TABLE "TagAlias" -( - name TEXT PRIMARY KEY, - tag_id TEXT REFERENCES "Tag" (name) -); --- +migrate Down -DROP TABLE "TagAlias"; \ No newline at end of file diff --git a/pkg/database/migrations/009_create_table_TagGroup_2024_06_04.sql b/pkg/database/migrations/009_create_table_TagGroup_2024_06_04.sql deleted file mode 100644 index da305cd..0000000 --- a/pkg/database/migrations/009_create_table_TagGroup_2024_06_04.sql +++ /dev/null @@ -1,9 +0,0 @@ --- +migrate Up -CREATE TABLE "TagGroup" -( - name TEXT PRIMARY KEY, - tag_id TEXT REFERENCES "Tag" (name) -); - --- +migrate Down -DROP TABLE "TagGroup"; \ No newline at end of file diff --git a/pkg/database/migrations/010_create_table_UserFavorite_2024_06_04.sql b/pkg/database/migrations/010_create_table_UserFavorite_2024_06_04.sql deleted file mode 100644 index 2058ab1..0000000 --- a/pkg/database/migrations/010_create_table_UserFavorite_2024_06_04.sql +++ /dev/null @@ -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"; \ No newline at end of file diff --git a/pkg/database/migrations/011_create_table_UserSource_2024_06_04.sql b/pkg/database/migrations/011_create_table_UserSource_2024_06_04.sql deleted file mode 100644 index 8ba7201..0000000 --- a/pkg/database/migrations/011_create_table_UserSource_2024_06_04.sql +++ /dev/null @@ -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"; \ No newline at end of file