From f3d6bbbc4a9e8700f5351f1d1b7dc890e998049a Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 30 Oct 2021 23:31:49 +0300 Subject: [PATCH] Replace VARCHAR(255) with TEXT in Matrix state store --- .../2021-10-30-varchar-to-text-state-store.go | 22 +++++++++++++++++++ database/upgrades/upgrades.go | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 database/upgrades/2021-10-30-varchar-to-text-state-store.go diff --git a/database/upgrades/2021-10-30-varchar-to-text-state-store.go b/database/upgrades/2021-10-30-varchar-to-text-state-store.go new file mode 100644 index 0000000..114bf12 --- /dev/null +++ b/database/upgrades/2021-10-30-varchar-to-text-state-store.go @@ -0,0 +1,22 @@ +package upgrades + +import ( + "database/sql" +) + +func init() { + upgrades[29] = upgrade{"Replace VARCHAR(255) with TEXT in the Matrix state store", func(tx *sql.Tx, ctx context) error { + if ctx.dialect == SQLite { + // SQLite doesn't enforce varchar sizes anyway + return nil + } + return execMany(tx, + `ALTER TABLE mx_registrations ALTER COLUMN user_id TYPE TEXT`, + `ALTER TABLE mx_room_state ALTER COLUMN room_id TYPE TEXT`, + `ALTER TABLE mx_user_profile ALTER COLUMN room_id TYPE TEXT`, + `ALTER TABLE mx_user_profile ALTER COLUMN user_id TYPE TEXT`, + `ALTER TABLE mx_user_profile ALTER COLUMN membership TYPE TEXT`, + `ALTER TABLE mx_user_profile ALTER COLUMN avatar_url TYPE TEXT`, + ) + }} +} diff --git a/database/upgrades/upgrades.go b/database/upgrades/upgrades.go index c0d9260..089fcfc 100644 --- a/database/upgrades/upgrades.go +++ b/database/upgrades/upgrades.go @@ -39,7 +39,7 @@ type upgrade struct { fn upgradeFunc } -const NumberOfUpgrades = 29 +const NumberOfUpgrades = 30 var upgrades [NumberOfUpgrades]upgrade