diff --git a/internal/dao/slonik/ce/postgres/models.go b/internal/dao/slonik/ce/postgres/models.go index 3d23c045..cdd22695 100644 --- a/internal/dao/slonik/ce/postgres/models.go +++ b/internal/dao/slonik/ce/postgres/models.go @@ -4,9 +4,183 @@ package dbr -import () +import ( + "github.com/jackc/pgx/v5/pgtype" +) + +type PAttachment struct { + ID int64 + UserID int64 + FileSize int64 + ImgWidth int64 + ImgHeight int64 + Type int16 + Content string + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 + IsDel int16 +} + +type PCaptcha struct { + ID int64 + Phone pgtype.Text + Captcha pgtype.Text + UseTimes int32 + ExpiredOn int64 + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 + IsDel int16 +} + +type PComment struct { + ID int64 + PostID int64 + UserID int64 + Ip string + IpLoc string + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 + IsDel int16 +} + +type PCommentContent struct { + ID int64 + CommentID int64 + UserID int64 + Content string + Type int16 + Sort int64 + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 + IsDel int16 +} + +type PCommentReply struct { + ID int64 + CommentID int64 + UserID int64 + AtUserID int64 + Content string + Ip string + IpLoc string + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 + IsDel int16 +} + +type PContact struct { + ID int64 + UserID int64 + FriendID int64 + GroupID int64 + Remark string + Status int16 + IsTop int16 + IsBlack int16 + IsDel int16 + NoticeEnable int16 + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 +} + +type PContactGroup struct { + ID int64 + UserID int32 + Name string + IsDel int16 + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 +} + +type PMessage struct { + ID int64 + SenderUserID int64 + ReceiverUserID int64 + Type int16 + Brief string + Content string + PostID int64 + CommentID int64 + ReplyID int64 + IsRead int16 + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 + IsDel int16 +} + +type PPost struct { + ID int64 + UserID int64 + CommentCount int64 + CollectionCount int64 + UpvoteCount int64 + IsTop int16 + IsEssence int16 + IsLock int16 + LatestRepliedOn int64 + Tags string + AttachmentPrice int64 + Ip string + IpLoc string + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 + IsDel int16 + Visibility int16 +} + +type PPostAttachmentBill struct { + ID int64 + PostID int64 + UserID int64 + PaidAmount int64 + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 + IsDel int16 +} + +type PPostCollection struct { + ID int64 + PostID int64 + UserID int64 + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 + IsDel int16 +} + +type PPostContent struct { + ID int64 + PostID int64 + UserID int64 + Content string + Type int16 + Sort int16 + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 + IsDel int16 +} + +type PPostStar struct { + ID int64 + PostID int64 + UserID int64 + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 + IsDel int16 +} -// 主题标签 type PTag struct { ID int64 UserID int64 @@ -15,8 +189,7 @@ type PTag struct { CreatedOn int64 ModifiedOn int64 DeletedOn int64 - // 是否删除 - IsDel bool + IsDel int16 } // 用户 @@ -37,5 +210,30 @@ type PUser struct { CreatedOn int64 ModifiedOn int64 DeletedOn int64 - IsDel bool + IsDel int16 +} + +type PWalletRecharge struct { + ID int64 + UserID int64 + Amount int64 + TradeNo string + TradeStatus string + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 + IsDel int16 +} + +type PWalletStatement struct { + ID int64 + UserID int64 + ChangeAmount int64 + BalanceSnapshot int64 + Reason string + PostID int64 + CreatedOn int64 + ModifiedOn int64 + DeletedOn int64 + IsDel int16 } diff --git a/internal/dao/slonik/ce/postgres/query/topic.sql b/internal/dao/slonik/ce/postgres/query/topic.sql index b549b6fc..b7fb950c 100644 --- a/internal/dao/slonik/ce/postgres/query/topic.sql +++ b/internal/dao/slonik/ce/postgres/query/topic.sql @@ -38,7 +38,7 @@ SET quote_num = quote_num-1, WHERE id IN ( SELECT id FROM p_tag - WHERE id = ANY(@ids::bigserial[]) AND is_del = false AND quote_num >= 1 + WHERE id = ANY(@ids::BIGINT[]) AND is_del = false AND quote_num >= 1 ); -- name: IncrTags :many @@ -49,6 +49,6 @@ SET quote_num = quote_num+1, WHERE id IN ( SELECT id FROM p_tag - WHERE tag = ANY(@tags::varchar[]) + WHERE tag = ANY(@tags::VARCHAR[]) ) RETURNING id, user_id, tag, quote_num; diff --git a/internal/dao/slonik/ce/postgres/schema/0001_initialize_schema.down.sql b/internal/dao/slonik/ce/postgres/schema/0001_initialize_schema.down.sql index a7b22974..d1fdd15f 100644 --- a/internal/dao/slonik/ce/postgres/schema/0001_initialize_schema.down.sql +++ b/internal/dao/slonik/ce/postgres/schema/0001_initialize_schema.down.sql @@ -1,5 +1,17 @@ +DROP TABLE IF EXISTS p_attachment; +DROP TABLE IF EXISTS p_captcha; +DROP TABLE IF EXISTS p_comment; +DROP TABLE IF EXISTS p_comment_content; +DROP TABLE IF EXISTS p_comment_reply; +DROP TABLE IF EXISTS p_message; +DROP TABLE IF EXISTS p_post; +DROP TABLE IF EXISTS p_post_attachment_bill; +DROP TABLE IF EXISTS p_post_collection; +DROP TABLE IF EXISTS p_post_content; +DROP TABLE IF EXISTS p_post_star; +DROP TABLE IF EXISTS p_tag; DROP TABLE IF EXISTS p_user; -DROP INDEX IF EXISTS p_user_username_idx, p_user_phone_idx; +DROP TABLE IF EXISTS p_wallet_recharge; +DROP TABLE IF EXISTS p_wallet_statement; +DROP SEQUENCE IF EXISTS post_id_seq; -DROP TABLE IF EXISTS p_tag; -DROP INDEX IF EXISTS p_tag_tag_idx, p_tag_user_idx, p_tag_quote_num_idx; diff --git a/internal/dao/slonik/ce/postgres/schema/0001_initialize_schema.up.sql b/internal/dao/slonik/ce/postgres/schema/0001_initialize_schema.up.sql index c097e776..43a68d2f 100644 --- a/internal/dao/slonik/ce/postgres/schema/0001_initialize_schema.up.sql +++ b/internal/dao/slonik/ce/postgres/schema/0001_initialize_schema.up.sql @@ -1,42 +1,236 @@ --- user ddl -- +CREATE TABLE p_attachment ( + id BIGSERIAL PRIMARY KEY, + user_id BIGINT NOT NULL DEFAULT 0, + file_size BIGINT NOT NULL, + img_width BIGINT NOT NULL DEFAULT 0, + img_height BIGINT NOT NULL DEFAULT 0, + "type" SMALLINT NOT NULL DEFAULT 1, -- 1图片、2视频、3其他附件 + content VARCHAR(255) NOT NULL DEFAULT '', + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0 -- 是否删除 0为未删除、1为已删除 +); +CREATE INDEX idx_attachment_user_id ON p_attachment USING btree (id); + +CREATE TABLE p_captcha ( + id BIGSERIAL PRIMARY KEY, + phone VARCHAR(16), + captcha VARCHAR(16), + use_times INTEGER NOT NULL DEFAULT 0, + expired_on BIGINT NOT NULL DEFAULT 0, + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0 -- 是否删除 0为未删除、1为已删除' +); +CREATE INDEX idx_captcha_phone ON p_captcha USING btree (phone); +CREATE INDEX idx_captcha_expired_on ON p_captcha USING btree (expired_on); +CREATE INDEX idx_captcha_use_times ON p_captcha USING btree (use_times); + +CREATE TABLE p_comment ( + id BIGSERIAL PRIMARY KEY, + post_id BIGINT NOT NULL DEFAULT 0, + user_id BIGINT NOT NULL DEFAULT 0, + ip VARCHAR(64) NOT NULL DEFAULT '', + ip_loc VARCHAR(64) NOT NULL DEFAULT '', + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0 +); +CREATE INDEX idx_comment_post_id ON p_comment USING btree (post_id); +CREATE INDEX idx_comment_user_id ON p_comment USING btree (user_id); + +CREATE TABLE p_comment_content ( + id BIGSERIAL PRIMARY KEY, + comment_id BIGINT NOT NULL DEFAULT 0, + user_id BIGINT NOT NULL DEFAULT 0, + content VARCHAR(255) NOT NULL DEFAULT '', + "type" SMALLINT NOT NULL DEFAULT 2, -- 类型,1标题,2文字段落,3图片地址,4视频地址,5语音地址,6链接地址, + sort BIGINT NOT NULL DEFAULT 100, + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0 +); +CREATE INDEX idx_comment_content_comment_id ON p_comment_content USING btree (comment_id); +CREATE INDEX idx_comment_content_user_id ON p_comment_content USING btree (user_id); +CREATE INDEX idx_comment_content_type ON p_comment_content USING btree ("type"); +CREATE INDEX idx_comment_content_sort ON p_comment_content USING btree (sort); + +CREATE TABLE p_comment_reply ( + id BIGSERIAL PRIMARY KEY, + comment_id BIGINT NOT NULL DEFAULT 0, + user_id BIGINT NOT NULL DEFAULT 0, + at_user_id BIGINT NOT NULL DEFAULT 0, + content VARCHAR(255) NOT NULL DEFAULT '', + ip VARCHAR(64) NOT NULL DEFAULT '', + ip_loc VARCHAR(64) NOT NULL DEFAULT '', + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0 +); +CREATE INDEX idx_comment_reply_comment_id ON p_comment_reply USING btree (comment_id); + +CREATE TABLE p_message ( + id BIGSERIAL PRIMARY KEY, + sender_user_id BIGINT NOT NULL DEFAULT 0, + receiver_user_id BIGINT NOT NULL DEFAULT 0, + type SMALLINT NOT NULL DEFAULT 1, + brief VARCHAR(255) NOT NULL DEFAULT '', + content VARCHAR(255) NOT NULL DEFAULT '', + post_id BIGINT NOT NULL DEFAULT 0, + comment_id BIGINT NOT NULL DEFAULT 0, + reply_id BIGINT NOT NULL DEFAULT 0, + is_read SMALLINT NOT NULL DEFAULT 0, + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0 +); +CREATE INDEX idx_message_receiver_user_id ON p_message USING btree (receiver_user_id); +CREATE INDEX idx_message_is_read ON p_message USING btree (is_read); +CREATE INDEX idx_message_type ON p_message USING btree ("type"); + +CREATE SEQUENCE IF NOT EXISTS post_id_seq AS BIGINT MINVALUE 1080017989 NO MAXVALUE; +CREATE TABLE p_post ( + id BIGINT NOT NULL DEFAULT nextval('post_id_seq'::regclass), + user_id BIGINT NOT NULL DEFAULT 0, + comment_count BIGINT NOT NULL DEFAULT 0, + collection_count BIGINT NOT NULL DEFAULT 0, + upvote_count BIGINT NOT NULL DEFAULT 0, + is_top SMALLINT NOT NULL DEFAULT 0, -- 是否置顶 + is_essence SMALLINT NOT NULL DEFAULT 0, -- 是否精华 + is_lock SMALLINT NOT NULL DEFAULT 0, -- 是否锁定 + latest_replied_on BIGINT NOT NULL DEFAULT 0, -- 最新回复时间 + tags VARCHAR(255) NOT NULL DEFAULT '', + attachment_price BIGINT NOT NULL DEFAULT 0, -- 附件价格(分) + ip VARCHAR(64) NOT NULL DEFAULT '', -- IP地址 + ip_loc VARCHAR(64) NOT NULL DEFAULT '', -- IP城市地址 + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0, + PRIMARY KEY (id) +); +CREATE INDEX idx_post_user_id ON p_post USING btree (user_id); + +CREATE TABLE p_post_attachment_bill ( + id BIGSERIAL PRIMARY KEY, + post_id BIGINT NOT NULL DEFAULT 0, + user_id BIGINT NOT NULL DEFAULT 0, + paid_amount BIGINT NOT NULL DEFAULT 0, -- 支付金额 + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0 +); +CREATE INDEX idx_post_attachment_bill_post_id ON p_post_attachment_bill USING btree (post_id); +CREATE INDEX idx_post_attachment_bill_user_id ON p_post_attachment_bill USING btree (user_id); + +CREATE TABLE p_post_collection ( + id BIGSERIAL PRIMARY KEY, + post_id BIGINT NOT NULL DEFAULT 0, + user_id BIGINT NOT NULL DEFAULT 0, + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0 +); +CREATE INDEX idx_post_collection_post_id ON p_post_collection USING btree (post_id); +CREATE INDEX idx_post_collection_user_id ON p_post_collection USING btree (user_id); + +CREATE TABLE p_post_content ( + id BIGSERIAL PRIMARY KEY, + post_id BIGINT NOT NULL DEFAULT 0, + user_id BIGINT NOT NULL DEFAULT 0, + content VARCHAR(2000) NOT NULL DEFAULT '', + "type" SMALLINT NOT NULL DEFAULT 2, -- 类型,1标题,2文字段落,3图片地址,4视频地址,5语音地址,6链接地址,7附件资源,8收费资源 + sort SMALLINT NOT NULL DEFAULT 100, + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0 +); +CREATE INDEX idx_post_content_post_id ON p_post_content USING btree (post_id); +CREATE INDEX idx_post_content_user_id ON p_post_content USING btree (user_id); + +CREATE TABLE p_post_star ( + id BIGSERIAL PRIMARY KEY, + post_id BIGINT NOT NULL DEFAULT 0, + user_id BIGINT NOT NULL DEFAULT 0, + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0 +); +CREATE INDEX idx_post_star_post_id ON p_post_star USING btree (post_id); +CREATE INDEX idx_post_star_user_id ON p_post_star USING btree (user_id); + +CREATE TABLE p_tag ( + id BIGSERIAL PRIMARY KEY, + user_id BIGINT NOT NULL DEFAULT 0, + tag VARCHAR(255) NOT NULL, + quote_num BIGINT NOT NULL DEFAULT 0, -- 引用数 + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0 +); +CREATE UNIQUE INDEX idx_tag_tag ON p_tag USING btree (tag); +CREATE INDEX idx_tag_user_id ON p_tag USING btree (user_id); +CREATE INDEX idx_tag_quote_num ON p_tag USING btree (quote_num); + CREATE TABLE p_user ( - id bigserial PRIMARY KEY, + id BIGSERIAL PRIMARY KEY, nickname VARCHAR(32) NOT NULL DEFAULT '', username VARCHAR(32) NOT NULL DEFAULT '', - phone VARCHAR(16) NOT NULL DEFAULT '', - PASSWORD VARCHAR(32) NOT NULL DEFAULT '', - salt VARCHAR(16) NOT NULL DEFAULT '', - status SMALLINT NOT NULL DEFAULT 1, + phone VARCHAR(16) NOT NULL DEFAULT '', -- 手机号 + password VARCHAR(32) NOT NULL DEFAULT '', -- MD5密码 + salt VARCHAR(16) NOT NULL DEFAULT '', -- 盐值 + status SMALLINT NOT NULL DEFAULT 1, -- 状态,1正常,2停用 avatar VARCHAR(255) NOT NULL DEFAULT '', - balance BIGINT NOT NULL, - is_admin BOOLEAN NOT NULL DEFAULT FALSE, - created_on BIGINT NOT NULL, - modified_on BIGINT NOT NULL, - deleted_on BIGINT NOT NULL, - is_del BOOLEAN NOT NULL DEFAULT FALSE, - UNIQUE (username) + balance BIGINT NOT NULL, -- 用户余额(分) + is_admin BOOLEAN NOT NULL DEFAULT false, -- 是否管理员 + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0 ); COMMENT ON TABLE p_user IS '用户'; COMMENT ON COLUMN p_user.password IS 'MD5密码'; COMMENT ON COLUMN p_user.status IS '状态, 1正常, 2停用'; COMMENT ON COLUMN p_user.balance IS '用户余额(分)'; -CREATE UNIQUE INDEX p_user_username_idx ON p_user (username); -CREATE INDEX p_user_phone_idx ON p_user (phone); +CREATE UNIQUE INDEX idx_user_username ON p_user USING btree (username); +CREATE INDEX idx_user_phone ON p_user USING btree (phone); --- tag ddl -- -CREATE TABLE p_tag ( - id bigserial PRIMARY KEY, - user_id bigserial NOT NULL, - tag VARCHAR(255) NOT NULL, - quote_num BIGINT NOT NULL DEFAULT 0, +CREATE TABLE p_wallet_recharge ( + id BIGSERIAL PRIMARY KEY, + user_id BIGINT NOT NULL DEFAULT 0, + amount BIGINT NOT NULL DEFAULT 0, -- 充值金额 + trade_no VARCHAR(64) NOT NULL DEFAULT '', -- 支付宝订单号 + trade_status VARCHAR(32) NOT NULL DEFAULT '', -- 交易状态 + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0, + is_del SMALLINT NOT NULL DEFAULT 0 -- 是否删除 0 为未删除、1 为已删除 +); +CREATE INDEX idx_wallet_recharge_user_id ON p_wallet_recharge USING btree (user_id); +CREATE INDEX idx_wallet_recharge_trade_no ON p_wallet_recharge USING btree (trade_no); +CREATE INDEX idx_wallet_recharge_trade_status ON p_wallet_recharge USING btree (trade_status); + +CREATE TABLE p_wallet_statement ( + id BIGSERIAL PRIMARY KEY, + user_id BIGINT NOT NULL DEFAULT 0, + change_amount BIGINT NOT NULL DEFAULT 0, -- 变动金额 + balance_snapshot BIGINT NOT NULL DEFAULT 0, -- 资金快照 + reason VARCHAR(255) NOT NULL, -- 变动原因 + post_id BIGINT NOT NULL DEFAULT 0, -- 关联动态 created_on BIGINT NOT NULL DEFAULT 0, modified_on BIGINT NOT NULL DEFAULT 0, deleted_on BIGINT NOT NULL DEFAULT 0, - is_del BOOLEAN NOT NULL DEFAULT FALSE, - UNIQUE (tag) + is_del SMALLINT NOT NULL DEFAULT 0 ); -COMMENT ON TABLE p_tag IS '主题标签'; -COMMENT ON COLUMN p_tag.is_del IS '是否删除'; -CREATE UNIQUE INDEX p_tag_tag_idx ON p_tag (tag); -CREATE INDEX p_tag_user_idx ON p_tag (user_id); -CREATE INDEX p_tag_quote_num_idx ON p_tag (quote_num); +CREATE INDEX idx_wallet_statement_user_id ON p_wallet_statement USING btree (user_id); diff --git a/internal/dao/slonik/ce/postgres/schema/0002_post_visibility.down.sql b/internal/dao/slonik/ce/postgres/schema/0002_post_visibility.down.sql new file mode 100644 index 00000000..2c9986ac --- /dev/null +++ b/internal/dao/slonik/ce/postgres/schema/0002_post_visibility.down.sql @@ -0,0 +1 @@ +ALTER TABLE p_post DROP COLUMN visibility; diff --git a/internal/dao/slonik/ce/postgres/schema/0002_post_visibility.up.sql b/internal/dao/slonik/ce/postgres/schema/0002_post_visibility.up.sql new file mode 100644 index 00000000..673432ab --- /dev/null +++ b/internal/dao/slonik/ce/postgres/schema/0002_post_visibility.up.sql @@ -0,0 +1 @@ +ALTER TABLE p_post ADD COLUMN visibility SMALLINT NOT NULL DEFAULT 0; -- 可见性 0公开 1私密 2好友可见 diff --git a/internal/dao/slonik/ce/postgres/schema/0003_feature_contact.down.sql b/internal/dao/slonik/ce/postgres/schema/0003_feature_contact.down.sql new file mode 100644 index 00000000..d3eb2b4e --- /dev/null +++ b/internal/dao/slonik/ce/postgres/schema/0003_feature_contact.down.sql @@ -0,0 +1,2 @@ +DROP TABLE IF EXISTS p_contact; +DROP TABLE IF EXISTS p_contact_group; diff --git a/internal/dao/slonik/ce/postgres/schema/0003_feature_contact.up.sql b/internal/dao/slonik/ce/postgres/schema/0003_feature_contact.up.sql new file mode 100644 index 00000000..9177db77 --- /dev/null +++ b/internal/dao/slonik/ce/postgres/schema/0003_feature_contact.up.sql @@ -0,0 +1,27 @@ +CREATE TABLE p_contact ( + id BIGSERIAL PRIMARY KEY, + user_id BIGINT NOT NULL, + friend_id BIGINT NOT NULL, + group_id BIGINT NOT NULL DEFAULT 0, -- 好友分组ID:默认为0无分组 + remark VARCHAR(32) NOT NULL DEFAULT '', -- 好友备注 + status SMALLINT NOT NULL DEFAULT 0, -- 好友状态: 1请求好友, 2已好友, 3拒绝好友, 4已删好友 + is_top SMALLINT NOT NULL DEFAULT 0, -- 是否置顶, 0否, 1是 + is_black SMALLINT NOT NULL DEFAULT 0, -- 是否为黑名单, 0否, 1是 + is_del SMALLINT NOT NULL DEFAULT 0, -- 否删除好友, 0否, 1是 + notice_enable SMALLINT NOT NULL DEFAULT 0, -- 是否有消息提醒, 0否, 1是 + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0 +); +CREATE UNIQUE INDEX idx_contact_user_friend ON p_contact USING btree (user_id,friend_id); +CREATE INDEX idx_contact_user_friend_status ON p_contact USING btree (user_id, friend_id, status); + +CREATE TABLE p_contact_group ( + id BIGSERIAL PRIMARY KEY, + user_id int NOT NULL DEFAULT 0, + name VARCHAR(32) NOT NULL DEFAULT '', -- 分组名称 + is_del SMALLINT NOT NULL DEFAULT 1, -- 是否删除, 0否, 1是 + created_on BIGINT NOT NULL DEFAULT 0, + modified_on BIGINT NOT NULL DEFAULT 0, + deleted_on BIGINT NOT NULL DEFAULT 0 +); diff --git a/internal/dao/slonik/ce/postgres/topic.sql.go b/internal/dao/slonik/ce/postgres/topic.sql.go index 49dd48a2..f25a27e8 100644 --- a/internal/dao/slonik/ce/postgres/topic.sql.go +++ b/internal/dao/slonik/ce/postgres/topic.sql.go @@ -16,7 +16,7 @@ SET quote_num = quote_num-1, WHERE id IN ( SELECT id FROM p_tag - WHERE id = ANY($2::bigserial[]) AND is_del = false AND quote_num >= 1 + WHERE id = ANY($2::BIGINT[]) AND is_del = false AND quote_num >= 1 ) ` @@ -93,7 +93,7 @@ SET quote_num = quote_num+1, WHERE id IN ( SELECT id FROM p_tag - WHERE tag = ANY($2::varchar[]) + WHERE tag = ANY($2::VARCHAR[]) ) RETURNING id, user_id, tag, quote_num ` diff --git a/internal/dao/slonik/topics.go b/internal/dao/slonik/topics.go index 94af2c1c..a1ce3d7d 100644 --- a/internal/dao/slonik/topics.go +++ b/internal/dao/slonik/topics.go @@ -13,7 +13,6 @@ import ( "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" dbr "github.com/rocboss/paopao-ce/internal/dao/slonik/ce/postgres" - "github.com/rocboss/paopao-ce/pkg/types" ) var ( @@ -30,7 +29,7 @@ func (s *topicServant) UpsertTags(userId int64, tags []string) (res cs.TagInfoLi err = s.with(func(c context.Context, q dbr.Querier) error { now := time.Now().Unix() upTags, err := q.IncrTags(c, &dbr.IncrTagsParams{ - Tags: types.PgxArray(tags), + Tags: tags, ModifiedOn: now, }) if err != nil { @@ -77,7 +76,7 @@ func (s *topicServant) UpsertTags(userId int64, tags []string) (res cs.TagInfoLi func (s *topicServant) DecrTagsById(ids []int64) error { return s.q.DecrTagsById(context.Background(), &dbr.DecrTagsByIdParams{ - Ids: types.PgxArray(ids), + Ids: ids, ModifiedOn: time.Now().Unix(), }) }