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

Fix migrations 1 #1446

Merged
merged 5 commits into from Mar 11, 2024
Merged

Fix migrations 1 #1446

merged 5 commits into from Mar 11, 2024

Conversation

dessalines
Copy link
Member

@dessalines dessalines commented Mar 11, 2024

Okay, I strongly typed all our default values, and double checked the column order (2 were in the wrong place iirc).

It'd be good if you could test this also, just to be sure it doesn't break existing installs.

@dessalines dessalines requested a review from MV-GH as a code owner March 11, 2024 15:22
// don't allow it
//
// Use Int for Bools
const val DEFAULT_THEME = 0
Copy link
Member Author

Choose a reason for hiding this comment

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

I really wanted to be able to use the Enums and ordinals here, but Room makes you use constants for their currentValue annotations.

@MV-GH
Copy link
Collaborator

MV-GH commented Mar 11, 2024

There is a test in AndroidTest that goes through the migrations to ensure it doesn't fail on migrating between versions but I will test it regardless.

"""
CREATE TABLE IF NOT EXISTS AppSettingsBackup (
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
`font_size` INTEGER NOT NULL DEFAULT ${DEFAULT_FONT_SIZE},
Copy link
Collaborator

@MV-GH MV-GH Mar 11, 2024

Choose a reason for hiding this comment

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

You can't do something like this, the migrations need to stay exactly the same.

If we make migration version 33, say we change a default.

We change the constant and now we have also changed migration of 32.

Room will rightly throw a error that the checksum of migration 32 mismatches. Because that means that some users their db schema 32 is different. That can be very problematic

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, can change them.

@MV-GH
Copy link
Collaborator

MV-GH commented Mar 11, 2024

Which columns where in the wrong place?

edit:

I see how I did the order wrong, I was basing the order on the order of the alter statements that added the columns

But If I look into the schemas, they are completely different. We should always explicitly set which columns maps to which to prevent subtle bugs like this to occur again.

db.execSQL("ALTER TABLE AppSettingsBackup RENAME to AppSettings")

// Reset a few messups to default
db.execSQL("UPDATE AppSettings SET post_actionbar_mode = $DEFAULT_POST_ACTION_BAR_MODE")
Copy link
Collaborator

@MV-GH MV-GH Mar 11, 2024

Choose a reason for hiding this comment

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

There are probably more but only the enums matter, bc if they get assigned a value bigger than their enum size (due swapping between two enums which have different size and that user having the biggest value) it would cause a NPE when we map the int to enum

Copy link
Collaborator

@MV-GH MV-GH Mar 11, 2024

Choose a reason for hiding this comment

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

Imo this should be sufficient unless you want to reset more enums.

@dessalines
Copy link
Member Author

iirc the two out of place, were show_collapsed_comment_content, and post_action_bar_mode . I'll fix it so that the migration doesn't use these defaults tho.

@dessalines dessalines marked this pull request as draft March 11, 2024 20:18
@dessalines dessalines marked this pull request as ready for review March 11, 2024 20:24
Copy link
Collaborator

@MV-GH MV-GH left a comment

Choose a reason for hiding this comment

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

Linter, looks good else

@dessalines
Copy link
Member Author

K, I'll get a release out after its merged.

@dessalines dessalines enabled auto-merge (squash) March 11, 2024 21:07
@dessalines dessalines merged commit 8d12d56 into main Mar 11, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants