db: Make 'text' field in 'comments' table NOT NULL and handling data migration
Checklist
- [x] All new and existing tests are passing
- [x] I have added an entry to
CHANGES.rstbecause this is a user-facing change or an important bugfix - [x] I have written proper commit message(s)
What changes does this Pull Request introduce?
This update introduces a schema migration to version 4 for the database, focusing on enhancing the 'comments' table. This ensures that the 'text' field in the 'comments' table will always have a value, which improves data consistency and integrity.
The key changes:
- Incrementing the database schema version from 3 to 4.
- Updating the "text" field in the "comments" table to be NOT NULL by setting empty strings for any NULL values.
- Creating a new table, "comments_new", with a NOT NULL constraint on the "text" field and then migrating data from the old "comments" table to this new table.
- Renaming the original "comments" table to "comments_backup_v3" for backup purposes and renaming "comments_new" to "comments" to finalize the migration.
- The migration process includes transaction handling to ensure data integrity, with a rollback in case of any errors during the migration.
Why is this necessary?
- https://github.com/isso-comments/isso/issues/979
- https://github.com/isso-comments/isso/pull/994
Nice effort, thank you.
I noticed that these lines should have been a migration as well:
https://github.com/isso-comments/isso/blob/27bdc72a5e2f4e6ae0a9fd506225774ae4ed711f/isso/db/comments.py#L44-L47
Could you add them while you're at it?
Thanks for the review. I have added the suggested changes. I will do squash commits once the code review is complete.
@ix5 Thank you for your suggestions. I've made the changes.
Squashed (pushed to your branch) and merged.
I have a few changes that I wrote and stashed locally when reviewing this, but that's for another day. This PR is a great improvement that allows for more confidence when releasing the next version.
Great, thank you.