Skip to content

Commit fda7f10

Browse files
GenerQAQclaude
andauthored
fix(api): use varchar(64) instead of char(64) in GORM models to prevent unnecessary ALTER TABLE on every pod startup (#461)
PostgreSQL stores char(64) as bpchar internally. GORM AutoMigrate compares the model type "char(64)" against the database type "bpchar" and sees a mismatch, issuing ALTER TABLE ... ALTER COLUMN TYPE char(64) on every pod restart. This ALTER acquires an ACCESS EXCLUSIVE lock, blocking all reads/writes and causing cascading connection pool exhaustion under load. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3ee9a19 commit fda7f10

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/server/api/go/internal/modules/model/asset_reference.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type AssetReference struct {
2323

2424
// SHA256 hash as unique identifier for content-based deduplication
2525
// Combined with ProjectID as composite unique key
26-
SHA256 string `gorm:"type:char(64);not null;uniqueIndex:idx_project_sha256,priority:2" json:"sha256"`
26+
SHA256 string `gorm:"type:varchar(64);not null;uniqueIndex:idx_project_sha256,priority:2" json:"sha256"`
2727

2828
// Canonical S3 key - the first uploaded location or preferred location
2929
// When same content is uploaded multiple times within a project, we keep only one copy

src/server/api/go/internal/modules/model/project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
type Project struct {
1111
ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();primaryKey" json:"id"`
12-
SecretKeyHMAC string `gorm:"type:char(64);uniqueIndex;not null" json:"-"`
12+
SecretKeyHMAC string `gorm:"type:varchar(64);uniqueIndex;not null" json:"-"`
1313
SecretKeyHashPHC string `gorm:"type:varchar(255);not null" json:"-"`
1414
Configs datatypes.JSONMap `gorm:"type:jsonb;index:idx_projects_configs,type:gin" swaggertype:"object" json:"configs"`
1515

0 commit comments

Comments
 (0)