From 1e59c2a6c79586d255fa27ef11895a1a16752623 Mon Sep 17 00:00:00 2001 From: eta Date: Thu, 23 Jul 2020 08:08:44 +0100 Subject: [PATCH] add fixup_1.sql, which corrects the UNIQUE error on user_contacts - The user_contacts table contained an incorrect UNIQUE constraint on wa_jid that meant only one user of the bridge could have any given whatsapp user in their contacts. - This is fixed in fixup_1.sql, which should be applied over schema.sql. --- fixup_1.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 fixup_1.sql diff --git a/fixup_1.sql b/fixup_1.sql new file mode 100644 index 0000000..3409c2e --- /dev/null +++ b/fixup_1.sql @@ -0,0 +1,18 @@ +BEGIN; +CREATE TABLE new_user_contacts ( + id INTEGER PRIMARY KEY, + user_id INT NOT NULL REFERENCES users, + wa_jid VARCHAR NOT NULL, + subscription_state VARCHAR NOT NULL DEFAULT 'none', + avatar_url VARCHAR, + name VARCHAR, + notify VARCHAR, + status VARCHAR, + UNIQUE(user_id, wa_jid) +); + +INSERT INTO new_user_contacts SELECT * FROM user_contacts; +DROP TABLE user_contacts; +ALTER TABLE new_user_contacts RENAME TO user_contacts; +CREATE INDEX user_contacts_idx ON user_contacts (user_id, wa_jid); +COMMIT;