From 2f92c6b7aee12423f0ce8e46f3c5635e420dcbb4 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Wed, 23 Sep 2026 14:54:32 +0200 Subject: [PATCH] rename db --- simplex-chat.cabal | 4 ++-- src/Simplex/Chat/Store/Postgres/Migrations.hs | 4 ++-- ...mes.hs => M20260923_wallet_owned_names.hs} | 12 +++++------ .../Store/Postgres/Migrations/chat_schema.sql | 20 +++++++++---------- src/Simplex/Chat/Store/SQLite/Migrations.hs | 4 ++-- ...mes.hs => M20260923_wallet_owned_names.hs} | 12 +++++------ .../Store/SQLite/Migrations/chat_schema.sql | 6 +++--- src/Simplex/Chat/Store/Wallets.hs | 2 +- tests/WalletTests.hs | 2 +- 9 files changed, 33 insertions(+), 33 deletions(-) rename src/Simplex/Chat/Store/Postgres/Migrations/{M20260923_wallet_names.hs => M20260923_wallet_owned_names.hs} (56%) rename src/Simplex/Chat/Store/SQLite/Migrations/{M20260923_wallet_names.hs => M20260923_wallet_owned_names.hs} (57%) diff --git a/simplex-chat.cabal b/simplex-chat.cabal index 50ec31ffdb..052ae6d275 100644 --- a/simplex-chat.cabal +++ b/simplex-chat.cabal @@ -169,7 +169,7 @@ library Simplex.Chat.Store.Postgres.Migrations.M20260904_file_badges Simplex.Chat.Store.Postgres.Migrations.M20260915_user_badges Simplex.Chat.Store.Postgres.Migrations.M20260921_wallet_seeds - Simplex.Chat.Store.Postgres.Migrations.M20260923_wallet_names + Simplex.Chat.Store.Postgres.Migrations.M20260923_wallet_owned_names else exposed-modules: Simplex.Chat.Archive @@ -346,7 +346,7 @@ library Simplex.Chat.Store.SQLite.Migrations.M20260904_file_badges Simplex.Chat.Store.SQLite.Migrations.M20260915_user_badges Simplex.Chat.Store.SQLite.Migrations.M20260921_wallet_seeds - Simplex.Chat.Store.SQLite.Migrations.M20260923_wallet_names + Simplex.Chat.Store.SQLite.Migrations.M20260923_wallet_owned_names other-modules: Paths_simplex_chat hs-source-dirs: diff --git a/src/Simplex/Chat/Store/Postgres/Migrations.hs b/src/Simplex/Chat/Store/Postgres/Migrations.hs index ddca9cde31..0e348f4221 100644 --- a/src/Simplex/Chat/Store/Postgres/Migrations.hs +++ b/src/Simplex/Chat/Store/Postgres/Migrations.hs @@ -52,7 +52,7 @@ import Simplex.Chat.Store.Postgres.Migrations.M20260828_file_expiry import Simplex.Chat.Store.Postgres.Migrations.M20260904_file_badges import Simplex.Chat.Store.Postgres.Migrations.M20260915_user_badges import Simplex.Chat.Store.Postgres.Migrations.M20260921_wallet_seeds -import Simplex.Chat.Store.Postgres.Migrations.M20260923_wallet_names +import Simplex.Chat.Store.Postgres.Migrations.M20260923_wallet_owned_names import Simplex.Messaging.Agent.Store.Shared (Migration (..)) schemaMigrations :: [(String, Text, Maybe Text)] @@ -105,7 +105,7 @@ schemaMigrations = ("20260904_file_badges", m20260904_file_badges, Just down_m20260904_file_badges), ("20260915_user_badges", m20260915_user_badges, Just down_m20260915_user_badges), ("20260921_wallet_seeds", m20260921_wallet_seeds, Nothing), - ("20260923_wallet_names", m20260923_wallet_names, Nothing) + ("20260923_wallet_owned_names", m20260923_wallet_owned_names, Nothing) ] -- | The list of migrations in ascending order by date diff --git a/src/Simplex/Chat/Store/Postgres/Migrations/M20260923_wallet_names.hs b/src/Simplex/Chat/Store/Postgres/Migrations/M20260923_wallet_owned_names.hs similarity index 56% rename from src/Simplex/Chat/Store/Postgres/Migrations/M20260923_wallet_names.hs rename to src/Simplex/Chat/Store/Postgres/Migrations/M20260923_wallet_owned_names.hs index e4253ee667..eb5d0823bb 100644 --- a/src/Simplex/Chat/Store/Postgres/Migrations/M20260923_wallet_names.hs +++ b/src/Simplex/Chat/Store/Postgres/Migrations/M20260923_wallet_owned_names.hs @@ -1,24 +1,24 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} -module Simplex.Chat.Store.Postgres.Migrations.M20260923_wallet_names where +module Simplex.Chat.Store.Postgres.Migrations.M20260923_wallet_owned_names where import Data.Text (Text) import Text.RawString.QQ (r) -m20260923_wallet_names :: Text -m20260923_wallet_names = +m20260923_wallet_owned_names :: Text +m20260923_wallet_owned_names = [r| -- the columns are commented in the SQLite migration -CREATE TABLE wallet_names ( - wallet_name_id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, +CREATE TABLE wallet_owned_names ( + wallet_owned_name_id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, wallet_seed_id BIGINT NOT NULL REFERENCES wallet_seeds ON DELETE CASCADE, account_index BIGINT NOT NULL CHECK (account_index BETWEEN 0 AND 2147483647), name TEXT NOT NULL, name_response TEXT NOT NULL ); -CREATE UNIQUE INDEX idx_wallet_names_wallet_seed_id_name ON wallet_names(wallet_seed_id, name); +CREATE UNIQUE INDEX idx_wallet_owned_names_wallet_seed_id_name ON wallet_owned_names(wallet_seed_id, name); |] -- No reverse step: wallet_seeds, which the rows hang off, has none either. diff --git a/src/Simplex/Chat/Store/Postgres/Migrations/chat_schema.sql b/src/Simplex/Chat/Store/Postgres/Migrations/chat_schema.sql index 97b0000331..610a67da57 100644 --- a/src/Simplex/Chat/Store/Postgres/Migrations/chat_schema.sql +++ b/src/Simplex/Chat/Store/Postgres/Migrations/chat_schema.sql @@ -1745,19 +1745,19 @@ ALTER TABLE test_chat_schema.wallet_accounts ALTER COLUMN wallet_account_id ADD -CREATE TABLE test_chat_schema.wallet_names ( - wallet_name_id bigint NOT NULL, +CREATE TABLE test_chat_schema.wallet_owned_names ( + wallet_owned_name_id bigint NOT NULL, wallet_seed_id bigint NOT NULL, account_index bigint NOT NULL, name text NOT NULL, name_response text NOT NULL, - CONSTRAINT wallet_names_account_index_check CHECK (((account_index >= 0) AND (account_index <= 2147483647))) + CONSTRAINT wallet_owned_names_account_index_check CHECK (((account_index >= 0) AND (account_index <= 2147483647))) ); -ALTER TABLE test_chat_schema.wallet_names ALTER COLUMN wallet_name_id ADD GENERATED ALWAYS AS IDENTITY ( - SEQUENCE NAME test_chat_schema.wallet_names_wallet_name_id_seq +ALTER TABLE test_chat_schema.wallet_owned_names ALTER COLUMN wallet_owned_name_id ADD GENERATED ALWAYS AS IDENTITY ( + SEQUENCE NAME test_chat_schema.wallet_owned_names_wallet_owned_name_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -2207,8 +2207,8 @@ ALTER TABLE ONLY test_chat_schema.wallet_accounts -ALTER TABLE ONLY test_chat_schema.wallet_names - ADD CONSTRAINT wallet_names_pkey PRIMARY KEY (wallet_name_id); +ALTER TABLE ONLY test_chat_schema.wallet_owned_names + ADD CONSTRAINT wallet_owned_names_pkey PRIMARY KEY (wallet_owned_name_id); @@ -3026,7 +3026,7 @@ CREATE UNIQUE INDEX idx_wallet_accounts_wallet_seed_id_account_index ON test_cha -CREATE UNIQUE INDEX idx_wallet_names_wallet_seed_id_name ON test_chat_schema.wallet_names USING btree (wallet_seed_id, name); +CREATE UNIQUE INDEX idx_wallet_owned_names_wallet_seed_id_name ON test_chat_schema.wallet_owned_names USING btree (wallet_seed_id, name); @@ -3769,8 +3769,8 @@ ALTER TABLE ONLY test_chat_schema.wallet_accounts -ALTER TABLE ONLY test_chat_schema.wallet_names - ADD CONSTRAINT wallet_names_wallet_seed_id_fkey FOREIGN KEY (wallet_seed_id) REFERENCES test_chat_schema.wallet_seeds(wallet_seed_id) ON DELETE CASCADE; +ALTER TABLE ONLY test_chat_schema.wallet_owned_names + ADD CONSTRAINT wallet_owned_names_wallet_seed_id_fkey FOREIGN KEY (wallet_seed_id) REFERENCES test_chat_schema.wallet_seeds(wallet_seed_id) ON DELETE CASCADE; diff --git a/src/Simplex/Chat/Store/SQLite/Migrations.hs b/src/Simplex/Chat/Store/SQLite/Migrations.hs index a1dfa0c74e..43ff09b41c 100644 --- a/src/Simplex/Chat/Store/SQLite/Migrations.hs +++ b/src/Simplex/Chat/Store/SQLite/Migrations.hs @@ -175,7 +175,7 @@ import Simplex.Chat.Store.SQLite.Migrations.M20260828_file_expiry import Simplex.Chat.Store.SQLite.Migrations.M20260904_file_badges import Simplex.Chat.Store.SQLite.Migrations.M20260915_user_badges import Simplex.Chat.Store.SQLite.Migrations.M20260921_wallet_seeds -import Simplex.Chat.Store.SQLite.Migrations.M20260923_wallet_names +import Simplex.Chat.Store.SQLite.Migrations.M20260923_wallet_owned_names import Simplex.Messaging.Agent.Store.Shared (Migration (..)) schemaMigrations :: [(String, Query, Maybe Query)] @@ -351,7 +351,7 @@ schemaMigrations = ("20260904_file_badges", m20260904_file_badges, Just down_m20260904_file_badges), ("20260915_user_badges", m20260915_user_badges, Just down_m20260915_user_badges), ("20260921_wallet_seeds", m20260921_wallet_seeds, Nothing), - ("20260923_wallet_names", m20260923_wallet_names, Nothing) + ("20260923_wallet_owned_names", m20260923_wallet_owned_names, Nothing) ] -- | The list of migrations in ascending order by date diff --git a/src/Simplex/Chat/Store/SQLite/Migrations/M20260923_wallet_names.hs b/src/Simplex/Chat/Store/SQLite/Migrations/M20260923_wallet_owned_names.hs similarity index 57% rename from src/Simplex/Chat/Store/SQLite/Migrations/M20260923_wallet_names.hs rename to src/Simplex/Chat/Store/SQLite/Migrations/M20260923_wallet_owned_names.hs index 9d7db9f892..1cfaeec57a 100644 --- a/src/Simplex/Chat/Store/SQLite/Migrations/M20260923_wallet_names.hs +++ b/src/Simplex/Chat/Store/SQLite/Migrations/M20260923_wallet_owned_names.hs @@ -1,22 +1,22 @@ {-# LANGUAGE QuasiQuotes #-} -module Simplex.Chat.Store.SQLite.Migrations.M20260923_wallet_names where +module Simplex.Chat.Store.SQLite.Migrations.M20260923_wallet_owned_names where import Database.SQLite.Simple (Query) import Database.SQLite.Simple.QQ (sql) -m20260923_wallet_names :: Query -m20260923_wallet_names = +m20260923_wallet_owned_names :: Query +m20260923_wallet_owned_names = [sql| -CREATE TABLE wallet_names ( - wallet_name_id INTEGER PRIMARY KEY AUTOINCREMENT, +CREATE TABLE wallet_owned_names ( + wallet_owned_name_id INTEGER PRIMARY KEY AUTOINCREMENT, wallet_seed_id INTEGER NOT NULL REFERENCES wallet_seeds ON DELETE CASCADE, account_index INTEGER NOT NULL CHECK (account_index BETWEEN 0 AND 2147483647), name TEXT NOT NULL, name_response TEXT NOT NULL -- the NameResponse a scan last read for this name ) STRICT; -CREATE UNIQUE INDEX idx_wallet_names_wallet_seed_id_name ON wallet_names(wallet_seed_id, name); +CREATE UNIQUE INDEX idx_wallet_owned_names_wallet_seed_id_name ON wallet_owned_names(wallet_seed_id, name); |] -- No reverse step: wallet_seeds, which the rows hang off, has none either. diff --git a/src/Simplex/Chat/Store/SQLite/Migrations/chat_schema.sql b/src/Simplex/Chat/Store/SQLite/Migrations/chat_schema.sql index ef2fc5231e..a11ed2401c 100644 --- a/src/Simplex/Chat/Store/SQLite/Migrations/chat_schema.sql +++ b/src/Simplex/Chat/Store/SQLite/Migrations/chat_schema.sql @@ -987,8 +987,8 @@ CREATE TABLE wallet_accounts( account_index INTEGER CHECK(account_index BETWEEN 0 AND 2147483647), user_id INTEGER REFERENCES users ON DELETE SET NULL ) STRICT; -CREATE TABLE wallet_names( - wallet_name_id INTEGER PRIMARY KEY AUTOINCREMENT, +CREATE TABLE wallet_owned_names( + wallet_owned_name_id INTEGER PRIMARY KEY AUTOINCREMENT, wallet_seed_id INTEGER NOT NULL REFERENCES wallet_seeds ON DELETE CASCADE, account_index INTEGER NOT NULL CHECK(account_index BETWEEN 0 AND 2147483647), name TEXT NOT NULL, @@ -1563,7 +1563,7 @@ CREATE UNIQUE INDEX idx_wallet_accounts_wallet_seed_id_account_index ON wallet_a account_index ); CREATE INDEX idx_wallet_accounts_user_id ON wallet_accounts(user_id); -CREATE UNIQUE INDEX idx_wallet_names_wallet_seed_id_name ON wallet_names( +CREATE UNIQUE INDEX idx_wallet_owned_names_wallet_seed_id_name ON wallet_owned_names( wallet_seed_id, name ); diff --git a/src/Simplex/Chat/Store/Wallets.hs b/src/Simplex/Chat/Store/Wallets.hs index 0b225bd6e8..5a600a19f4 100644 --- a/src/Simplex/Chat/Store/Wallets.hs +++ b/src/Simplex/Chat/Store/Wallets.hs @@ -174,7 +174,7 @@ recordScan db sId userId inUse = do DB.execute db [sql| - INSERT INTO wallet_names (wallet_seed_id, account_index, name, name_response) VALUES (?, ?, ?, ?) + INSERT INTO wallet_owned_names (wallet_seed_id, account_index, name, name_response) VALUES (?, ?, ?, ?) ON CONFLICT (wallet_seed_id, name) DO UPDATE SET account_index = EXCLUDED.account_index, name_response = EXCLUDED.name_response |] diff --git a/tests/WalletTests.hs b/tests/WalletTests.hs index 4a0fdcf088..7350932c61 100644 --- a/tests/WalletTests.hs +++ b/tests/WalletTests.hs @@ -121,7 +121,7 @@ testWalletScan ps = withSmpServerAndNames $ \reg -> withNewTestChat ps "alice" a alice ##> "/_wallet scan" alice <## "accounts: 1" -- the names the scan saw are recorded against the account that holds them - names <- withCCTransaction alice $ \db -> DB.query_ db "SELECT account_index, name, name_response FROM wallet_names" + names <- withCCTransaction alice $ \db -> DB.query_ db "SELECT account_index, name, name_response FROM wallet_owned_names" map (\(n, nm, _) -> (n, nm)) names `shouldBe` [(1 :: Int64, "alice.simplex" :: Text)] map (\(_, _, r) -> registeredName <$> decodeJSON r) names `shouldBe` [Just (Just "alice.simplex")] -- the scan gives the imported phrase the counter it had none of