diff --git a/cmd/mautrix-telegram/legacymigrate.sql b/cmd/mautrix-telegram/legacymigrate.sql index 45b48e33..0b46562d 100644 --- a/cmd/mautrix-telegram/legacymigrate.sql +++ b/cmd/mautrix-telegram/legacymigrate.sql @@ -262,6 +262,9 @@ CREATE TABLE new_mx_room_state ( INSERT INTO new_mx_room_state (room_id, encryption, power_levels, create_event, members_fetched) SELECT room_id, encryption, power_levels, create_event, COALESCE(has_full_member_list, false) FROM mx_room_state; + +DROP TABLE mx_room_state; +ALTER TABLE new_mx_room_state RENAME TO mx_room_state; -- end only sqlite ALTER TABLE mx_user_profile ADD COLUMN name_skeleton bytea; diff --git a/pkg/connector/store/upgrades/09-legacy-migrate-fix.go b/pkg/connector/store/upgrades/09-legacy-migrate-fix.go new file mode 100644 index 00000000..b62710df --- /dev/null +++ b/pkg/connector/store/upgrades/09-legacy-migrate-fix.go @@ -0,0 +1,40 @@ +// mautrix-telegram - A Matrix-Telegram puppeting bridge. +// Copyright (C) 2026 Tulir Asokan +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package upgrades + +import ( + "context" + + "go.mau.fi/util/dbutil" +) + +func init() { + Table.Register(-1, 9, 2, "Fix bug in legacy migration", dbutil.TxnModeOn, func(ctx context.Context, db *dbutil.Database) error { + if db.Dialect != dbutil.SQLite { + return nil + } + exists, err := db.TableExists(ctx, "new_mx_room_state") + if !exists || err != nil { + return err + } + _, err = db.Exec(ctx, ` + DROP TABLE mx_room_state; + ALTER TABLE new_mx_room_state RENAME TO mx_room_state; + `) + return err + }) +}