diff --git a/sql/migrations/000001_init.up.sql b/sql/migrations/000001_init.up.sql index 669143a..97f881d 100644 --- a/sql/migrations/000001_init.up.sql +++ b/sql/migrations/000001_init.up.sql @@ -24,6 +24,22 @@ CREATE TABLE images ( image_path text UNIQUE NOT NULL ); +CREATE TABLE reviews ( + id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + data text NOT NULL, + rating int CHECK (rating >= 0 AND rating <= 10), + illust_id bigint REFERENCES images (id), + user_id bigint REFERENCES users (id), + title_id bigint REFERENCES titles (id), + created_at timestamptz DEFAULT NOW() +); + +CREATE TABLE review_images ( + PRIMARY KEY (review_id, image_id), + review_id bigint NOT NULL REFERENCES reviews(id) ON DELETE CASCADE, + image_id bigint NOT NULL REFERENCES images(id) ON DELETE CASCADE +); + CREATE TABLE users ( id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, avatar_id bigint REFERENCES images (id), diff --git a/sql/models.go b/sql/models.go index 6583b71..a36c6fa 100644 --- a/sql/models.go +++ b/sql/models.go @@ -208,6 +208,21 @@ type Provider struct { Credentials []byte `json:"credentials"` } +type Review struct { + ID int64 `json:"id"` + Data string `json:"data"` + Rating *int32 `json:"rating"` + IllustID *int64 `json:"illust_id"` + UserID *int64 `json:"user_id"` + TitleID *int64 `json:"title_id"` + CreatedAt pgtype.Timestamptz `json:"created_at"` +} + +type ReviewImage struct { + ReviewID int64 `json:"review_id"` + ImageID int64 `json:"image_id"` +} + type Signal struct { ID int64 `json:"id"` TitleID *int64 `json:"title_id"`