Merge branch 'dev' into feature/deprecated-oldweb

pull/256/head
Michael Li 2 years ago
commit 8418a45312
No known key found for this signature in database

@ -171,10 +171,11 @@ Postgres: # PostgreSQL数据库
User: paopao User: paopao
Password: paopao Password: paopao
DBName: paopao DBName: paopao
Schema: public
Host: localhost Host: localhost
Port: 5432 Port: 5432
SSLMode: disable SSLMode: disable
TimeZone: Asia/Shanghai ApplicationName:
Sqlite3: # Sqlite3数据库 Sqlite3: # Sqlite3数据库
Path: custom/data/sqlite3/paopao-ce.db Path: custom/data/sqlite3/paopao-ce.db
Redis: Redis:

@ -301,8 +301,18 @@ func (s *MySQLSettingS) Dsn() string {
func (s PostgresSettingS) Dsn() string { func (s PostgresSettingS) Dsn() string {
var params []string var params []string
for k, v := range s { for k, v := range s {
if len(v) > 0 { if len(v) == 0 {
params = append(params, strings.ToLower(k)+"="+v) continue
}
lk := strings.ToLower(k)
tv := strings.Trim(v, " ")
switch lk {
case "schema":
params = append(params, "search_path="+tv)
case "applicationname":
params = append(params, "application_name="+tv)
default:
params = append(params, lk+"="+tv)
} }
} }
return strings.Join(params, " ") return strings.Join(params, " ")

@ -7,6 +7,7 @@ package dbr
import ( import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/clause"
) )
const ( const (
@ -73,7 +74,7 @@ func (c *Contact) List(db *gorm.DB, conditions ConditionsT, offset, limit int) (
} }
} }
db.Joins("User").Order("`User`.`nickname` ASC") db.Joins("User").Order(clause.OrderByColumn{Column: clause.Column{Name: "nickname"}, Desc: false})
if err = db.Find(&contacts).Error; err != nil { if err = db.Find(&contacts).Error; err != nil {
return nil, err return nil, err
} }

@ -8,6 +8,7 @@ import (
"time" "time"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/clause"
) )
type PostCollection struct { type PostCollection struct {
@ -31,7 +32,7 @@ func (p *PostCollection) Get(db *gorm.DB) (*PostCollection, error) {
db = db.Where(tn+"user_id = ?", p.UserID) db = db.Where(tn+"user_id = ?", p.UserID)
} }
db = db.Joins("Post").Where("Post.visibility <> ?", PostVisitPrivate).Order("Post.id DESC") db = db.Joins("Post").Where("visibility <> ?", PostVisitPrivate).Order(clause.OrderByColumn{Column: clause.Column{Table: "Post", Name: "id"}, Desc: true})
err := db.First(&star).Error err := db.First(&star).Error
if err != nil { if err != nil {
return &star, err return &star, err
@ -73,7 +74,7 @@ func (p *PostCollection) List(db *gorm.DB, conditions *ConditionsT, offset, limi
} }
} }
db = db.Joins("Post").Where("Post.visibility <> ?", PostVisitPrivate).Order("Post.id DESC") db = db.Joins("Post").Where(`visibility <> ?`, PostVisitPrivate).Order(clause.OrderByColumn{Column: clause.Column{Table: "Post", Name: "id"}, Desc: true})
if err = db.Where(tn+"is_del = ?", 0).Find(&collections).Error; err != nil { if err = db.Where(tn+"is_del = ?", 0).Find(&collections).Error; err != nil {
return nil, err return nil, err
} }
@ -97,7 +98,7 @@ func (p *PostCollection) Count(db *gorm.DB, conditions *ConditionsT) (int64, err
} }
} }
db = db.Joins("Post").Where("Post.visibility <> ?", PostVisitPrivate) db = db.Joins("Post").Where(`visibility <> ?`, PostVisitPrivate)
if err := db.Model(p).Count(&count).Error; err != nil { if err := db.Model(p).Count(&count).Error; err != nil {
return 0, err return 0, err
} }

