forked from SenCodeMaker/whatsapp-database-merger
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Updates.sql
133 lines (131 loc) · 14.1 KB
/
Updates.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
--
-- This script update the data in the newest db to make it insertable in the oldest respecting the ids
-- exec it connect to the newest
--
ATTACH DATABASE '/path/old/msgstore_older.db' AS oldest;
update user_device set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="user_device")) where _id > 0;
update user_device set _id = -_id where _id < 0;
update group_participant_user set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="group_participant_user")) where _id > 0;
update group_participant_user set _id = -_id where _id < 0;
update group_participant_device set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="group_participant_device")) where _id > 0;
update group_participant_device set _id = -_id where _id < 0;
update call_log_participant_v2 set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="call_log_participant_v2")) where _id > 0;
update call_log_participant_v2 set _id = -_id where _id < 0;
update call_log set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="call_log")) where _id > 0;
update call_log set _id = -_id where _id < 0;
update receipts set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="receipts")) where _id > 0;
update receipts set _id = -_id where _id < 0;
update receipt_orphaned set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="receipt_orphaned")) where _id > 0;
update receipt_orphaned set _id = -_id where _id < 0;
update receipt_orphaned set receipt_device_jid_row_id = -(receipt_device_jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="receipt_device")) where receipt_device_jid_row_id > 0;
update receipt_orphaned set receipt_device_jid_row_id = -receipt_device_jid_row_id where receipt_device_jid_row_id < 0;
update receipt_device set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="receipt_device")) where _id > 0;
update receipt_device set _id = -_id where _id < 0;
update receipt_user set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="receipt_user")) where _id > 0;
update receipt_user set _id = -_id where _id < 0;
update user_device set device_jid_row_id = -(device_jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where device_jid_row_id > 0;
update user_device set device_jid_row_id = -device_jid_row_id where device_jid_row_id < 0;
update group_participant_device set device_jid_row_id = -(device_jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where device_jid_row_id > 0;
update group_participant_device set device_jid_row_id = -device_jid_row_id where device_jid_row_id < 0;
---------------------------------------------------------------------------------------------
update missed_call_logs set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="missed_call_logs")) where _id > 0;
update missed_call_logs set _id = -_id where _id < 0;
update missed_call_log_participant set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="missed_call_log_participant")) where _id > 0;
update missed_call_log_participant set _id = -_id where _id < 0;
update media_refs set _id = -_id where _id < 0;
update missed_call_log_participant set call_logs_row_id = -(call_logs_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="call_log")) where call_logs_row_id > 0;
update missed_call_log_participant set call_logs_row_id = -call_logs_row_id where call_logs_row_id < 0;
--------------------------------------------------------
update media_refs set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="media_refs")) where _id > 0;
update media_refs set _id = -_id where _id < 0;
update chat set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="chat")) where _id > 0;
update chat set _id = -_id where _id < 0;
update message_media set chat_row_id = -(chat_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="chat")) where chat_row_id > 0;
update message_media set chat_row_id = -chat_row_id where chat_row_id < 0;
update receipt_orphaned set chat_row_id = -(chat_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="chat")) where chat_row_id > 0;
update receipt_orphaned set chat_row_id = -chat_row_id where chat_row_id < 0;
------------------------------------------------------------------------------------------
update jid set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where _id > 0;
update jid set _id = -_id where _id < 0;
update call_log set jid_row_id = -(jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where jid_row_id > 0;
update call_log set jid_row_id = -jid_row_id where jid_row_id < 0;
update call_log set call_creator_device_jid_row_id = -(call_creator_device_jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where call_creator_device_jid_row_id > 0;
update call_log set call_creator_device_jid_row_id = -call_creator_device_jid_row_id where call_creator_device_jid_row_id < 0;
update missed_call_logs set group_jid_row_id = -(group_jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where group_jid_row_id > 0;
update missed_call_logs set group_jid_row_id = -group_jid_row_id where group_jid_row_id < 0;
update call_log_participant_v2 set call_log_row_id = -(call_log_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="call_log_participant_v2")) where call_log_row_id > 0;
update call_log_participant_v2 set call_log_row_id = -call_log_row_id where call_log_row_id < 0;
update call_log_participant_v2 set jid_row_id = -(jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where jid_row_id > 0;
update call_log_participant_v2 set jid_row_id = -jid_row_id where jid_row_id < 0;
update chat set jid_row_id = -(jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where jid_row_id > 0;
update chat set jid_row_id = -jid_row_id where jid_row_id < 0;
update chat set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="chat")) where _id > 0;
update chat set _id = -_id where _id < 0;
update group_notification_version set group_jid_row_id = -(group_jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where group_jid_row_id > 0;
update group_notification_version set group_jid_row_id = -group_jid_row_id where group_jid_row_id < 0;
update group_participant_user set user_jid_row_id = -(user_jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where user_jid_row_id > 0;
update group_participant_user set user_jid_row_id = -user_jid_row_id where user_jid_row_id < 0;
update group_participant_user set group_jid_row_id = -(group_jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where group_jid_row_id > 0;
update group_participant_user set group_jid_row_id = -group_jid_row_id where group_jid_row_id < 0;
update receipt_user set receipt_user_jid_row_id = -(receipt_user_jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where receipt_user_jid_row_id > 0;
update receipt_user set receipt_user_jid_row_id = -receipt_user_jid_row_id where receipt_user_jid_row_id < 0;
update user_device set user_jid_row_id = -(user_jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where user_jid_row_id > 0;
update user_device set user_jid_row_id = -user_jid_row_id where user_jid_row_id < 0;
update user_device_info set user_jid_row_id = -(user_jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where user_jid_row_id > 0;
update user_device_info set user_jid_row_id = -user_jid_row_id where user_jid_row_id < 0;
update receipt_orphaned set receipt_recipient_jid_row_id = -(receipt_recipient_jid_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="jid")) where receipt_recipient_jid_row_id > 0;
update receipt_orphaned set receipt_recipient_jid_row_id = -receipt_recipient_jid_row_id where receipt_recipient_jid_row_id < 0;
---------------------------------------------------------------------------------------
update message set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where _id > 0;
update message set _id = -_id where _id < 0;
update message set sort_id = -(sort_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where _id > 0;
update message set sort_id = -sort_id where _id < 0;
update audio_data set message_row_id = -(message_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where message_row_id > 0;
update audio_data set message_row_id = -message_row_id where message_row_id < 0;
update message_ftsv2_content set docid = -(docid + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where docid > 0;
update message_ftsv2_content set docid = -docid where docid < 0;
update message_ftsv2_docsize set docid = -(docid + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where docid > 0;
update message_ftsv2_docsize set docid = -docid where docid < 0;
update message_forwarded set message_row_id = -(message_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where message_row_id > 0;
update message_forwarded set message_row_id = -message_row_id where message_row_id < 0;
update message_streaming_sidecar set message_row_id = -(message_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where message_row_id > 0;
update message_streaming_sidecar set message_row_id = -message_row_id where message_row_id < 0;
update message_media set message_row_id = -(message_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where message_row_id > 0;
update message_media set message_row_id = -message_row_id where message_row_id < 0;
update message_view_once_media set message_row_id = -(message_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where message_row_id > 0;
update message_view_once_media set message_row_id = -message_row_id where message_row_id < 0;
update missed_call_logs set message_row_id = -(message_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where message_row_id > 0;
update missed_call_logs set message_row_id = -message_row_id where message_row_id < 0;
update mms_thumbnail_metadata set message_row_id = -(message_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where message_row_id > 0;
update mms_thumbnail_metadata set message_row_id = -message_row_id where message_row_id < 0;
update receipt_device set message_row_id = -(message_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where message_row_id > 0;
update receipt_device set message_row_id = -message_row_id where message_row_id < 0;
update receipt_user set message_row_id = -(message_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where message_row_id > 0;
update receipt_user set message_row_id = -message_row_id where message_row_id < 0;
update status set message_table_id = -(message_table_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where message_table_id > 0;
update status set message_table_id = -message_table_id where message_table_id < 0;
update status set last_read_message_table_id = -(last_read_message_table_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where last_read_message_table_id > 0;
update status set last_read_message_table_id = -last_read_message_table_id where last_read_message_table_id < 0;
update status set last_read_receipt_sent_message_table_id = -(last_read_receipt_sent_message_table_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where last_read_receipt_sent_message_table_id > 0;
update status set last_read_receipt_sent_message_table_id = -last_read_receipt_sent_message_table_id where last_read_receipt_sent_message_table_id < 0;
update status set last_read_message_table_id = -(last_read_message_table_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where last_read_message_table_id > 0;
update status set last_read_message_table_id = -last_read_message_table_id where last_read_message_table_id < 0;
update status set first_unread_message_table_id = -(first_unread_message_table_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where first_unread_message_table_id > 0;
update status set first_unread_message_table_id = -first_unread_message_table_id where first_unread_message_table_id < 0;
update status set autodownload_limit_message_table_id = -(autodownload_limit_message_table_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where autodownload_limit_message_table_id > 0;
update status set autodownload_limit_message_table_id = -autodownload_limit_message_table_id where autodownload_limit_message_table_id < 0;
update message_link set message_row_id = -(message_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where message_row_id > 0;
update message_link set message_row_id = -message_row_id where message_row_id < 0;
update message_vcard set message_row_id = -(message_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where message_row_id > 0;
update message_vcard set message_row_id = -message_row_id where message_row_id < 0;
update message_vcard_jid set message_row_id = -(message_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where message_row_id > 0;
update message_vcard_jid set message_row_id = -message_row_id where message_row_id < 0;
-----------------------------------------------------------------------------
update message_quoted set message_row_id = -(message_row_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message")) where message_row_id > 0;
update message_quoted set message_row_id = -message_row_id where message_row_id < 0;
update message_link set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message_link")) where _id > 0;
update message_link set _id = -_id where _id < 0;
update message_vcard set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message_vcard")) where _id > 0;
update message_vcard set _id = -_id where _id < 0;
update message_vcard_jid set _id = -(_id + (SELECT seq FROM oldest.sqlite_sequence WHERE name="message_vcard_jid")) where _id > 0;
update message_vcard_jid set _id = -_id where _id < 0;