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 ); -- 创建索引