From b2ef18e7088516523ae1a733ded6af2291cb429d Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Thu, 7 Jul 2022 12:44:50 +0200 Subject: [PATCH] Namespace migrations --- federationapi/storage/postgres/storage.go | 5 ++--- federationapi/storage/sqlite3/storage.go | 5 ++--- keyserver/storage/postgres/cross_signing_sigs_table.go | 2 +- keyserver/storage/postgres/key_changes_table.go | 5 ++--- keyserver/storage/sqlite3/cross_signing_sigs_table.go | 2 +- keyserver/storage/sqlite3/key_changes_table.go | 5 ++--- roomserver/storage/postgres/membership_table.go | 2 +- roomserver/storage/postgres/storage.go | 5 ++--- roomserver/storage/sqlite3/membership_table.go | 2 +- roomserver/storage/sqlite3/storage.go | 5 ++--- syncapi/storage/postgres/receipt_table.go | 2 +- syncapi/storage/postgres/send_to_device_table.go | 2 +- syncapi/storage/sqlite3/receipt_table.go | 2 +- syncapi/storage/sqlite3/send_to_device_table.go | 2 +- userapi/storage/postgres/accounts_table.go | 4 ++-- userapi/storage/postgres/devices_table.go | 2 +- userapi/storage/sqlite3/accounts_table.go | 4 ++-- userapi/storage/sqlite3/devices_table.go | 2 +- 18 files changed, 26 insertions(+), 32 deletions(-) diff --git a/federationapi/storage/postgres/storage.go b/federationapi/storage/postgres/storage.go index cd8d45c6c..7c2883c1b 100644 --- a/federationapi/storage/postgres/storage.go +++ b/federationapi/storage/postgres/storage.go @@ -16,7 +16,6 @@ package postgres import ( - "context" "database/sql" "fmt" @@ -85,10 +84,10 @@ func NewDatabase(base *base.BaseDendrite, dbProperties *config.DatabaseOptions, } m := sqlutil.NewMigrator(d.db) m.AddMigrations(sqlutil.Migration{ - Version: "drop federationsender_rooms", + Version: "federationsender: drop federationsender_rooms", Up: deltas.UpRemoveRoomsTable, }) - err = m.Up(context.Background()) + err = m.Up(base.Context()) if err != nil { return nil, err } diff --git a/federationapi/storage/sqlite3/storage.go b/federationapi/storage/sqlite3/storage.go index d63e15efe..9594aaec6 100644 --- a/federationapi/storage/sqlite3/storage.go +++ b/federationapi/storage/sqlite3/storage.go @@ -16,7 +16,6 @@ package sqlite3 import ( - "context" "database/sql" "github.com/matrix-org/dendrite/federationapi/storage/shared" @@ -84,10 +83,10 @@ func NewDatabase(base *base.BaseDendrite, dbProperties *config.DatabaseOptions, } m := sqlutil.NewMigrator(d.db) m.AddMigrations(sqlutil.Migration{ - Version: "drop federationsender_rooms", + Version: "federationsender: drop federationsender_rooms", Up: deltas.UpRemoveRoomsTable, }) - err = m.Up(context.Background()) + err = m.Up(base.Context()) if err != nil { return nil, err } diff --git a/keyserver/storage/postgres/cross_signing_sigs_table.go b/keyserver/storage/postgres/cross_signing_sigs_table.go index 5ab1a46f5..8b2a865b9 100644 --- a/keyserver/storage/postgres/cross_signing_sigs_table.go +++ b/keyserver/storage/postgres/cross_signing_sigs_table.go @@ -70,7 +70,7 @@ func NewPostgresCrossSigningSigsTable(db *sql.DB) (tables.CrossSigningSigs, erro m := sqlutil.NewMigrator(db) m.AddMigrations(sqlutil.Migration{ - Version: "", + Version: "keyserver: cross signing signature indexes", Up: deltas.UpFixCrossSigningSignatureIndexes, }) if err = m.Up(context.Background()); err != nil { diff --git a/keyserver/storage/postgres/key_changes_table.go b/keyserver/storage/postgres/key_changes_table.go index 59946c663..6894d7b7c 100644 --- a/keyserver/storage/postgres/key_changes_table.go +++ b/keyserver/storage/postgres/key_changes_table.go @@ -64,12 +64,11 @@ func NewPostgresKeyChangesTable(db *sql.DB) (tables.KeyChanges, error) { // TODO: Remove when we are sure we are not having goose artefacts in the db // This forces an error, which indicates the migration is already applied, since the // column partition was removed from the table - var count int - err = db.QueryRow("SELECT partition FROM keyserver_key_changes LIMIT 1;").Scan(&count) + err = db.QueryRow("SELECT partition FROM keyserver_key_changes LIMIT 1;").Scan() if err == nil { m := sqlutil.NewMigrator(db) m.AddMigrations(sqlutil.Migration{ - Version: "refactor key changes", + Version: "keyserver: refactor key changes", Up: deltas.UpRefactorKeyChanges, }) return s, m.Up(context.Background()) diff --git a/keyserver/storage/sqlite3/cross_signing_sigs_table.go b/keyserver/storage/sqlite3/cross_signing_sigs_table.go index f129b9149..ea431151e 100644 --- a/keyserver/storage/sqlite3/cross_signing_sigs_table.go +++ b/keyserver/storage/sqlite3/cross_signing_sigs_table.go @@ -68,7 +68,7 @@ func NewSqliteCrossSigningSigsTable(db *sql.DB) (tables.CrossSigningSigs, error) } m := sqlutil.NewMigrator(db) m.AddMigrations(sqlutil.Migration{ - Version: "", + Version: "keyserver: cross signing signature indexes", Up: deltas.UpFixCrossSigningSignatureIndexes, }) if err = m.Up(context.Background()); err != nil { diff --git a/keyserver/storage/sqlite3/key_changes_table.go b/keyserver/storage/sqlite3/key_changes_table.go index 0e89174fa..1b27c3d05 100644 --- a/keyserver/storage/sqlite3/key_changes_table.go +++ b/keyserver/storage/sqlite3/key_changes_table.go @@ -61,12 +61,11 @@ func NewSqliteKeyChangesTable(db *sql.DB) (tables.KeyChanges, error) { // TODO: Remove when we are sure we are not having goose artefacts in the db // This forces an error, which indicates the migration is already applied, since the // column partition was removed from the table - var count int - err = db.QueryRow("SELECT partition FROM keyserver_key_changes LIMIT 1;").Scan(&count) + err = db.QueryRow("SELECT partition FROM keyserver_key_changes LIMIT 1;").Scan() if err == nil { m := sqlutil.NewMigrator(db) m.AddMigrations(sqlutil.Migration{ - Version: "refactor key changes", + Version: "keyserver: refactor key changes", Up: deltas.UpRefactorKeyChanges, }) return s, m.Up(context.Background()) diff --git a/roomserver/storage/postgres/membership_table.go b/roomserver/storage/postgres/membership_table.go index 4cb675613..98ac5b71a 100644 --- a/roomserver/storage/postgres/membership_table.go +++ b/roomserver/storage/postgres/membership_table.go @@ -168,7 +168,7 @@ func CreateMembershipTable(db *sql.DB) error { } m := sqlutil.NewMigrator(db) m.AddMigrations(sqlutil.Migration{ - Version: "add forgotten column", + Version: "roomserver: add forgotten column", Up: deltas.UpAddForgottenColumn, }) return m.Up(context.Background()) diff --git a/roomserver/storage/postgres/storage.go b/roomserver/storage/postgres/storage.go index 5331eb848..8ff098234 100644 --- a/roomserver/storage/postgres/storage.go +++ b/roomserver/storage/postgres/storage.go @@ -54,12 +54,11 @@ func Open(base *base.BaseDendrite, dbProperties *config.DatabaseOptions, cache c // TODO: Remove when we are sure we are not having goose artefacts in the db // This forces an error, which indicates the migration is already applied, since the // column event_nid was removed from the table - var count int - err = db.QueryRow("SELECT event_nid FROM roomserver_state_block LIMIT 1;").Scan(&count) + err = db.QueryRow("SELECT event_nid FROM roomserver_state_block LIMIT 1;").Scan() if err == nil { m := sqlutil.NewMigrator(db) m.AddMigrations(sqlutil.Migration{ - Version: "state blocks refactor", + Version: "roomserver: state blocks refactor", Up: deltas.UpStateBlocksRefactor, }) if err := m.Up(context.Background()); err != nil { diff --git a/roomserver/storage/sqlite3/membership_table.go b/roomserver/storage/sqlite3/membership_table.go index 7eebe4ee6..dc5a7b175 100644 --- a/roomserver/storage/sqlite3/membership_table.go +++ b/roomserver/storage/sqlite3/membership_table.go @@ -144,7 +144,7 @@ func CreateMembershipTable(db *sql.DB) error { } m := sqlutil.NewMigrator(db) m.AddMigrations(sqlutil.Migration{ - Version: "add forgotten column", + Version: "roomserver: add forgotten column", Up: deltas.UpAddForgottenColumn, }) return m.Up(context.Background()) diff --git a/roomserver/storage/sqlite3/storage.go b/roomserver/storage/sqlite3/storage.go index 0621f50f4..035c52f7f 100644 --- a/roomserver/storage/sqlite3/storage.go +++ b/roomserver/storage/sqlite3/storage.go @@ -63,12 +63,11 @@ func Open(base *base.BaseDendrite, dbProperties *config.DatabaseOptions, cache c // TODO: Remove when we are sure we are not having goose artefacts in the db // This forces an error, which indicates the migration is already applied, since the // column event_nid was removed from the table - var count int - err = db.QueryRow("SELECT event_nid FROM roomserver_state_block LIMIT 1;").Scan(&count) + err = db.QueryRow("SELECT event_nid FROM roomserver_state_block LIMIT 1;").Scan() if err == nil { m := sqlutil.NewMigrator(db) m.AddMigrations(sqlutil.Migration{ - Version: "state blocks refactor", + Version: "roomserver: state blocks refactor", Up: deltas.UpStateBlocksRefactor, }) if err := m.Up(context.Background()); err != nil { diff --git a/syncapi/storage/postgres/receipt_table.go b/syncapi/storage/postgres/receipt_table.go index d5795d6af..bbddaa939 100644 --- a/syncapi/storage/postgres/receipt_table.go +++ b/syncapi/storage/postgres/receipt_table.go @@ -76,7 +76,7 @@ func NewPostgresReceiptsTable(db *sql.DB) (tables.Receipts, error) { } m := sqlutil.NewMigrator(db) m.AddMigrations(sqlutil.Migration{ - Version: "fix sequences", + Version: "syncapi: fix sequences", Up: deltas.UpFixSequences, }) err = m.Up(context.Background()) diff --git a/syncapi/storage/postgres/send_to_device_table.go b/syncapi/storage/postgres/send_to_device_table.go index 3709e54fc..6a69f4d27 100644 --- a/syncapi/storage/postgres/send_to_device_table.go +++ b/syncapi/storage/postgres/send_to_device_table.go @@ -78,7 +78,7 @@ func NewPostgresSendToDeviceTable(db *sql.DB) (tables.SendToDevice, error) { } m := sqlutil.NewMigrator(db) m.AddMigrations(sqlutil.Migration{ - Version: "drop sent_by_token", + Version: "syncapi: drop sent_by_token", Up: deltas.UpRemoveSendToDeviceSentColumn, }) err = m.Up(context.Background()) diff --git a/syncapi/storage/sqlite3/receipt_table.go b/syncapi/storage/sqlite3/receipt_table.go index ee0c877e8..31adb005b 100644 --- a/syncapi/storage/sqlite3/receipt_table.go +++ b/syncapi/storage/sqlite3/receipt_table.go @@ -73,7 +73,7 @@ func NewSqliteReceiptsTable(db *sql.DB, streamID *StreamIDStatements) (tables.Re } m := sqlutil.NewMigrator(db) m.AddMigrations(sqlutil.Migration{ - Version: "fix sequences", + Version: "syncapi: fix sequences", Up: deltas.UpFixSequences, }) err = m.Up(context.Background()) diff --git a/syncapi/storage/sqlite3/send_to_device_table.go b/syncapi/storage/sqlite3/send_to_device_table.go index 1b2eb60e3..5e5b4759c 100644 --- a/syncapi/storage/sqlite3/send_to_device_table.go +++ b/syncapi/storage/sqlite3/send_to_device_table.go @@ -79,7 +79,7 @@ func NewSqliteSendToDeviceTable(db *sql.DB) (tables.SendToDevice, error) { } m := sqlutil.NewMigrator(db) m.AddMigrations(sqlutil.Migration{ - Version: "drop sent_by_token", + Version: "syncapi: drop sent_by_token", Up: deltas.UpRemoveSendToDeviceSentColumn, }) err = m.Up(context.Background()) diff --git a/userapi/storage/postgres/accounts_table.go b/userapi/storage/postgres/accounts_table.go index eb63d2f59..33fb6dd42 100644 --- a/userapi/storage/postgres/accounts_table.go +++ b/userapi/storage/postgres/accounts_table.go @@ -89,12 +89,12 @@ func NewPostgresAccountsTable(db *sql.DB, serverName gomatrixserverlib.ServerNam m := sqlutil.NewMigrator(db) m.AddMigrations([]sqlutil.Migration{ { - Version: "add is active", + Version: "userapi: add is active", Up: deltas.UpIsActive, Down: deltas.DownIsActive, }, { - Version: "add account type", + Version: "userapi: add account type", Up: deltas.UpAddAccountType, Down: deltas.DownAddAccountType, }, diff --git a/userapi/storage/postgres/devices_table.go b/userapi/storage/postgres/devices_table.go index 6decee30a..f65681aae 100644 --- a/userapi/storage/postgres/devices_table.go +++ b/userapi/storage/postgres/devices_table.go @@ -123,7 +123,7 @@ func NewPostgresDevicesTable(db *sql.DB, serverName gomatrixserverlib.ServerName } m := sqlutil.NewMigrator(db) m.AddMigrations(sqlutil.Migration{ - Version: "add last_seen_ts", + Version: "userapi: add last_seen_ts", Up: deltas.UpLastSeenTSIP, }) err = m.Up(context.Background()) diff --git a/userapi/storage/sqlite3/accounts_table.go b/userapi/storage/sqlite3/accounts_table.go index eded371fa..484e90056 100644 --- a/userapi/storage/sqlite3/accounts_table.go +++ b/userapi/storage/sqlite3/accounts_table.go @@ -91,12 +91,12 @@ func NewSQLiteAccountsTable(db *sql.DB, serverName gomatrixserverlib.ServerName) m := sqlutil.NewMigrator(db) m.AddMigrations([]sqlutil.Migration{ { - Version: "add is active", + Version: "userapi: add is active", Up: deltas.UpIsActive, Down: deltas.DownIsActive, }, { - Version: "add account type", + Version: "userapi: add account type", Up: deltas.UpAddAccountType, Down: deltas.DownAddAccountType, }, diff --git a/userapi/storage/sqlite3/devices_table.go b/userapi/storage/sqlite3/devices_table.go index fed785d25..27a7524d6 100644 --- a/userapi/storage/sqlite3/devices_table.go +++ b/userapi/storage/sqlite3/devices_table.go @@ -110,7 +110,7 @@ func NewSQLiteDevicesTable(db *sql.DB, serverName gomatrixserverlib.ServerName) } m := sqlutil.NewMigrator(db) m.AddMigrations(sqlutil.Migration{ - Version: "add last_seen_ts", + Version: "userapi: add last_seen_ts", Up: deltas.UpLastSeenTSIP, }) if err = m.Up(context.Background()); err != nil {