HomePhabricator
Diffusion Comm 9fb5c0c2f74c

[native/sqlite] add `NOT NULL` constraint to `drafts` table

Description

[native/sqlite] add NOT NULL constraint to drafts table

Summary:
Motivation

  1. Purpose is to enhance DB schema and add NOT NULL everywhere where NULL is not expected since SQLite by default accepts null values. task
  2. Instead of running all migrations to create database even on a fresh install (task) there is possibility to infer model from sqlite_orm, while orm itself deduce where types are not nullish there will be inconsistency (orm will generate NOT NULL clause in places where it should be).

Implementation
There is no ALTER COLUMN or any more straightforward method to do it, this solution is suggested by SQLite docs: https://www.sqlite.org/lang_altertable.html#making_other_kinds_of_table_schema_changes.

Why this change

  1. key and text fields are std::string and as a result they can not be assigned to null (it's not the same as empty string), so NULL should not appear in DB.
  2. In CommCoreModule while adding something do drafts table we use asString method which will return string or throw error.

Test Plan:

  1. Use decoded SQLite (e.g. comment encryption code and re-install app)
  2. Add some drafts
  3. Run this code and restart app to run migration
  4. Connect to database (path should be logged) by sqlite3 and run .schema drafts to check if the constraint is added.
  5. Check if created drafts are correctly saved.

Reviewers: tomek, jon, atul, karol, marcin

Reviewed By: tomek, marcin

Subscribers: ashoat, atul, abosh

Differential Revision: https://phab.comm.dev/D5144

Details

Provenance
kamilAuthored on Sep 15 2022, 5:35 AM
Reviewer
tomek
Differential Revision
D5144: [native/sqlite] add `NOT NULL` constraint to `drafts` table
Parents
rCOMMd1d82f4ef167: [web] Make `AddMembersList` more universal
Branches
Unknown
Tags
Unknown