core: name the unique index on wallet_seeds

The one key per device rule is meant to be lifted later. SQLite cannot drop
a column with an inline UNIQUE, or its automatic index, so lifting it would
have meant rebuilding the table. As a named index it is a DROP INDEX and a
DROP COLUMN.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rvc3HbiWBTqbAvRT45G5oX
This commit is contained in:
Alain Brenzikofer
2026-09-10 09:53:26 +00:00
co-authored by Claude Opus 5
parent fe9c20370f
commit e7f5908d01
5 changed files with 12 additions and 10 deletions
@@ -15,12 +15,13 @@ CREATE TABLE wallet_seeds (
-- see the SQLite migration
next_account_index BIGINT NOT NULL DEFAULT 0,
-- one key per device for now
single_seed SMALLINT NOT NULL DEFAULT 1 UNIQUE
single_seed SMALLINT NOT NULL DEFAULT 1
);
ALTER TABLE users ADD COLUMN wallet_seed_id BIGINT REFERENCES wallet_seeds ON DELETE RESTRICT;
ALTER TABLE users ADD COLUMN wallet_account_index BIGINT;
CREATE UNIQUE INDEX idx_wallet_seeds_single_seed ON wallet_seeds(single_seed);
CREATE INDEX idx_users_wallet_seed_id ON users(wallet_seed_id);
|]
@@ -1918,11 +1918,6 @@ ALTER TABLE ONLY test_chat_schema.wallet_seeds
ALTER TABLE ONLY test_chat_schema.wallet_seeds
ADD CONSTRAINT wallet_seeds_single_seed_key UNIQUE (single_seed);
ALTER TABLE ONLY test_chat_schema.xftp_file_descriptions
ADD CONSTRAINT xftp_file_descriptions_pkey PRIMARY KEY (file_descr_id);
@@ -2676,6 +2671,10 @@ CREATE INDEX idx_users_wallet_seed_id ON test_chat_schema.users USING btree (wal
CREATE UNIQUE INDEX idx_wallet_seeds_single_seed ON test_chat_schema.wallet_seeds USING btree (single_seed);
CREATE INDEX idx_xftp_file_descriptions_user_id ON test_chat_schema.xftp_file_descriptions USING btree (user_id);
@@ -16,12 +16,13 @@ CREATE TABLE wallet_seeds (
-- the order they ask for a key, not the order they had
next_account_index INTEGER NOT NULL DEFAULT 0,
-- one key per device for now
single_seed INTEGER NOT NULL DEFAULT 1 UNIQUE
single_seed INTEGER NOT NULL DEFAULT 1
) STRICT;
ALTER TABLE users ADD COLUMN wallet_seed_id INTEGER REFERENCES wallet_seeds ON DELETE RESTRICT;
ALTER TABLE users ADD COLUMN wallet_account_index INTEGER;
CREATE UNIQUE INDEX idx_wallet_seeds_single_seed ON wallet_seeds(single_seed);
CREATE INDEX idx_users_wallet_seed_id ON users(wallet_seed_id);
|]
@@ -862,7 +862,7 @@ CREATE TABLE wallet_seeds(
-- the order they ask for a key, not the order they had
next_account_index INTEGER NOT NULL DEFAULT 0,
-- one key per device for now
single_seed INTEGER NOT NULL DEFAULT 1 UNIQUE
single_seed INTEGER NOT NULL DEFAULT 1
) STRICT;
CREATE INDEX contact_profiles_index ON contact_profiles(
display_name,
@@ -1398,6 +1398,7 @@ CREATE INDEX idx_files_roster_transfer_id ON files(roster_transfer_id);
CREATE INDEX idx_chat_items_item_signed_by_group_member_id ON chat_items(
item_signed_by_group_member_id
);
CREATE UNIQUE INDEX idx_wallet_seeds_single_seed ON wallet_seeds(single_seed);
CREATE INDEX idx_users_wallet_seed_id ON users(wallet_seed_id);
CREATE TRIGGER on_group_members_insert_update_summary
AFTER INSERT ON group_members
+2 -2
View File
@@ -2,8 +2,8 @@
-- | BIP-39 seeds and the keys derived from them.
--
-- One key per name, not one per profile, so that exporting a name's key hands
-- over that name only.
-- Two layers: one account path per profile, and one key per name under it. A
-- per-profile key would hand over every name that profile owns.
module Simplex.Chat.Wallet
( SeedId (..),
WalletSeed (..),