diff --git a/migrations/message_store_postgres/content_script_version_3.nim b/migrations/message_store_postgres/content_script_version_3.nim new file mode 100644 index 0000000000..2938087ccd --- /dev/null +++ b/migrations/message_store_postgres/content_script_version_3.nim @@ -0,0 +1,8 @@ +const ContentScriptVersion_3* = + """ +CREATE INDEX IF NOT EXISTS i_query ON messages + (contentTopic, pubsubTopic, storedAt, id); + +UPDATE version SET version = 3 WHERE version = 2; + +""" diff --git a/migrations/message_store_postgres/pg_migration_manager.nim b/migrations/message_store_postgres/pg_migration_manager.nim index 661e23cae2..d4de18f6d9 100644 --- a/migrations/message_store_postgres/pg_migration_manager.nim +++ b/migrations/message_store_postgres/pg_migration_manager.nim @@ -1,4 +1,4 @@ -import content_script_version_1, content_script_version_2 +import content_script_version_1, content_script_version_2, content_script_version_3 type MigrationScript* = object version*: int @@ -11,6 +11,7 @@ const PgMigrationScripts* = @[ MigrationScript(version: 1, scriptContent: ContentScriptVersion_1), MigrationScript(version: 2, scriptContent: ContentScriptVersion_2), + MigrationScript(version: 3, scriptContent: ContentScriptVersion_3), ] 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 c4b25228a3..a7f4814792 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* = 2 # increase this when there is an update in the database schema +const SchemaVersion* = 3 # 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 diff --git a/waku/waku_archive/driver/sqlite_driver/sqlite_driver.nim b/waku/waku_archive/driver/sqlite_driver/sqlite_driver.nim index 2190ce8fb6..5331f2ea47 100644 --- a/waku/waku_archive/driver/sqlite_driver/sqlite_driver.nim +++ b/waku/waku_archive/driver/sqlite_driver/sqlite_driver.nim @@ -35,7 +35,7 @@ proc init(db: SqliteDatabase): ArchiveDriverResult[void] = let resMsgIndex = createHistoryQueryIndex(db) if resMsgIndex.isErr(): - return err("failed to create i_msg index: " & resMsgIndex.error()) + return err("failed to create i_query index: " & resMsgIndex.error()) return ok()