rename db

This commit is contained in:
Alain Brenzikofer
2026-09-23 14:54:32 +02:00
parent 6999e63a66
commit 2f92c6b7ae
9 changed files with 33 additions and 33 deletions
+2 -2
View File
@@ -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:
@@ -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
@@ -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.
@@ -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;
+2 -2
View File
@@ -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
@@ -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.
@@ -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
);
+1 -1
View File
@@ -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
|]
+1 -1
View File
@@ -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