SQL is hard

This commit is contained in:
Till Faelligen 2023-05-17 14:08:49 +02:00
parent 4de150a2e9
commit 09a571c8e3
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E

View file

@ -38,12 +38,15 @@ func UpDropEventReferenceSHAEvents(ctx context.Context, tx *sql.Tx) error {
}
func UpDropEventReferenceSHAPrevEvents(ctx context.Context, tx *sql.Tx) error {
_, err := tx.ExecContext(ctx, `ALTER TABLE roomserver_previous_events DROP COLUMN IF EXISTS previous_reference_sha256;`)
_, err := tx.ExecContext(ctx, "ALTER TABLE roomserver_previous_events DROP CONSTRAINT roomserver_previous_event_id_unique;")
if err != nil {
return fmt.Errorf("failed to execute upgrade: %w", err)
}
// re-add constraint, as it seems to be dropped as well
_, err = tx.ExecContext(ctx, `CREATE UNIQUE INDEX IF NOT EXISTS roomserver_previous_event_id_unique ON roomserver_previous_events (previous_event_id);`)
_, err = tx.ExecContext(ctx, `ALTER TABLE roomserver_previous_events DROP COLUMN IF EXISTS previous_reference_sha256;`)
if err != nil {
return fmt.Errorf("failed to execute upgrade: %w", err)
}
_, err = tx.ExecContext(ctx, `ALTER TABLE roomserver_previous_events ADD CONSTRAINT roomserver_previous_event_id_unique UNIQUE (previous_event_id);`)
if err != nil {
return fmt.Errorf("failed to execute upgrade: %w", err)
}