@ -8,6 +8,7 @@ import (
"time" "time"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/clause"
) )
type PostStar struct { type PostStar struct {
@ -31,7 +32,7 @@ func (p *PostStar) Get(db *gorm.DB) (*PostStar, error) {
db = db.Where(tn+"user_id = ?", p.UserID) db = db.Where(tn+"user_id = ?", p.UserID)
} }
db = db.Joins("Post").Where("Post.visibility <> ?", PostVisitPrivate).Order("Post.id DESC") db = db.Joins("Post").Where("visibility <> ?", PostVisitPrivate).Order(clause.OrderByColumn{Column: clause.Column{Table: "Post", Name: "id"}, Desc: true})
if err := db.First(&star).Error; err != nil { if err := db.First(&star).Error; err != nil {
return nil, err return nil, err
} }
@ -71,7 +72,7 @@ func (p *PostStar) List(db *gorm.DB, conditions *ConditionsT, offset, limit int)
} }
} }
db = db.Joins("Post").Where("Post.visibility <> ?", PostVisitPrivate).Order("Post.id DESC") db = db.Joins("Post").Where("visibility <> ?", PostVisitPrivate).Order(clause.OrderByColumn{Column: clause.Column{Table: "Post", Name: "id"}, Desc: true})
if err = db.Find(&stars).Error; err != nil { if err = db.Find(&stars).Error; err != nil {
return nil, err return nil, err
} }
@ -94,7 +95,7 @@ func (p *PostStar) Count(db *gorm.DB, conditions *ConditionsT) (int64, error) {
} }
} }
db = db.Joins("Post").Where("Post.visibility <> ?", PostVisitPrivate) db = db.Joins("Post").Where("visibility <> ?", PostVisitPrivate)
if err := db.Model(p).Count(&count).Error; err != nil { if err := db.Model(p).Count(&count).Error; err != nil {
return 0, err return 0, err
} }

@ -13,3 +13,4 @@ DROP TABLE IF EXISTS p_tag;
DROP TABLE IF EXISTS p_user; DROP TABLE IF EXISTS p_user;
DROP TABLE IF EXISTS p_wallet_recharge; DROP TABLE IF EXISTS p_wallet_recharge;
DROP TABLE IF EXISTS p_wallet_statement; DROP TABLE IF EXISTS p_wallet_statement;
DROP SEQUENCE IF EXISTS post_id_seq;

