refactor(server/db): 多库(2/4)— 时间等 DB 端计算退回 Go(可移植)

auth/admin/httpapi:把 UTC_TIMESTAMP(6) 等 DB 端取值改为 Go time.Now().UTC()
作为 ? 参数传入(两库精度一致、可测、天然跨方言)。仅这三个文件不涉及
upsert/锁,故独立成提交;其余域文件的同类改动与 dialect 改动同语句交错,合入(3/4)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-18 00:01:12 +08:00
parent f3471ae139
commit ece51d7e3d
3 changed files with 12 additions and 11 deletions
+6 -5
View File
@@ -66,10 +66,11 @@ func (s *SQLStore) CreateUserWithTrial(ctx context.Context, email, pwHash string
}
}()
now := time.Now().UTC()
res, err := tx.ExecContext(ctx,
`INSERT INTO users (uuid, email, pw_hash, dp_uuid, status, created_at)
VALUES (?, ?, ?, ?, 'active', UTC_TIMESTAMP(6))`,
userUUID, email, pwHash, dpUUID)
VALUES (?, ?, ?, ?, 'active', ?)`,
userUUID, email, pwHash, dpUUID, now)
if err != nil {
if isDuplicateKey(err) {
return nil, ErrEmailTaken
@@ -86,11 +87,11 @@ func (s *SQLStore) CreateUserWithTrial(ctx context.Context, email, pwHash string
if err := tx.QueryRowContext(ctx, `SELECT id FROM plans WHERE code='pro'`).Scan(&proID); err != nil {
return nil, fmt.Errorf("auth: lookup pro plan: %w", err)
}
expires := time.Now().UTC().AddDate(0, 0, trialDays)
expires := now.AddDate(0, 0, trialDays)
if _, err := tx.ExecContext(ctx,
`INSERT INTO subscriptions (user_id, plan_id, expires_at, source, created_at)
VALUES (?, ?, ?, 'trial', UTC_TIMESTAMP(6))`,
userID, proID, expires); err != nil {
VALUES (?, ?, ?, 'trial', ?)`,
userID, proID, expires, now); err != nil {
return nil, fmt.Errorf("auth: insert trial subscription: %w", err)
}