diff --git a/waku/v2/node/storage/message/waku_message_store_queries.nim b/waku/v2/node/storage/message/waku_message_store_queries.nim index a97a46588..e964dfb2a 100644 --- a/waku/v2/node/storage/message/waku_message_store_queries.nim +++ b/waku/v2/node/storage/message/waku_message_store_queries.nim @@ -76,7 +76,7 @@ proc createTable*(db: SqliteDatabase): DatabaseResult[void] {.inline.} = ## Create index template createIndexQuery(table: string): SqlQueryStr = - "CREATE INDEX IF NOT EXISTS i_rt ON " & table & " (receiverTimestamp);" + "CREATE INDEX IF NOT EXISTS i_msg ON " & table & " (contentTopic, pubsubTopic, senderTimestamp, id);" proc createIndex*(db: SqliteDatabase): DatabaseResult[void] {.inline.} = let query = createIndexQuery(DbTable) diff --git a/waku/v2/node/storage/migration/migration_types.nim b/waku/v2/node/storage/migration/migration_types.nim index 12b958c38..c2dd304c6 100644 --- a/waku/v2/node/storage/migration/migration_types.nim +++ b/waku/v2/node/storage/migration/migration_types.nim @@ -7,7 +7,7 @@ const MESSAGE_STORE_MIGRATION_PATH* = sourceDir / "migrations_scripts/message" const PEER_STORE_MIGRATION_PATH* = sourceDir / "migrations_scripts/peer" const ALL_STORE_MIGRATION_PATH* = sourceDir / "migrations_scripts" -const USER_VERSION* = 4 # increase this when there is an update in the database schema +const USER_VERSION* = 5 # increase this when there is an update in the database schema type MigrationScriptsResult*[T] = Result[T, string] type diff --git a/waku/v2/node/storage/migration/migrations_scripts/message/00005_updateIndex.up.sql b/waku/v2/node/storage/migration/migrations_scripts/message/00005_updateIndex.up.sql new file mode 100644 index 000000000..19cc8f81d --- /dev/null +++ b/waku/v2/node/storage/migration/migrations_scripts/message/00005_updateIndex.up.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS i_rt; + +CREATE INDEX IF NOT EXISTS i_msg ON Message (contentTopic, pubsubTopic, senderTimestamp, id);