Skip to content

do not change db schema in an incompatible way#5254

Merged
r10s merged 3 commits intomainfrom
r10s/keep-compatibility-with-previous-versions
Feb 13, 2024
Merged

do not change db schema in an incompatible way#5254
r10s merged 3 commits intomainfrom
r10s/keep-compatibility-with-previous-versions

Conversation

@r10s
Copy link
Copy Markdown
Contributor

@r10s r10s commented Feb 7, 2024

PR #5099 removed some columns in the database that were actually in use.

usually, to not worsen UX unnecessarily
(releases take time - in between, "Add Second Device", "Backup" etc. would fail), we try to avoid such schema changes (checking for db-version would avoid import etc. but would still worse UX),
see discussion at #2294.

these are the errors, the user will be confronted with otherwise:

it is not great to maintain the old columns, but well :)

as no official releases with newer cores are rolled out yet, i think, it is fine to change the "107" migration
and not copy things a second time in a newer migration.

(this issue happens to me during testing, and is probably also the issue reported by @lk108 for ubuntu-touch)

@r10s r10s added the bug Something is not working label Feb 7, 2024
@r10s r10s requested review from iequidoo and link2xt February 7, 2024 22:19
@link2xt
Copy link
Copy Markdown
Collaborator

link2xt commented Feb 7, 2024

Where this column is used? Does this only happen if you import a new backup into old Delta Chat core and then it tries to use the column?

@link2xt
Copy link
Copy Markdown
Collaborator

link2xt commented Feb 7, 2024

I don't think changing existing migration is a good idea. If needed we can add a migration restoring the column on top of this, but otherwise it will break backups of anyone who imported them into nightly.

Also I run the latest core and @hpk42 probably runs the latest core on desktop, if we change existing migration this means database should be manually modified by anyone running core this way.

@iequidoo
Copy link
Copy Markdown
Collaborator

iequidoo commented Feb 7, 2024

Also I run the latest core and @hpk42 probably runs the latest core on desktop, if we change existing migration this means database should be manually modified by anyone running core this way.

But in this case it should be modified only if you are going to import the db to the older version, no? Which you are probably not going to do. We just should keep in mind that there are some db-s with these columns absent.

@link2xt
Copy link
Copy Markdown
Collaborator

link2xt commented Feb 7, 2024

Also some databases will have old_keypairs table and some will not?

as no official releases with newer cores are rolled out yet

These changes have been released in core 1.133.0 and there are bots running with this core.

@adbenitez
Copy link
Copy Markdown
Collaborator

I already released a DeltaLab version yesterday with core from yesterday, just overriding the migration will cause issues I am afraid?

@adbenitez
Copy link
Copy Markdown
Collaborator

I don't think changing existing migration is a good idea. If needed we can add a migration restoring the column on top of this,

+1000

@r10s
Copy link
Copy Markdown
Contributor Author

r10s commented Feb 7, 2024

Where this column is used? Does this only happen if you import a new backup into old Delta Chat core and then it tries to use the column?

it is used in cores v1.131.9 and below, so on virtually all released versions, that will break eg. when they get a second-device-database or backup from the upcoming version.

iirc, in comparable previous column-removals, we removed only columns that are not in use.

so, eg. using add-second-device from and andorid-1.44 to an desktop-1.42 (or the other way round) won't work. same for backups or just downgrading as 1.44 has issues that will be fixed in 1.44.1 or so.

for changing the existing migration: i was not aware that it is that widely in use, i thought more about some devs, i am also running current cores on many devices :) bots usually do not do add-second-device or downgrades. the only difference to the changed-107 would be that these devs/bots already have the three columns removed. in a later migration, we could remove the columns for all.

however, i am also fine to close/change this pr and go for another migration, just thought it is not worth the effort (and potentially added bugs :) (/me afk for now, so if someone wants to take over, feel free to commit/close, otherwise i can have a look tomorrow)

@lk108
Copy link
Copy Markdown
Contributor

lk108 commented Feb 8, 2024

I know of at least one user who is running core v1.134.0 on desktop and the most recent DeltaLab. They wanted to add an account to their Ubuntu Touch device, and got the error in the screenshot above. They thought their Ubuntu Touch setup was broken and wiped their entire DeltaTouch config on Ubuntu Touch. All of their accounts are completely on the v1.1.34.0 scheme by now, older backups may not be available.

@link2xt
Copy link
Copy Markdown
Collaborator

link2xt commented Feb 8, 2024

We also cannot just restore old_keypairs as it is outdated for anyone using new core, this one should be dropped in any case.

I would suggest that we solve this by adding a new migration that adds empty addr column and fill it in housekeeping so it is updated right before backup export and we avoid adding anything other than SQL to migrations.

PR #5099 removed some columns in the database that were actually in use.

usually, to not worsen UX unnecessarily
(releases take time - in between, "Add Second Device", "Backup" etc. would fail),
we try to avoid such schema changes,
see discussion at #2294.

there as still some situations imaginable,
where things cause problems, however, the vast majority of real-life cases
should be fine.

as no official releases with newer cores are rolled out yet,
i think, it is fine to change the "107" migration
and not copy things a second time in a newer migration.
@r10s r10s force-pushed the r10s/keep-compatibility-with-previous-versions branch from 970db1b to 8088333 Compare February 13, 2024 16:19
@r10s
Copy link
Copy Markdown
Contributor Author

r10s commented Feb 13, 2024

thinking it over, the sometimes missing columns would cause troubles also when keypairs are added on these systems.

so, i added a commit that re-adds the columns in a new migration, filling it the same way as it was used for migration 107 - maybe i've overseen sth, but to me it looks as if housekeeping is not needed. also did some little tests using the repl tool

when this is merged, we should do a new core so a 1.43.1 can be done for android/ios-testflight

@r10s r10s requested a review from iequidoo February 13, 2024 17:40
// otherwise "add second device" or "backup" may break.
// moreover, this allows downgrades to the previous version.
// writing of `addr` and `is_default` can be removed ~ 2024-08
let addr = keypair.addr.to_string();
Copy link
Copy Markdown
Collaborator

@iequidoo iequidoo Feb 13, 2024

Choose a reason for hiding this comment

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

Is to_string() really needed here?

Copy link
Copy Markdown
Contributor Author

@r10s r10s Feb 13, 2024

Choose a reason for hiding this comment

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

idk - i did not wanted to optimise code but just do what was done before to protect against further side effects :)

the code is subject to be removed in some months anyways

sql.execute_migration(
"ALTER TABLE keypairs ADD COLUMN addr TEXT DEFAULT '' COLLATE NOCASE;
ALTER TABLE keypairs ADD COLUMN is_default INTEGER DEFAULT 0;
ALTER TABLE keypairs ADD COLUMN created INTEGER DEFAULT 0;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

created column is not used even by old versions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i am not sure, therefore just played safe :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i just checked, it was never read but written in store_self_keypair() - therefore it is needed

@r10s r10s merged commit 9135cff into main Feb 13, 2024
@r10s r10s deleted the r10s/keep-compatibility-with-previous-versions branch February 13, 2024 22:00
r10s added a commit that referenced this pull request Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something is not working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants