fix shared database account sequence initialization

This commit is contained in:
richjohnrambo
2026-09-22 18:00:18 +08:00
parent e4416da04a
commit 8e04f00e96
8 changed files with 158 additions and 13 deletions
+5
View File
@@ -446,6 +446,11 @@ func nextTenantUserAccountNo(ctx context.Context, tx *sqlx.Tx, tenantID t.Tenant
if columns == 0 {
return 0, false, nil
}
if _, err := tx.ExecContext(ctx, `INSERT IGNORE INTO im_user_account_sequences(tenant_id,id,next_value)
SELECT ?,1,GREATEST(COALESCE(MAX(account_no),999),999) FROM im_users WHERE tenant_id=? AND account_no>0`,
tenantID, tenantID); err != nil {
return 0, true, err
}
if _, err := tx.ExecContext(ctx, `UPDATE im_user_account_sequences
SET next_value=GREATEST(next_value,(SELECT GREATEST(COALESCE(MAX(account_no),999),999) FROM im_users WHERE tenant_id=? AND account_no>0))
WHERE tenant_id=? AND id=1`, tenantID, tenantID); err != nil {