@ -94,8 +94,9 @@ CREATE INDEX idx_message_receiver_user_id ON p_message USING btree (receiver_use
CREATE INDEX idx_message_is_read ON p_message USING btree (is_read); 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 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 ( CREATE TABLE p_post (
id BIGSERIAL PRIMARY KEY, id BIGINT NOT NULL DEFAULT nextval('post_id_seq'::regclass),
user_id BIGINT NOT NULL DEFAULT 0, user_id BIGINT NOT NULL DEFAULT 0,
comment_count BIGINT NOT NULL DEFAULT 0, comment_count BIGINT NOT NULL DEFAULT 0,
collection_count BIGINT NOT NULL DEFAULT 0, collection_count BIGINT NOT NULL DEFAULT 0,
@ -111,7 +112,8 @@ CREATE TABLE p_post (
created_on BIGINT NOT NULL DEFAULT 0, created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0, modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0, deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT 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 INDEX idx_post_user_id ON p_post USING btree (user_id);
@ -191,7 +193,7 @@ CREATE TABLE p_user (
status SMALLINT NOT NULL DEFAULT 1, -- 状态1正常2停用 status SMALLINT NOT NULL DEFAULT 1, -- 状态1正常2停用
avatar VARCHAR(255) NOT NULL DEFAULT '', avatar VARCHAR(255) NOT NULL DEFAULT '',
balance BIGINT NOT NULL, -- 用户余额(分) balance BIGINT NOT NULL, -- 用户余额(分)
is_admin SMALLINT NOT NULL DEFAULT 0, -- 是否管理员 is_admin BOOLEAN NOT NULL DEFAULT false, -- 是否管理员
created_on BIGINT NOT NULL DEFAULT 0, created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0, modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0, deleted_on BIGINT NOT NULL DEFAULT 0,

@ -1,2 +1 @@
ALTER TABLE p_post ADD COLUMN visibility SMALLINT NOT NULL DEFAULT 0; -- 可见性 0公开 1私密 2好友可见 ALTER TABLE p_post ADD COLUMN visibility SMALLINT NOT NULL DEFAULT 0; -- 可见性 0公开 1私密 2好友可见
CREATE INDEX idx_visibility ON p_post USING btree (visibility)

@ -7,7 +7,7 @@ CREATE TABLE p_contact (
status SMALLINT NOT NULL DEFAULT 0, -- 好友状态: 1请求好友, 2已好友, 3拒绝好友, 4已删好友 status SMALLINT NOT NULL DEFAULT 0, -- 好友状态: 1请求好友, 2已好友, 3拒绝好友, 4已删好友
is_top SMALLINT NOT NULL DEFAULT 0, -- 是否置顶, 0否, 1是 is_top SMALLINT NOT NULL DEFAULT 0, -- 是否置顶, 0否, 1是
is_black SMALLINT NOT NULL DEFAULT 0, -- 是否为黑名单, 0否, 1是 is_black SMALLINT NOT NULL DEFAULT 0, -- 是否为黑名单, 0否, 1是
is_delete 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是 notice_enable SMALLINT NOT NULL DEFAULT 0, -- 是否有消息提醒, 0否, 1是
created_on BIGINT NOT NULL DEFAULT 0, created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0, modified_on BIGINT NOT NULL DEFAULT 0,
@ -20,7 +20,7 @@ CREATE TABLE p_contact_group (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,
user_id int NOT NULL DEFAULT 0, user_id int NOT NULL DEFAULT 0,
name VARCHAR(32) NOT NULL DEFAULT '', -- 分组名称 name VARCHAR(32) NOT NULL DEFAULT '', -- 分组名称
is_delete SMALLINT NOT NULL DEFAULT 1, -- 是否删除, 0否, 1是 is_del SMALLINT NOT NULL DEFAULT 1, -- 是否删除, 0否, 1是
created_on BIGINT NOT NULL DEFAULT 0, created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0, modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0 deleted_on BIGINT NOT NULL DEFAULT 0

@ -106,9 +106,10 @@ CREATE INDEX idx_message_receiver_user_id ON p_message USING btree (receiver_use
CREATE INDEX idx_message_is_read ON p_message USING btree (is_read); 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 INDEX idx_message_type ON p_message USING btree ("type");
CREATE SEQUENCE IF NOT EXISTS post_id_seq AS BIGINT MINVALUE 1080017989 NO MAXVALUE;
DROP TABLE IF EXISTS p_post; DROP TABLE IF EXISTS p_post;
CREATE TABLE p_post ( CREATE TABLE p_post (
id BIGSERIAL PRIMARY KEY, id BIGINT NOT NULL DEFAULT nextval('post_id_seq'::regclass),
user_id BIGINT NOT NULL DEFAULT 0, user_id BIGINT NOT NULL DEFAULT 0,
comment_count BIGINT NOT NULL DEFAULT 0, comment_count BIGINT NOT NULL DEFAULT 0,
collection_count BIGINT NOT NULL DEFAULT 0, collection_count BIGINT NOT NULL DEFAULT 0,
@ -125,7 +126,8 @@ CREATE TABLE p_post (
created_on BIGINT NOT NULL DEFAULT 0, created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0, modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0, deleted_on BIGINT NOT NULL DEFAULT 0,
is_del SMALLINT 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 INDEX idx_post_user_id ON p_post USING btree (user_id);
CREATE INDEX idx_post_visibility ON p_post USING btree (visibility); CREATE INDEX idx_post_visibility ON p_post USING btree (visibility);
@ -212,7 +214,7 @@ CREATE TABLE p_user (
status SMALLINT NOT NULL DEFAULT 1, -- 状态1正常2停用 status SMALLINT NOT NULL DEFAULT 1, -- 状态1正常2停用
avatar VARCHAR(255) NOT NULL DEFAULT '', avatar VARCHAR(255) NOT NULL DEFAULT '',
balance BIGINT NOT NULL, -- 用户余额(分) balance BIGINT NOT NULL, -- 用户余额(分)
is_admin SMALLINT NOT NULL DEFAULT 0, -- 是否管理员 is_admin BOOLEAN NOT NULL DEFAULT false, -- 是否管理员
created_on BIGINT NOT NULL DEFAULT 0, created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0, modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0, deleted_on BIGINT NOT NULL DEFAULT 0,
@ -231,7 +233,7 @@ CREATE TABLE p_contact (
status SMALLINT NOT NULL DEFAULT 0, -- 好友状态: 1请求好友, 2已好友, 3拒绝好友, 4已删好友 status SMALLINT NOT NULL DEFAULT 0, -- 好友状态: 1请求好友, 2已好友, 3拒绝好友, 4已删好友
is_top SMALLINT NOT NULL DEFAULT 0, -- 是否置顶, 0否, 1是 is_top SMALLINT NOT NULL DEFAULT 0, -- 是否置顶, 0否, 1是
is_black SMALLINT NOT NULL DEFAULT 0, -- 是否为黑名单, 0否, 1是 is_black SMALLINT NOT NULL DEFAULT 0, -- 是否为黑名单, 0否, 1是
is_delete 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是 notice_enable SMALLINT NOT NULL DEFAULT 0, -- 是否有消息提醒, 0否, 1是
created_on BIGINT NOT NULL DEFAULT 0, created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0, modified_on BIGINT NOT NULL DEFAULT 0,
@ -245,7 +247,7 @@ CREATE TABLE p_contact_group (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,
user_id int NOT NULL DEFAULT 0, user_id int NOT NULL DEFAULT 0,
name VARCHAR(32) NOT NULL DEFAULT '', -- 分组名称 name VARCHAR(32) NOT NULL DEFAULT '', -- 分组名称
is_delete SMALLINT NOT NULL DEFAULT 1, -- 是否删除, 0否, 1是 is_del SMALLINT NOT NULL DEFAULT 1, -- 是否删除, 0否, 1是
created_on BIGINT NOT NULL DEFAULT 0, created_on BIGINT NOT NULL DEFAULT 0,
modified_on BIGINT NOT NULL DEFAULT 0, modified_on BIGINT NOT NULL DEFAULT 0,
deleted_on BIGINT NOT NULL DEFAULT 0 deleted_on BIGINT NOT NULL DEFAULT 0

Loading…
Cancel
Save