Skip to content

Commit

Permalink
v2: copy relay user ID in legacy migration
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jun 29, 2024
1 parent 10eefaf commit a3e20a8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
43 changes: 22 additions & 21 deletions cmd/mautrix-signal-v2/legacymigrate.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
INSERT INTO "user" (bridge_id, mxid, management_room, access_token)
SELECT '', mxid, management_room, NULL
FROM user_old;

INSERT INTO user_login (bridge_id, user_mxid, id, space_room, metadata)
SELECT
'',
mxid,
cast(uuid AS TEXT),
space_room,
CAST(
'{"phone":"' || phone || '","remote_name":"' || phone || '"}'
-- only: postgres
AS jsonb
-- only: sqlite (line commented)
-- AS text
)
FROM user_old WHERE uuid IS NOT NULL AND phone IS NOT NULL;

INSERT INTO portal (
bridge_id, id, receiver, mxid, parent_id, parent_receiver,
bridge_id, id, receiver, mxid, parent_id, parent_receiver, relay_bridge_id, relay_login_id,
name, topic, avatar_id, avatar_hash, avatar_mxc,
name_set, avatar_set, topic_set, in_space, metadata
)
Expand All @@ -13,6 +32,8 @@ SELECT
mxid,
NULL, -- parent_id
'', -- parent_receiver
CASE WHEN portal_old.relay_user_id<>'' THEN '' END, -- relay_bridge_id
CASE WHEN portal_old.relay_user_id<>'' THEN portal_old.relay_user_id END, -- relay_login_id
name,
topic,
CASE
Expand All @@ -37,7 +58,6 @@ SELECT
-- only: sqlite (line commented)
-- AS text
) -- metadata
-- TODO migrate relay user id
FROM portal_old;

INSERT INTO ghost (
Expand Down Expand Up @@ -126,25 +146,6 @@ SELECT
) -- metadata
FROM reaction_old;

INSERT INTO "user" (bridge_id, mxid, management_room, access_token)
SELECT '', mxid, management_room, NULL
FROM user_old;

INSERT INTO user_login (bridge_id, user_mxid, id, space_room, metadata)
SELECT
'',
mxid,
cast(uuid AS TEXT),
space_room,
CAST(
'{"phone":"' || phone || '","remote_name":"' || phone || '"}'
-- only: postgres
AS jsonb
-- only: sqlite (line commented)
-- AS text
)
FROM user_old WHERE uuid IS NOT NULL AND phone IS NOT NULL;

INSERT INTO user_portal (
bridge_id, user_mxid, login_id, portal_id, portal_receiver, in_space, preferred, last_read
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mautrix-signal-v2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func main() {
20,
"v0.5.1",
"v0.7.0",
m.LegacyMigrateSimple(legacyMigrateRenameTables, legacyMigrateCopyData, 2),
m.LegacyMigrateSimple(legacyMigrateRenameTables, legacyMigrateCopyData, 4),
true,
)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
golang.org/x/net v0.26.0
google.golang.org/protobuf v1.34.2
maunium.net/go/mautrix v0.19.0-beta.1.0.20240628200158-86ac5c340b35
maunium.net/go/mautrix v0.19.0-beta.1.0.20240629130130-2b668652aba5
nhooyr.io/websocket v1.8.11
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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.19.0-beta.1.0.20240628200158-86ac5c340b35 h1:ghI1MLQc4JS0ov31rpjuHrCwqVP7b+4wZfwXsD/5i0k=
maunium.net/go/mautrix v0.19.0-beta.1.0.20240628200158-86ac5c340b35/go.mod h1:eu/C1dTewrW7yiFNiCKGm4zuWJANyt7zPjaY5g3f3r4=
maunium.net/go/mautrix v0.19.0-beta.1.0.20240629130130-2b668652aba5 h1:OtQxTxVhivW4U6VC0UhGZINemqePLigA70ot2p+zp6I=
maunium.net/go/mautrix v0.19.0-beta.1.0.20240629130130-2b668652aba5/go.mod h1:eu/C1dTewrW7yiFNiCKGm4zuWJANyt7zPjaY5g3f3r4=
nhooyr.io/websocket v1.8.11 h1:f/qXNc2/3DpoSZkHt1DQu6rj4zGC8JmkkLkWss0MgN0=
nhooyr.io/websocket v1.8.11/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=

0 comments on commit a3e20a8

Please sign in to comment.