From 62dd5899e014cdea5d70d553fa7c4113ba77a9c8 Mon Sep 17 00:00:00 2001 From: yanghao05 Date: Fri, 18 Apr 2025 16:59:00 +0800 Subject: [PATCH] feat: update model --- .../database/migrations/20250322100215_create_posts.sql | 2 +- backend/database/schemas/public/model/posts.go | 1 + backend/database/schemas/public/table/posts.go | 7 +++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/database/migrations/20250322100215_create_posts.sql b/backend/database/migrations/20250322100215_create_posts.sql index 4bd6b0f..bce67df 100644 --- a/backend/database/migrations/20250322100215_create_posts.sql +++ b/backend/database/migrations/20250322100215_create_posts.sql @@ -7,7 +7,7 @@ CREATE TABLE posts( deleted_at timestamp, status int2 NOT NULL DEFAULT 0, title varchar(128) NOT NULL, - head_image int8 NOT NULL DEFAULT 0, + head_images jsonb DEFAULT '[]' ::jsonb NOT NULL, description varchar(256) NOT NULL, content text NOT NULL, price int8 NOT NULL DEFAULT 0, diff --git a/backend/database/schemas/public/model/posts.go b/backend/database/schemas/public/model/posts.go index e1d80fa..306f4e8 100644 --- a/backend/database/schemas/public/model/posts.go +++ b/backend/database/schemas/public/model/posts.go @@ -27,4 +27,5 @@ type Posts struct { Likes int64 `json:"likes"` Tags fields.Json[[]string] `json:"tags"` Assets fields.Json[[]fields.MediaAsset] `json:"assets"` + HeadImages string `json:"head_images"` } diff --git a/backend/database/schemas/public/table/posts.go b/backend/database/schemas/public/table/posts.go index e7874ef..c1afaed 100644 --- a/backend/database/schemas/public/table/posts.go +++ b/backend/database/schemas/public/table/posts.go @@ -31,6 +31,7 @@ type postsTable struct { Likes postgres.ColumnInteger Tags postgres.ColumnString Assets postgres.ColumnString + HeadImages postgres.ColumnString AllColumns postgres.ColumnList MutableColumns postgres.ColumnList @@ -85,8 +86,9 @@ func newPostsTableImpl(schemaName, tableName, alias string) postsTable { LikesColumn = postgres.IntegerColumn("likes") TagsColumn = postgres.StringColumn("tags") AssetsColumn = postgres.StringColumn("assets") - allColumns = postgres.ColumnList{IDColumn, CreatedAtColumn, UpdatedAtColumn, DeletedAtColumn, StatusColumn, TitleColumn, DescriptionColumn, ContentColumn, PriceColumn, DiscountColumn, ViewsColumn, LikesColumn, TagsColumn, AssetsColumn} - mutableColumns = postgres.ColumnList{CreatedAtColumn, UpdatedAtColumn, DeletedAtColumn, StatusColumn, TitleColumn, DescriptionColumn, ContentColumn, PriceColumn, DiscountColumn, ViewsColumn, LikesColumn, TagsColumn, AssetsColumn} + HeadImagesColumn = postgres.StringColumn("head_images") + allColumns = postgres.ColumnList{IDColumn, CreatedAtColumn, UpdatedAtColumn, DeletedAtColumn, StatusColumn, TitleColumn, DescriptionColumn, ContentColumn, PriceColumn, DiscountColumn, ViewsColumn, LikesColumn, TagsColumn, AssetsColumn, HeadImagesColumn} + mutableColumns = postgres.ColumnList{CreatedAtColumn, UpdatedAtColumn, DeletedAtColumn, StatusColumn, TitleColumn, DescriptionColumn, ContentColumn, PriceColumn, DiscountColumn, ViewsColumn, LikesColumn, TagsColumn, AssetsColumn, HeadImagesColumn} ) return postsTable{ @@ -107,6 +109,7 @@ func newPostsTableImpl(schemaName, tableName, alias string) postsTable { Likes: LikesColumn, Tags: TagsColumn, Assets: AssetsColumn, + HeadImages: HeadImagesColumn, AllColumns: allColumns, MutableColumns: mutableColumns,