Skip to content

Commit 369e17b

Browse files
Add datatype for is_spent sqlite column
Although, Sqlite column accepts values of any type, it is important to annotate this column to make it easy to reason about.
1 parent 9f9ffd0 commit 369e17b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/database/sqlite.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ static MIGRATIONS: &[&str] = &[
5252
"DELETE FROM transactions;",
5353
"DELETE FROM utxos;",
5454
"DROP INDEX idx_txid_vout;",
55-
"CREATE UNIQUE INDEX idx_utxos_txid_vout ON utxos(txid, vout);"
55+
"CREATE UNIQUE INDEX idx_utxos_txid_vout ON utxos(txid, vout);",
56+
"BEGIN TRANSACTION;\
57+
ALTER TABLE utxos RENAME TO utxos_old;\
58+
CREATE TABLE utxos (value INTEGER, keychain TEXT, vout INTEGER, txid BLOB, script BLOB, is_spent BOOLEAN DEFAULT 0);\
59+
INSERT INTO utxos SELECT value, keychain, vout, txid, script, is_spent FROM utxos_old;\
60+
DROP TABLE utxos_old;\
61+
CREATE UNIQUE INDEX idx_utxos_txid_vout ON utxos(txid, vout);\
62+
COMMIT;"
5663
];
5764

5865
/// Sqlite database stored on filesystem

0 commit comments

Comments
 (0)