mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-10-31 22:40:01 +00:00
[bugfix] In Postgres, drop shortcodedomain constraint before creating new emoji table (#1528)
This commit is contained in:
parent
a684fc4628
commit
a0068e8915
1 changed files with 11 additions and 1 deletions
|
@ -24,11 +24,21 @@
|
|||
|
||||
gtsmodel "github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20211113114307_init"
|
||||
"github.com/uptrace/bun"
|
||||
"github.com/uptrace/bun/dialect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
up := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
// SQLite doesn't mind creating multiple constraints with the same name,
|
||||
// but Postgres balks at it, so remove the constraint before we go editing
|
||||
// the emoji tables.
|
||||
if tx.Dialect().Name() == dialect.PG {
|
||||
if _, err := tx.ExecContext(ctx, "ALTER TABLE ? DROP CONSTRAINT ?", bun.Ident("emojis"), bun.Safe("shortcodedomain")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// create the new emojis table
|
||||
if _, err := tx.
|
||||
NewCreateTable().
|
||||
|
@ -63,7 +73,7 @@ func init() {
|
|||
}
|
||||
|
||||
// rename the new table to the same name as the old table was
|
||||
if _, err := tx.ExecContext(ctx, "ALTER TABLE new_emojis RENAME TO emojis;"); err != nil {
|
||||
if _, err := tx.ExecContext(ctx, "ALTER TABLE ? RENAME TO ?", bun.Ident("new_emojis"), bun.Ident("emojis")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue