[native/sqlite] add NOT NULL constraint to drafts table
Summary:
Motivation
- Purpose is to enhance DB schema and add NOT NULL everywhere where NULL is not expected since SQLite by default accepts null values. task
- 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
- 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.
- In CommCoreModule while adding something do drafts table we use asString method which will return string or throw error.
Test Plan:
- Use decoded SQLite (e.g. comment encryption code and re-install app)
- Add some drafts
- Run this code and restart app to run migration
- Connect to database (path should be logged) by sqlite3 and run .schema drafts to check if the constraint is added.
- 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