Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB migration and thisAndFuture addition #45

Merged
merged 4 commits into from Jan 25, 2023

Conversation

dcaliste
Copy link
Contributor

It's a follow-up of the discussion from #43 .

Trying to make the migration to version with thisAndFuture column, I found that the initial implementation of the thisAndFuture column was wrong. It created different table schema for migrated DB and new DB, thus the INSERT, the UPDATE and the SELECT were wrong, or let say working only in one case... This should be fixed with the first commit, creating the new column always at the end for migrated or new DBs.

Then, as discussed in #43, I try to make the migration steps as atomic as possible, making the write immediate and setting the pragma there, immediately after the DB changes. This is the third commit.

The second commit is a minor simplification when I noticed that the SL3_exec macro was filtering out the constraint errors for the sole purpose of inserting at each opening an existing empty timezone.

When I tested, I noticed that if you delete the default notebook, then the DB has no default notebook anymore (even if it still contains various other notebooks) and this breaks a lot of assertions in the tests. I think it's not a big deal to always create a default notebook on opening. On device, there is already a default notebook (the "private" one), so it should not create additional notebooks.

I tested these changes with an old user_version = 0 DB and with a DB created on the fly by the tests. @pvuorela tell me what do you think about these changes.

src/sqlitestorage.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@pvuorela pvuorela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second commit "An empty timezone is a no-op in SqliteFormat::loadTimezones()." should be SqliteStorage::Private::loadTimezones(), I suppose.

Good that we got back to discussing this. Indeed need to remember to add new columns to the end.

Commented on renaming the extra1, but could be also eventually get rid of the unused extras. In retrospect suppose the extra3 could have been renamed to thisAndFuture. But the renamings/drops will also require a version bump so maybe do that separately, independent change or together with some later adjustement.

So far looking good, I'll do some more test round

src/sqliteformat.cpp Show resolved Hide resolved
@pvuorela
Copy link
Contributor

Created JB#59982 for fixing the column placement. Can use that for reference.

…JB#59982

The INSERT and UPDATE sharing the same code in
sqliteformat.cpp, and INSERT relying on column
order, new column should be added at the end in
the CREATE statement. Otherwise, there is a
difference between migrated DBs where the new
column is at the end and new DBs where the column
has been added in the middle of other columns.

Correct this issue for the new thisAndFuture column.
An empty timezone is a no-op in
SqliteFormat::Private::loadTimezones().

This allows to remove the constraint exception
on error check in macro SL3_exec().
Commit changes immediately after migration to the next
version and bump user_version as soon as possible to
avoid the database being migrated but the pragma not
being in sync with the DB status.

Don't fail on migration error when adding a new column,
assuming that the column may already exists.
Operations like addEvent(KCalendarCore::Event) requires
a default notebook to exist. Change a bit the initialisation
to create a default notebook if none exists, instead of
doing it only when the DB is empty.
@dcaliste
Copy link
Contributor Author

should be SqliteStorage::Private::loadTimezones(), I suppose.

Indeed, corrected in the commit message.

Created JB#59982 for fixing the column placement.

Thanks, bug id added in the corresponding commit.

In retrospect suppose the extra3 could have been renamed to thisAndFuture.

Indeed, but since you introduced a way to migrate the database, I was tempted to use it since it avoids to get things behind names like extra3 and make the commit and the code in general more clear. But finally it ended up in two separated commits. Not sure it is clearer !

@pvuorela
Copy link
Contributor

Alright, let's have this.

@pvuorela pvuorela merged commit af0791f into sailfishos:master Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants