From 3a93437300adb4fd165075da14c779d492db6f34 Mon Sep 17 00:00:00 2001 From: Ivan FB <128452529+Ivansete-status@users.noreply.github.com> Date: Thu, 6 Jun 2024 11:38:58 +0200 Subject: [PATCH] add new index to optimize the order by storedAt (#2778) --- .../message_store_postgres/content_script_version_5.nim | 6 ++++++ migrations/message_store_postgres/pg_migration_manager.nim | 3 ++- waku/waku_archive/driver/postgres_driver/migrations.nim | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 migrations/message_store_postgres/content_script_version_5.nim diff --git a/migrations/message_store_postgres/content_script_version_5.nim b/migrations/message_store_postgres/content_script_version_5.nim new file mode 100644 index 000000000..a59b2da87 --- /dev/null +++ b/migrations/message_store_postgres/content_script_version_5.nim @@ -0,0 +1,6 @@ +const ContentScriptVersion_5* = + """ +CREATE INDEX IF NOT EXISTS i_query_storedAt ON messages (storedAt, id); + +UPDATE version SET version = 5 WHERE version = 4; +""" diff --git a/migrations/message_store_postgres/pg_migration_manager.nim b/migrations/message_store_postgres/pg_migration_manager.nim index 2293f4027..86f6fcb27 100644 --- a/migrations/message_store_postgres/pg_migration_manager.nim +++ b/migrations/message_store_postgres/pg_migration_manager.nim @@ -1,6 +1,6 @@ import content_script_version_1, content_script_version_2, content_script_version_3, - content_script_version_4 + content_script_version_4, content_script_version_5 type MigrationScript* = object version*: int @@ -15,6 +15,7 @@ const PgMigrationScripts* = MigrationScript(version: 2, scriptContent: ContentScriptVersion_2), MigrationScript(version: 3, scriptContent: ContentScriptVersion_3), MigrationScript(version: 4, scriptContent: ContentScriptVersion_4), + MigrationScript(version: 5, scriptContent: ContentScriptVersion_5), ] proc getMigrationScripts*(currentVersion: int64, targetVersion: int64): seq[string] = diff --git a/waku/waku_archive/driver/postgres_driver/migrations.nim b/waku/waku_archive/driver/postgres_driver/migrations.nim index 1a52eeabc..4e09c3ca9 100644 --- a/waku/waku_archive/driver/postgres_driver/migrations.nim +++ b/waku/waku_archive/driver/postgres_driver/migrations.nim @@ -9,7 +9,7 @@ import logScope: topics = "waku archive migration" -const SchemaVersion* = 4 # increase this when there is an update in the database schema +const SchemaVersion* = 5 # increase this when there is an update in the database schema proc breakIntoStatements*(script: string): seq[string] = ## Given a full migration script, that can potentially contain a list