@@ -41,6 +41,16 @@ static MIGRATIONS: &[&str] = &[
41
41
"INSERT INTO transaction_details SELECT txid, timestamp, received, sent, fee, height FROM transaction_details_old;" ,
42
42
"DROP TABLE transaction_details_old;" ,
43
43
"ALTER TABLE utxos ADD COLUMN is_spent;" ,
44
+ // drop all data due to possible inconsistencies with duplicate utxos, re-sync required
45
+ "DELETE FROM checksums;" ,
46
+ "DELETE FROM last_derivation_indices;" ,
47
+ "DELETE FROM script_pubkeys;" ,
48
+ "DELETE FROM sync_time;" ,
49
+ "DELETE FROM transaction_details;" ,
50
+ "DELETE FROM transactions;" ,
51
+ "DELETE FROM utxos;" ,
52
+ "DROP INDEX idx_txid_vout;" ,
53
+ "CREATE UNIQUE INDEX idx_utxos_txid_vout ON utxos(txid, vout);"
44
54
] ;
45
55
46
56
/// Sqlite database stored on filesystem
@@ -86,7 +96,7 @@ impl SqliteDatabase {
86
96
script : & [ u8 ] ,
87
97
is_spent : bool ,
88
98
) -> Result < i64 , Error > {
89
- let mut statement = self . connection . prepare_cached ( "INSERT INTO utxos (value, keychain, vout, txid, script, is_spent) VALUES (:value, :keychain, :vout, :txid, :script, :is_spent)" ) ?;
99
+ let mut statement = self . connection . prepare_cached ( "INSERT INTO utxos (value, keychain, vout, txid, script, is_spent) VALUES (:value, :keychain, :vout, :txid, :script, :is_spent) ON CONFLICT(txid, vout) DO UPDATE SET value=:value, keychain=:keychain, script=:script, is_spent=:is_spent " ) ?;
90
100
statement. execute ( named_params ! {
91
101
":value" : value,
92
102
":keychain" : keychain,
0 commit comments