mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
bridgev2/legacymigrate: drop *_mxid_unique constraints before migration
This commit is contained in:
parent
cb4204ceb5
commit
d86913bd5c
1 changed files with 12 additions and 0 deletions
|
|
@ -26,6 +26,18 @@ import (
|
|||
|
||||
func (br *BridgeMain) LegacyMigrateWithAnotherUpgrader(renameTablesQuery, copyDataQuery string, newDBVersion int, otherTable dbutil.UpgradeTable, otherTableName string, otherNewVersion int) func(ctx context.Context) error {
|
||||
return func(ctx context.Context) error {
|
||||
// Unique constraints must have globally unique names on postgres, and renaming the table doesn't rename them,
|
||||
// so just drop the ones that may conflict with the new schema.
|
||||
if br.DB.Dialect == dbutil.Postgres {
|
||||
_, err := br.DB.Exec(ctx, "ALTER TABLE message DROP CONSTRAINT IF EXISTS message_mxid_unique")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to drop potentially conflicting constraint on message: %w", err)
|
||||
}
|
||||
_, err = br.DB.Exec(ctx, "ALTER TABLE reaction DROP CONSTRAINT IF EXISTS reaction_mxid_unique")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to drop potentially conflicting constraint on reaction: %w", err)
|
||||
}
|
||||
}
|
||||
err := dbutil.DangerousInternalUpgradeVersionTable(ctx, br.DB)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue