From b1534f1cc827cd213d1f36372e010abe7e4ca886 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 24 Feb 2026 12:48:47 +0100 Subject: [PATCH] fix: replace tx.Sync() with explicit ALTER TABLE in webhooks migration tx.Sync() fails on PostgreSQL because it tries to reconcile primary key constraints/indexes, causing index-drop errors. Use explicit ALTER TABLE ADD COLUMN with existence checks instead. Fixes #2215 --- pkg/migration/20260123000717.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pkg/migration/20260123000717.go b/pkg/migration/20260123000717.go index b4ecaefab..6ed67f035 100644 --- a/pkg/migration/20260123000717.go +++ b/pkg/migration/20260123000717.go @@ -21,21 +21,27 @@ import ( "xorm.io/xorm" ) -type webhooks20260123000717 struct { - BasicAuthUser string `xorm:"null" json:"basicauthuser"` - BasicAuthPassword string `xorm:"null" json:"basicauthpassword"` -} - -func (webhooks20260123000717) TableName() string { - return "webhooks" -} - func init() { migrations = append(migrations, &xormigrate.Migration{ ID: "20260123000717", Description: "Add basic auth to webhooks", Migrate: func(tx *xorm.Engine) error { - return tx.Sync(webhooks20260123000717{}) + columns := []string{"basic_auth_user", "basic_auth_password"} + for _, col := range columns { + exists, err := columnExists(tx, "webhooks", col) + if err != nil { + return err + } + if exists { + continue + } + + if _, err = tx.Exec("ALTER TABLE webhooks ADD COLUMN " + col + " TEXT NULL"); err != nil { + return err + } + } + + return nil }, Rollback: func(tx *xorm.Engine) error { return nil