Skip to content

Commit 1eafae5

Browse files
authored
legacymigrate: fix postgres compatibility (#21)
1 parent e4a58db commit 1eafae5

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

cmd/mautrix-linkedin/legacymigrate.sql

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ SELECT
2828
false, -- avatar_set (need to set it on the new case-insensitive ghost mxid)
2929
false, -- contact_info_set (need to set it on the new case-insensitive ghost mxid)
3030
false, -- is_bot
31-
'["linkedin:' || li_member_urn || '"]', -- identifiers
31+
-- only: postgres
32+
jsonb_build_array
33+
-- only: sqlite (line commented)
34+
-- json_array
35+
(
36+
'linkedin:' || li_member_urn
37+
), -- identifiers
3238
'{}' -- metadata
3339
FROM puppet_old;
3440

@@ -39,7 +45,7 @@ INSERT INTO portal (
3945
SELECT
4046
'', -- bridge_id
4147
'urn:li:msg_conversation:(urn:li:fsd_profile:' || li_receiver_urn || ',' || li_thread_urn || ')', -- id
42-
CASE WHEN li_is_group_chat=0 THEN li_receiver_urn ELSE '' END, -- receiver
48+
CASE WHEN NOT li_is_group_chat THEN li_receiver_urn ELSE '' END, -- receiver
4349
mxid, -- mxid
4450
CASE WHEN NOT li_is_group_chat THEN li_other_user_urn END, -- other_user_id
4551
COALESCE(name, ''), -- name
@@ -76,14 +82,19 @@ SELECT
7682
(
7783
'urn:li:msg_message:(urn:li:fsd_profile:' ||
7884
li_receiver_urn ||
79-
SUBSTR(li_message_urn, INSTR(li_message_urn, ',')) ||
85+
SUBSTR(li_message_urn,
86+
-- only: postgres
87+
POSITION(',' IN li_message_urn)
88+
-- only: sqlite (line commented)
89+
-- INSTR(li_message_urn, ',')
90+
) ||
8091
')'
8192
), -- id
8293
'', -- part_id
8394
mxid,
8495
'urn:li:msg_conversation:(urn:li:fsd_profile:' || li_receiver_urn || ',' || li_thread_urn || ')', -- room_id
8596
(
86-
SELECT CASE WHEN li_is_group_chat=0 THEN li_receiver_urn ELSE '' END
97+
SELECT CASE WHEN NOT li_is_group_chat THEN li_receiver_urn ELSE '' END
8798
FROM portal_old
8899
WHERE li_thread_urn=message_old.li_thread_urn
89100
), -- room_receiver
@@ -104,17 +115,32 @@ SELECT
104115
(
105116
'urn:li:msg_message:(urn:li:fsd_profile:' ||
106117
li_receiver_urn ||
107-
SUBSTR(li_message_urn, INSTR(li_message_urn, ',')) ||
118+
SUBSTR(li_message_urn,
119+
-- only: postgres
120+
POSITION(',' IN li_message_urn)
121+
-- only: sqlite (line commented)
122+
-- INSTR(li_message_urn, ',')
123+
) ||
108124
')'
109125
), -- message_id
110126
'', -- message_part_id
111127
li_sender_urn, -- sender_id
112128
reaction, -- emoji_id
113-
'urn:li:msg_conversation:(urn:li:fsd_profile:' || li_receiver_urn || ',' || SUBSTR(li_message_urn, 0, INSTR(li_message_urn, ',')) || ')', -- room_id
129+
'urn:li:msg_conversation:(urn:li:fsd_profile:' || li_receiver_urn || ',' || SUBSTR(li_message_urn, 0,
130+
-- only: postgres
131+
POSITION(',' IN li_message_urn)
132+
-- only: sqlite (line commented)
133+
-- INSTR(li_message_urn, ',')
134+
) || ')', -- room_id
114135
(
115-
SELECT CASE WHEN li_is_group_chat=0 THEN li_receiver_urn ELSE '' END
136+
SELECT CASE WHEN NOT li_is_group_chat THEN li_receiver_urn ELSE '' END
116137
FROM portal_old
117-
WHERE li_thread_urn=SUBSTR(li_message_urn, 0, INSTR(li_message_urn, ','))
138+
WHERE li_thread_urn=SUBSTR(li_message_urn, 0,
139+
-- only: postgres
140+
POSITION(',' IN li_message_urn)
141+
-- only: sqlite (line commented)
142+
-- INSTR(li_message_urn, ',')
143+
)
118144
), -- room_receiver
119145
mxid,
120146
(
@@ -139,7 +165,7 @@ CREATE TABLE IF NOT EXISTS database_owner (
139165
key INTEGER PRIMARY KEY DEFAULT 0,
140166
owner TEXT NOT NULL
141167
);
142-
INSERT INTO database_owner (key, owner) VALUES (0, "megabridge/mautrix-linkedin");
168+
INSERT INTO database_owner (key, owner) VALUES (0, 'megabridge/mautrix-linkedin');
143169

144170
-- Python -> Go mx_ table migration
145171
ALTER TABLE mx_room_state DROP COLUMN is_encrypted;

0 commit comments

Comments
 (0)