Merge #595: db: keep NOT NULL constraint on is_immature in migration

64df2a15a2ab8c6c0ddd97a90fb3e4b8cc66ce13 db: keep NOT NULL constraint on is_immature in migration (Antoine Poinsot)

Pull request description:

  As suggested by Edouard in https://github.com/wizardsardine/liana/pull/578/files#r1285476881 there is no reason not to keep the `NOT NULL` constraint. I also added the `CHECK .. IN (0, 1)`.

  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.

ACKs for top commit:
  edouardparis:
    utACK 64df2a15a2ab8c6c0ddd97a90fb3e4b8cc66ce13

Tree-SHA512: 28ab4426b18d139bd1d53d017fb667db20ec0e997b61d6ed6afeae0c006697b737bed1fa8e158813ad45fed98137af806c5a6b39d463d6cc0ff03318f64e5943
This commit is contained in:
Antoine Poinsot 2023-08-09 15:50:49 +02:00
commit b205a25ed9
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![])?;