修复:为 user-svc 添加健康检查和启动顺序控制

This commit is contained in:
fish
2026-03-28 21:54:09 +08:00
parent 5ac0a52bb1
commit c5260bcae8
31 changed files with 1995 additions and 167 deletions

View File

@@ -2,10 +2,9 @@ package repository
import (
"database/sql"
"time"
"backend/services/user-svc/internal/domain"
"backend/shared/pkg/errors"
"user-svc/internal/domain"
"shared/pkg/errors"
"github.com/google/uuid"
"golang.org/x/crypto/bcrypt"
@@ -41,7 +40,11 @@ func (r *UserRepository) Register(req *domain.RegisterRequest) (*domain.Register
}
// 创建用户
userID := uuid.NewV7()
userID, err := uuid.NewV7()
if err != nil {
tx.Rollback()
return nil, errors.WrapError(err, "failed to generate user ID")
}
userQuery := "INSERT INTO user_main (id, deleted) VALUES ($1, $2)"
if _, err := tx.Exec(userQuery, userID, false); err != nil {
@@ -50,7 +53,11 @@ func (r *UserRepository) Register(req *domain.RegisterRequest) (*domain.Register
}
// 创建登录账号
accountID := uuid.NewV7()
accountID, err := uuid.NewV7()
if err != nil {
tx.Rollback()
return nil, errors.WrapError(err, "failed to generate account ID")
}
accountQuery := "INSERT INTO user_login_account (id, user_id, account, deleted) VALUES ($1, $2, $3, $4)"
if _, err := tx.Exec(accountQuery, accountID, userID, req.Account, false); err != nil {
tx.Rollback()
@@ -65,7 +72,11 @@ func (r *UserRepository) Register(req *domain.RegisterRequest) (*domain.Register
}
// 创建密码记录
passwordID := uuid.NewV7()
passwordID, err := uuid.NewV7()
if err != nil {
tx.Rollback()
return nil, errors.WrapError(err, "failed to generate password ID")
}
passwordQuery := "INSERT INTO user_login_password (id, user_id, password, deleted) VALUES ($1, $2, $3, $4)"
if _, err := tx.Exec(passwordQuery, passwordID, userID, string(hashedPassword), false); err != nil {
tx.Rollback()