mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-03 04:43:01 +00:00
fix: use GORM v2 row locking for subscription resets (#6057)
* fix: use GORM v2 row locking for subscription resets * docs: codify GORM row locking rules
This commit is contained in:
@@ -80,6 +80,7 @@ Do NOT directly import or call `encoding/json` in business code. `json.RawMessag
|
||||
|
||||
- Prefer GORM methods (`Create`, `Find`, `Where`, `Updates`, etc.) over raw SQL.
|
||||
- Let GORM handle primary key generation; do not use `AUTO_INCREMENT` or `SERIAL` directly.
|
||||
- Standard `SELECT ... FOR UPDATE` row locks built with GORM query methods in `model/` MUST use `lockForUpdate(tx)`. Do not use the legacy GORM v1 pattern `tx.Set("gorm:query_option", "FOR UPDATE")`, because GORM v2 silently ignores it and no lock is acquired. Do not duplicate `clause.Locking{Strength: "UPDATE"}` at call sites; the shared helper emits `FOR UPDATE` for MySQL/PostgreSQL and skips it for SQLite, where the syntax is unsupported. Dialect-specific locking with different semantics (for example, a MySQL next-key/gap lock) may use raw SQL only behind explicit database-type branches with valid fallbacks for every supported database.
|
||||
- When raw SQL is unavoidable, account for dialect differences:
|
||||
- PostgreSQL uses `"column"` quoting, while MySQL/SQLite use `` `column` ``.
|
||||
- Use `commonGroupCol`, `commonKeyCol` from `model/main.go` for reserved-word columns like `group` and `key`.
|
||||
|
||||
Reference in New Issue
Block a user