legacymigrate: add create_event column to mx_room_state if necessary

This commit is contained in:
Tulir Asokan
2026-04-04 18:30:17 +03:00
parent c3216f1e4d
commit 8350230693
4 changed files with 34 additions and 8 deletions
+4 -4
View File
@@ -1,10 +1,10 @@
# v26.04 (unreleased)
* Rewrote bridge in Go using bridgev2 architecture.
* To migrate the bridge, simply upgrade in-place. The database and config
will be migrated automatically, although some parts of the config aren't
migrated (e.g. log config, permission types specific to the legacy bridge).
Taking backups beforehand is always recommended.
* To migrate the bridge, simply upgrade in-place from v0.15.3 or later. The
database and config will be migrated automatically, although some parts of
the config aren't migrated (e.g. log config, permission types specific to
the legacy bridge). Taking backups beforehand is always recommended.
* It is recommended to check the config file after upgrading. If you have
prevented the bridge from writing to the config, you should update it
manually.
+27 -1
View File
@@ -17,13 +17,17 @@
package main
import (
"context"
_ "embed"
"fmt"
"github.com/rs/zerolog"
up "go.mau.fi/util/configupgrade"
"go.mau.fi/util/dbutil"
"maunium.net/go/mautrix/bridgev2/bridgeconfig"
)
const legacyMigrateRenameTables = `
const legacyMigrateRenameTablesQuery = `
ALTER TABLE backfill_queue RENAME TO backfill_queue_old;
ALTER TABLE bot_chat RENAME TO bot_chat_old;
ALTER TABLE contact RENAME TO contact_old;
@@ -42,6 +46,28 @@ ALTER TABLE user_portal RENAME TO user_portal_old;
DROP INDEX IF EXISTS telegram_file_mxc_idx;
`
func legacyMigrateRenameTables(ctx context.Context, db *dbutil.Database) error {
_, err := db.Exec(ctx, legacyMigrateRenameTablesQuery)
if err != nil {
return err
}
var mxVersion int
err = db.QueryRow(ctx, "SELECT version FROM mx_version").Scan(&mxVersion)
if err != nil {
return fmt.Errorf("failed to get mx_version: %w", err)
} else if mxVersion == 3 {
zerolog.Ctx(ctx).Debug().Msg("mx_version is 3, adding create_event column before running actual migration")
_, err = db.Exec(ctx, `
ALTER TABLE mx_room_state ADD COLUMN create_event TEXT;
UPDATE mx_version SET version=4;
`)
if err != nil {
return fmt.Errorf("failed to add create_event column to mx_room_state: %w", err)
}
}
return nil
}
//go:embed legacymigrate.sql
var legacyMigrateCopyData string
+1 -1
View File
@@ -42,7 +42,7 @@ require (
golang.org/x/sync v0.20.0
golang.org/x/tools v0.43.0
gopkg.in/yaml.v3 v3.0.1
maunium.net/go/mautrix v0.26.5-0.20260403090948-59e52f7acd76
maunium.net/go/mautrix v0.26.5-0.20260404152556-105984c2b676
rsc.io/qr v0.2.0
)
+2 -2
View File
@@ -236,7 +236,7 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
maunium.net/go/mautrix v0.26.5-0.20260403090948-59e52f7acd76 h1:uQeQD1mCHGamkmYhuPltZOEdYI8ag1gDQJ/adCLk6LM=
maunium.net/go/mautrix v0.26.5-0.20260403090948-59e52f7acd76/go.mod h1:RUSMBPky3jhXB7Ux+AptfkEvFlJ4ajZKCYiXI8YzxVE=
maunium.net/go/mautrix v0.26.5-0.20260404152556-105984c2b676 h1:1hc9asoUumM44g4jy43AomCovR4JFlMRU6ngrx/DJu4=
maunium.net/go/mautrix v0.26.5-0.20260404152556-105984c2b676/go.mod h1:RUSMBPky3jhXB7Ux+AptfkEvFlJ4ajZKCYiXI8YzxVE=
rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY=
rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs=