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
This commit is contained in:
kolaente
2026-02-24 12:48:47 +01:00
parent 7c04d44e2e
commit b1534f1cc8

View File

@@ -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