github.com/status-im/status-go@v1.1.0/appdatabase/migrations/sql/1689498471_make_wallet_accounts_positions_non_negative.up.sql (about) 1 -- All wallet account positions should be positive, startig from 0. 2 -- Chat account position will be always -1. 3 UPDATE 4 keypairs_accounts 5 SET 6 position = (SELECT MIN(position) - 1 AS min_pos FROM keypairs_accounts) 7 WHERE 8 chat = 1; 9 10 CREATE TABLE keypairs_accounts_tmp ( 11 id INTEGER PRIMARY KEY AUTOINCREMENT, 12 address VARCHAR, 13 key_uid VARCHAR, 14 pubkey VARCHAR, 15 path VARCHAR NOT NULL DEFAULT "", 16 name VARCHAR NOT NULL DEFAULT "", 17 color VARCHAR NOT NULL DEFAULT "", 18 emoji VARCHAR NOT NULL DEFAULT "", 19 wallet BOOL NOT NULL DEFAULT FALSE, 20 chat BOOL NOT NULL DEFAULT FALSE, 21 hidden BOOL NOT NULL DEFAULT FALSE, 22 operable VARCHAR NOT NULL DEFAULT "no", 23 created_at DATETIME NOT NULL, 24 updated_at DATETIME NOT NULL, 25 clock INT NOT NULL DEFAULT 0, 26 position INT NOT NULL DEFAULT 0, 27 FOREIGN KEY (key_uid) REFERENCES keypairs (key_uid) ON DELETE CASCADE 28 ); 29 30 INSERT INTO 31 keypairs_accounts_tmp (address, key_uid, pubkey, path, name, color, emoji, wallet, chat, 32 hidden, operable, created_at, updated_at, clock, position) 33 SELECT * 34 FROM 35 keypairs_accounts 36 ORDER BY 37 position; 38 39 DELETE FROM keypairs_accounts; 40 41 INSERT INTO 42 keypairs_accounts 43 SELECT 44 address, key_uid, pubkey, path, name, color, emoji, wallet, chat, hidden, operable, 45 created_at, updated_at, clock, id-2 AS pos 46 FROM 47 keypairs_accounts_tmp; 48 49 DROP TABLE keypairs_accounts_tmp; 50 51 -- we need to keep a clock when accounts reordering was executed 52 ALTER TABLE settings ADD COLUMN wallet_accounts_position_change_clock INTEGER NOT NULL DEFAULT 0;