From 7b8333ea2438d3293af96fbe27fd459c4e9b68b5 Mon Sep 17 00:00:00 2001 From: Jerin J Titus <72017981+jerinjtitus@users.noreply.github.com> Date: Wed, 6 Jan 2021 06:58:28 +0530 Subject: [PATCH 1/6] Dropped last_used column from access_tokens Signed-off-by: Jerin J Titus <72017981+jerinjtitus@users.noreply.github.com> --- .../delta/58/28drop_last_used_column.sql | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql diff --git a/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql b/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql new file mode 100644 index 000000000000..1e2600a47b8a --- /dev/null +++ b/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql @@ -0,0 +1,30 @@ +/* + * Copyright 2020 The Matrix.org Foundation C.I.C. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + -- Dropping last_used column from access_tokens table. + +CREATE TABLE access_tokens2 ( + id BIGINT PRIMARY KEY, + user_id TEXT NOT NULL, + device_id TEXT, + token TEXT NOT NULL, + UNIQUE(token) +); + +INSERT INTO access_tokens2(id, user_id, device_id, token) + SELECT id, user_id, device_id, token from access_tokens; + +DROP TABLE access_tokens; +ALTER TABLE access_tokens2 RENAME TO access_tokens; From d7a571e735558f7f0ad5bf6b35d3a679b4dabc13 Mon Sep 17 00:00:00 2001 From: Jerin J Titus <72017981+jerinjtitus@users.noreply.github.com> Date: Wed, 6 Jan 2021 07:06:24 +0530 Subject: [PATCH 2/6] Added changelog file Signed-off-by: Jerin J Titus <72017981+jerinjtitus@users.noreply.github.com> --- changelog.d/9025.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/9025.misc diff --git a/changelog.d/9025.misc b/changelog.d/9025.misc new file mode 100644 index 000000000000..1279405f8824 --- /dev/null +++ b/changelog.d/9025.misc @@ -0,0 +1 @@ +Removed an unused column from access_tokens table. \ No newline at end of file From 57f833f9bb67a9d36763d9f313d9efc525586d0f Mon Sep 17 00:00:00 2001 From: Jerin J Titus <72017981+jerinjtitus@users.noreply.github.com> Date: Wed, 6 Jan 2021 09:06:11 +0530 Subject: [PATCH 3/6] Re-added access_tokens_device_id index Signed-off-by: Jerin J Titus <72017981+jerinjtitus@users.noreply.github.com> --- .../databases/main/schema/delta/58/28drop_last_used_column.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql b/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql index 1e2600a47b8a..c72ebb0fbfdd 100644 --- a/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql +++ b/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql @@ -28,3 +28,5 @@ INSERT INTO access_tokens2(id, user_id, device_id, token) DROP TABLE access_tokens; ALTER TABLE access_tokens2 RENAME TO access_tokens; + +CREATE INDEX access_tokens_device_id ON access_tokens (user_id, device_id); From 81f3b6634e5a787369a3d95e37679b7f9c946dd2 Mon Sep 17 00:00:00 2001 From: Jerin J Titus <72017981+jerinjtitus@users.noreply.github.com> Date: Wed, 6 Jan 2021 20:50:19 +0530 Subject: [PATCH 4/6] Added leftout columns Signed-off-by: Jerin J Titus <72017981+jerinjtitus@users.noreply.github.com> --- .../delta/58/28drop_last_used_column.sql | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql b/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql index c72ebb0fbfdd..ee0e3521bfb2 100644 --- a/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql +++ b/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + -- Dropping last_used column from access_tokens table. CREATE TABLE access_tokens2 ( @@ -20,13 +21,42 @@ CREATE TABLE access_tokens2 ( user_id TEXT NOT NULL, device_id TEXT, token TEXT NOT NULL, + valid_until_ms BIGINT, + puppets_user_id TEXT, + last_validated BIGINT, UNIQUE(token) ); INSERT INTO access_tokens2(id, user_id, device_id, token) - SELECT id, user_id, device_id, token from access_tokens; + SELECT id, user_id, device_id, token FROM access_tokens; DROP TABLE access_tokens; ALTER TABLE access_tokens2 RENAME TO access_tokens; CREATE INDEX access_tokens_device_id ON access_tokens (user_id, device_id); + + +-- Re-adding foreign key reference in event_txn_id table + +CREATE TABLE event_txn_id2 ( + event_id TEXT NOT NULL, + room_id TEXT NOT NULL, + user_id TEXT NOT NULL, + token_id BIGINT NOT NULL, + txn_id TEXT NOT NULL, + inserted_ts BIGINT NOT NULL, + FOREIGN KEY (event_id) + REFERENCES events (event_id) ON DELETE CASCADE, + FOREIGN KEY (token_id) + REFERENCES access_tokens (id) ON DELETE CASCADE +); + +INSERT INTO event_txn_id2(event_id, room_id, user_id, token_id, txn_id, inserted_ts) + SELECT event_id, room_id, user_id, token_id, txn_id, inserted_ts FROM event_txn_id; + +DROP TABLE event_txn_id; +ALTER TABLE event_txn_id2 RENAME TO event_txn_id; + +CREATE UNIQUE INDEX IF NOT EXISTS event_txn_id_event_id ON event_txn_id(event_id); +CREATE UNIQUE INDEX IF NOT EXISTS event_txn_id_txn_id ON event_txn_id(room_id, user_id, token_id, txn_id); +CREATE INDEX IF NOT EXISTS event_txn_id_ts ON event_txn_id(inserted_ts); \ No newline at end of file From 13256385c29cdb341995999a2b685339d869d6e4 Mon Sep 17 00:00:00 2001 From: Jerin J Titus <72017981+jerinjtitus@users.noreply.github.com> Date: Wed, 6 Jan 2021 22:49:43 +0530 Subject: [PATCH 5/6] added delta file for dropping column from postgres Signed-off-by: Jerin J Titus <72017981+jerinjtitus@users.noreply.github.com> --- .../58/28drop_last_used_column.sql.postgres | 16 ++++++++++++++++ ...mn.sql => 28drop_last_used_column.sql.sqlite} | 0 2 files changed, 16 insertions(+) create mode 100644 synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql.postgres rename synapse/storage/databases/main/schema/delta/58/{28drop_last_used_column.sql => 28drop_last_used_column.sql.sqlite} (100%) diff --git a/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql.postgres b/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql.postgres new file mode 100644 index 000000000000..de5764501975 --- /dev/null +++ b/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql.postgres @@ -0,0 +1,16 @@ +/* Copyright 2020 The Matrix.org Foundation C.I.C + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +ALTER TABLE access_tokens DROP COLUMN last_used; \ No newline at end of file diff --git a/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql b/synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql.sqlite similarity index 100% rename from synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql rename to synapse/storage/databases/main/schema/delta/58/28drop_last_used_column.sql.sqlite From 74a5d010d4fe1a298188d77de59de248b7214fda Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 11 Jan 2021 10:20:45 +0000 Subject: [PATCH 6/6] Fixup changelog.d/9025.misc --- changelog.d/9025.misc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/9025.misc b/changelog.d/9025.misc index 1279405f8824..658f50d8534a 100644 --- a/changelog.d/9025.misc +++ b/changelog.d/9025.misc @@ -1 +1 @@ -Removed an unused column from access_tokens table. \ No newline at end of file +Removed an unused column from `access_tokens` table.