package updates import ( "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" ) // addHandleToUsers adds users.handle, the unique @mention identity (D-15), // only when it is missing: an application whose users table already has the // column (added on PHP by chatchannels) keeps it and its data. The rollback // is a no-op for the same reason: the column may predate this plugin. var addHandleToUsers = []*gormigrate.Migration{ { ID: "202610160002_add_handle_to_users", Migrate: func(tx *gorm.DB) error { if err := tx.Exec(`ALTER TABLE users ADD COLUMN IF NOT EXISTS handle VARCHAR(255) NULL`).Error; err != nil { return err } return tx.Exec(`CREATE UNIQUE INDEX IF NOT EXISTS users_handle_unique ON users (handle)`).Error }, Rollback: func(*gorm.DB) error { // No-op: the shared users column may predate the plugin. return nil }, }, } func init() { Register(addHandleToUsers...) }