diff options
| author | 2023-02-18 17:54:51 +0100 | |
|---|---|---|
| committer | 2023-02-18 17:54:51 +0100 | |
| commit | a0068e89158b67dfb790c77e875400a6772d1890 (patch) | |
| tree | 346ebcf3b412a8299e0699d6920274e672844d1e /internal/db | |
| parent | [chore] transport improvements (#1524) (diff) | |
| download | gotosocial-a0068e89158b67dfb790c77e875400a6772d1890.tar.xz | |
[bugfix] In Postgres, drop shortcodedomain constraint before creating new emoji table (#1528)
Diffstat (limited to 'internal/db')
| -rw-r--r-- | internal/db/bundb/migrations/20220905150505_custom_emoji_updates.go | 12 | 
1 files changed, 11 insertions, 1 deletions
| diff --git a/internal/db/bundb/migrations/20220905150505_custom_emoji_updates.go b/internal/db/bundb/migrations/20220905150505_custom_emoji_updates.go index 944b7c3b4..1b915c253 100644 --- a/internal/db/bundb/migrations/20220905150505_custom_emoji_updates.go +++ b/internal/db/bundb/migrations/20220905150505_custom_emoji_updates.go @@ -24,11 +24,21 @@ import (  	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  			} | 
