db: keep NOT NULL constraint on is_immature in migration

This adds an extraneous DEFAULT compared to the schema in freshly
created databases, but anything else (altering the column in an
SQLite-friendly way after setting all NULL values to 0) would be way too
involved.
This commit is contained in:
Antoine Poinsot 2023-08-07 13:24:30 +02:00
parent 39d576fe83
commit 64df2a15a2
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304

View File

@ -170,11 +170,7 @@ fn migrate_v0_to_v1(conn: &mut rusqlite::Connection) -> Result<(), SqliteDbError
fn migrate_v1_to_v2(conn: &mut rusqlite::Connection) -> Result<(), SqliteDbError> {
db_exec(conn, |tx| {
tx.execute(
"ALTER TABLE coins ADD COLUMN is_immature",
rusqlite::params![],
)?;
tx.execute(
"UPDATE coins SET is_immature = 0 WHERE is_immature IS NULL",
"ALTER TABLE coins ADD COLUMN is_immature BOOLEAN NOT NULL DEFAULT 0 CHECK (is_immature IN (0,1))",
rusqlite::params![],
)?;
tx.execute("UPDATE version SET version = 2", rusqlite::params![])?;