feat(db): finalizing migration statements
Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
parent
b2b354c60f
commit
751f387b86
9
db/migrations/001_create_enum_Rating_2024_06_04.sql
Normal file
9
db/migrations/001_create_enum_Rating_2024_06_04.sql
Normal file
@ -0,0 +1,9 @@
|
||||
-- +migrate Up
|
||||
CREATE TYPE Rating AS ENUM (
|
||||
'safe',
|
||||
'questionable',
|
||||
'explicit'
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TYPE Rating;
|
13
db/migrations/002_create_enum_TagType_2024_06_04.sql
Normal file
13
db/migrations/002_create_enum_TagType_2024_06_04.sql
Normal file
@ -0,0 +1,13 @@
|
||||
-- +migrate Up
|
||||
CREATE TYPE TagType AS ENUM (
|
||||
'general',
|
||||
'species',
|
||||
'character',
|
||||
'artist',
|
||||
'lore',
|
||||
'meta',
|
||||
'invalid'
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TYPE TagType;
|
10
db/migrations/003_create_table_Post_2024_06_04.sql
Normal file
10
db/migrations/003_create_table_Post_2024_06_04.sql
Normal file
@ -0,0 +1,10 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE "Post"
|
||||
(
|
||||
id VARCHAR(25) PRIMARY KEY,
|
||||
rating Rating,
|
||||
created_at TIMESTAMP
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TYPE Post;
|
11
db/migrations/004_create_table_Source_2024_06_04.sql
Normal file
11
db/migrations/004_create_table_Source_2024_06_04.sql
Normal file
@ -0,0 +1,11 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE "Source"
|
||||
(
|
||||
id VARCHAR(25) PRIMARY KEY,
|
||||
display_name TEXT,
|
||||
domain TEXT NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE "Source";
|
9
db/migrations/005_create_table_Tag_2024_06_04.sql
Normal file
9
db/migrations/005_create_table_Tag_2024_06_04.sql
Normal file
@ -0,0 +1,9 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE "Tag"
|
||||
(
|
||||
name TEXT PRIMARY KEY,
|
||||
type TagType
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE "Tag";
|
9
db/migrations/006_create_table_User_2024_06_04.sql
Normal file
9
db/migrations/006_create_table_User_2024_06_04.sql
Normal file
@ -0,0 +1,9 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE "User"
|
||||
(
|
||||
id TEXT PRIMARY KEY,
|
||||
created_at TIMESTAMP
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE "User";
|
12
db/migrations/007_create_table_PostReference_2024_06_04.sql
Normal file
12
db/migrations/007_create_table_PostReference_2024_06_04.sql
Normal file
@ -0,0 +1,12 @@
|
||||
-- +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";
|
8
db/migrations/008_create_table_TagAlias_2024_06_04.sql
Normal file
8
db/migrations/008_create_table_TagAlias_2024_06_04.sql
Normal file
@ -0,0 +1,8 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE "TagAlias"
|
||||
(
|
||||
name TEXT PRIMARY KEY,
|
||||
tag_id TEXT REFERENCES "Tag" (name)
|
||||
);
|
||||
-- +migrate Down
|
||||
DROP TABLE "TagAlias";
|
9
db/migrations/009_create_table_TagGroup_2024_06_04.sql
Normal file
9
db/migrations/009_create_table_TagGroup_2024_06_04.sql
Normal file
@ -0,0 +1,9 @@
|
||||
-- +migrate Up
|
||||
CREATE TABLE "TagGroup"
|
||||
(
|
||||
name TEXT PRIMARY KEY,
|
||||
tag_id TEXT REFERENCES "Tag" (name)
|
||||
);
|
||||
|
||||
-- +migrate Down
|
||||
DROP TABLE "TagGroup";
|
11
db/migrations/010_create_table_UserFavorite_2024_06_04.sql
Normal file
11
db/migrations/010_create_table_UserFavorite_2024_06_04.sql
Normal file
@ -0,0 +1,11 @@
|
||||
-- +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";
|
13
db/migrations/011_create_table_UserSource_2024_06_04.sql
Normal file
13
db/migrations/011_create_table_UserSource_2024_06_04.sql
Normal file
@ -0,0 +1,13 @@
|
||||
-- +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";
|
@ -25,16 +25,15 @@ func NewPostgresqlConnection() OtterSpace {
|
||||
}
|
||||
|
||||
func (p postgresqlConnection) Connect(ctx context.Context, endpoint string, username string, password string, database string, port int, ssl string, timezone string) error {
|
||||
|
||||
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s", endpoint, username, password, database, port, ssl, timezone)
|
||||
db, err := gorm.Open(gormPostgres.Open(dsn), &gorm.Config{})
|
||||
p.db = db
|
||||
var err error
|
||||
|
||||
err = p.migrateDatabase(dsn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = p.migrateDatabase(dsn)
|
||||
|
||||
p.db, err = gorm.Open(gormPostgres.Open(dsn), &gorm.Config{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user