mirror of
https://github.com/alexandrev/xslt-lab.git
synced 2026-09-13 08:43:16 +00:00
Fix: create the fiddle table with explicit DDL, not AutoMigrate
GORM's migrator crashes with "insufficient arguments" when it introspects this composite-primary-key table if the table already exists — which is exactly what happened on the first production rollout (my local end-to-end test had created the table moments earlier), crashlooping the backend until a rollout undo restored service. CREATE TABLE IF NOT EXISTS is idempotent and has no such moods. A failure now degrades to fiddles-off like every other storage failure, instead of taking /transform down with it. Verified against all three paths: existing table, fresh database, and restart over a self-created table. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KZntQUfw463NW4ftgSjWw5
This commit is contained in:
+16
-2
@@ -76,8 +76,22 @@ func registerFiddleRoutes(r *gin.Engine, db *gorm.DB) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := db.AutoMigrate(&Fiddle{}); err != nil {
|
||||
log.Fatalf("fiddle migrate: %v", err)
|
||||
// Explicit, idempotent DDL instead of GORM's AutoMigrate: the migrator
|
||||
// chokes on this composite primary key when the table already exists
|
||||
// ("insufficient arguments" on its introspection query), which crashlooped
|
||||
// the first deployment. CREATE IF NOT EXISTS has no such moods.
|
||||
if err := db.Exec(`CREATE TABLE IF NOT EXISTS fiddles (
|
||||
id varchar(12) NOT NULL,
|
||||
revision integer NOT NULL,
|
||||
payload text NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
PRIMARY KEY (id, revision)
|
||||
)`).Error; err != nil {
|
||||
// Same degradation contract as a failed connection: fiddles off,
|
||||
// transforms unaffected.
|
||||
log.Printf("fiddle table create failed, fiddle storage disabled: %v", err)
|
||||
registerFiddleRoutes(r, nil)
|
||||
return
|
||||
}
|
||||
|
||||
r.POST("/fiddle", func(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user