mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 18:43:10 -06:00
Add migration to rename dupe index
This commit is contained in:
parent
1af5c7e69a
commit
fc74946246
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright 2023 The Matrix.org Foundation C.I.C.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package deltas
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func UpRenameOutputRoomEventsIndex(ctx context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.ExecContext(ctx, `ALTER TABLE syncapi_output_room_events RENAME CONSTRAINT syncapi_event_id_idx TO syncapi_output_room_event_id_idx;`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to execute upgrade: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/lib/pq"
|
||||
|
|
@ -223,12 +224,30 @@ func NewPostgresEventsTable(db *sql.DB) (tables.Events, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
migrationName := "syncapi: rename dupe index (output_room_events)"
|
||||
|
||||
var cName string
|
||||
err = db.QueryRowContext(context.Background(), "select constraint_name from information_schema.table_constraints where table_name = 'syncapi_output_room_events' AND constraint_name = 'syncapi_event_id_idx'").Scan(&cName)
|
||||
switch err {
|
||||
case sql.ErrNoRows: // migration was already executed, as the index was renamed
|
||||
if err = sqlutil.InsertMigration(context.Background(), db, migrationName); err != nil {
|
||||
return nil, fmt.Errorf("unable to manually insert migration '%s': %w", migrationName, err)
|
||||
}
|
||||
case nil:
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m := sqlutil.NewMigrator(db)
|
||||
m.AddMigrations(
|
||||
sqlutil.Migration{
|
||||
Version: "syncapi: add history visibility column (output_room_events)",
|
||||
Up: deltas.UpAddHistoryVisibilityColumnOutputRoomEvents,
|
||||
},
|
||||
sqlutil.Migration{
|
||||
Version: migrationName,
|
||||
Up: deltas.UpRenameOutputRoomEventsIndex,
|
||||
},
|
||||
)
|
||||
err = m.Up(context.Background())
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue