From c57cc89dfeeab6b76238afb8dd94b22832d2bc92 Mon Sep 17 00:00:00 2001 From: fish Date: Sat, 28 Mar 2026 20:16:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8=20UUIDv7=20=E7=94=9F?= =?UTF-8?q?=E6=88=90=20UUID=EF=BC=8C=E8=AE=BE=E7=BD=AE=20create=5Ftime=20?= =?UTF-8?q?=E5=92=8C=20update=5Ftime=20=E4=B8=BA=E4=B8=9C=E5=85=AB?= =?UTF-8?q?=E5=8C=BA=E6=97=B6=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/user-svc/internal/repository/repo.go | 6 +++--- backend/services/user-svc/migrations/001_init.sql | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/services/user-svc/internal/repository/repo.go b/backend/services/user-svc/internal/repository/repo.go index ad4b858..955b060 100644 --- a/backend/services/user-svc/internal/repository/repo.go +++ b/backend/services/user-svc/internal/repository/repo.go @@ -41,7 +41,7 @@ func (r *UserRepository) Register(req *domain.RegisterRequest) (*domain.Register } // 创建用户 - userID := uuid.New() + userID := uuid.NewV7() now := time.Now() userQuery := "INSERT INTO user_main (id, deleted, create_time, update_time) VALUES ($1, $2, $3, $4)" @@ -51,7 +51,7 @@ func (r *UserRepository) Register(req *domain.RegisterRequest) (*domain.Register } // 创建登录账号 - accountID := uuid.New() + accountID := uuid.NewV7() accountQuery := "INSERT INTO user_login_account (id, user_id, account, deleted, create_time, update_time) VALUES ($1, $2, $3, $4, $5, $6)" if _, err := tx.Exec(accountQuery, accountID, userID, req.Account, false, now, now); err != nil { tx.Rollback() @@ -66,7 +66,7 @@ func (r *UserRepository) Register(req *domain.RegisterRequest) (*domain.Register } // 创建密码记录 - passwordID := uuid.New() + passwordID := uuid.NewV7() passwordQuery := "INSERT INTO user_login_password (id, user_id, password, deleted, create_time, update_time) VALUES ($1, $2, $3, $4, $5, $6)" if _, err := tx.Exec(passwordQuery, passwordID, userID, string(hashedPassword), false, now, now); err != nil { tx.Rollback() diff --git a/backend/services/user-svc/migrations/001_init.sql b/backend/services/user-svc/migrations/001_init.sql index 84c1485..2a49f29 100644 --- a/backend/services/user-svc/migrations/001_init.sql +++ b/backend/services/user-svc/migrations/001_init.sql @@ -1,9 +1,12 @@ +-- 设置时区为东八区 +SET TIMEZONE = 'Asia/Shanghai'; + -- 创建 user_main 表 CREATE TABLE IF NOT EXISTS user_main ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), deleted BOOLEAN DEFAULT false, - create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP + create_time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + update_time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP ); -- 创建 user_login_account 表 @@ -12,8 +15,8 @@ CREATE TABLE IF NOT EXISTS user_login_account ( user_id UUID NOT NULL REFERENCES user_main(id), account VARCHAR(255) NOT NULL, deleted BOOLEAN DEFAULT false, - create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + create_time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + update_time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, UNIQUE(account) ); @@ -23,8 +26,8 @@ CREATE TABLE IF NOT EXISTS user_login_password ( user_id UUID NOT NULL REFERENCES user_main(id), password VARCHAR(255) NOT NULL, deleted BOOLEAN DEFAULT false, - create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP + create_time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + update_time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP ); -- 创建索引