-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add DB schema check and instructions for updating the schema version #219
base: main
Are you sure you want to change the base?
Conversation
|
9a6ebed
to
d2f53fa
Compare
.sort((a, b) => (a.name < b.name ? 1 : -1)), | ||
); | ||
|
||
const hasSchemaChanged = async (db: Dexie) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have some tests for this. Feels like it could be a finicky process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do! that's an easy add, it's just a string comparison.
await db.open(); | ||
if (await hasSchemaChanged(db)) { | ||
throw new Error( | ||
`The local DB schema has changed and must be upgraded. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we only changing the schema on major version's? Seems like that is a requirement, given it requires an explicit user migration to update their schema version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good question and something i've thought about a lot. sometimes adding a new feature requires a schema change, but adding to the schema doesn't usually create an issue. it's only when updating/removing an existing schema that requires a new version.
that being said, having to add/update a component prop for an SDK update could be considered a breaking change in that it does require a code change. however, it's not an involved refactor, usually just a single character change. is that a breaking change? i could be convinced that it is... or isn't.
ideally, this is something that we would manage internally so that developers don't have to think about it. how we're currently managing the schema for content type caching makes this more difficult since we're not storing all versions of the schema over time.
i'm definitely open to going down this route. it was something i originally considered but went with a simpler solution at the time.
import App from "./App.tsx"; | ||
|
||
export const MyApp: React.FC = () => ( | ||
<XMTPProvider dbVersion={2}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when I increment this version? Is it going to wipe out my entire local DB and force re-create it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just informs Dexie about the new schema so it understands how to work with the data. the current DB and its data should remain intact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when you set the dbVersion
to 2
, did you have another tab open with the app? i haven't encountered that error yet, but this issue may provide some insight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's strange. chrome shouldn't affect firefox and vice versa.
Summary
When the local DB schema is updated as part of a code change in the React SDK, client apps must upgrade their schema version to include the changes. To help with this, instructions and a DB schema check have been added. If the schema check detects change, it will throw an error that informs app developers to upgrade the schema version.