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

Remove dexie version bump requirement for new game additions #1373

Merged
merged 1 commit into from
Aug 19, 2024

Conversation

ethangreen-dev
Copy link
Contributor

This PR primarily implements a way to track settings without requiring each game to exist as an independent table. This is done by, simply, moving everything to a new games table, by which each game is a row, indexable by setting identifier.

This also removes code that migrated the legacy settings store to v2, but don't fret, I've replaced it with migration code that converts v2 game tables to the new v3 row entries.

src/r2mm/manager/SettingsDexieStore.ts Outdated Show resolved Hide resolved
src/r2mm/manager/SettingsDexieStore.ts Outdated Show resolved Hide resolved
src/r2mm/manager/SettingsDexieStore.ts Outdated Show resolved Hide resolved
@ethangreen-dev ethangreen-dev marked this pull request as ready for review June 22, 2024 17:48
Copy link
Collaborator

@anttimaki anttimaki left a comment

Choose a reason for hiding this comment

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

I know this is a bit late on the second review round, but did you consider using Version.upgrade to do all this in one fell swoop, thus not requiring run-time checkups?

Copy link
Collaborator

@anttimaki anttimaki left a comment

Choose a reason for hiding this comment

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

Overall looks okay and I tested this locally so works on my PC. Left a few nitpick/opinion comments in case the Version.upgrade() approach doesn't pan out.

src/r2mm/manager/SettingsDexieStore.ts Outdated Show resolved Hide resolved
src/r2mm/manager/SettingsDexieStore.ts Outdated Show resolved Hide resolved
src/r2mm/manager/SettingsDexieStore.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@anttimaki anttimaki left a comment

Choose a reason for hiding this comment

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

For me this doesn't work as expected, see the comments. I guess valid approaches would be:

  1. Fix this one way or another to actually persist existing settings upon migration
  2. Clean out the ineffective data migration code, effectively just resetting the game specific settings
  3. Fall back using the older approach which didn't use Version.upgrade()

src/r2mm/manager/SettingsDexieStore.ts Outdated Show resolved Hide resolved
src/r2mm/manager/SettingsDexieStore.ts Outdated Show resolved Hide resolved
This commit primarily implements a way to track settings without
requiring each game to exist as an independent table. This is done by,
simply, moving everything to a new `games` table, by which each game is
a row, indexable by each's setting identifier.

This commit also removes code that migrated the legacy settings store to
v2, but don't fret, I've replaced it with migration code that converts
v2 game tables to the new v3 row entries.

feat: add legacy table clear, remove old migration code

chore: resolve PR review comments
- Replace occurences of `==` with customary `===`.
- Remove transaction wrapper from `applyV2ToV3Migration`
- Invert logic of `getLatestGameSpecific` to reduce nesting and catch
  case where `game === undefined` and `applyV2ToV3Migration === true`.

feat: move migration code to `Version.upgrade`

This should ideally handle the migration from < 75 versions to 75
automatically at runtime, thus removing the need to integrate the
migration routine into `getLatestGameSpecific`.

Legacy game tables are not entirely removed, but they are cleared
and, thanks to `Version.upgrade`, should not cause any future problems.

chore: code cleanup - remove trailing whitespace, imports, debug log
Copy link
Collaborator

@anttimaki anttimaki left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:

Tested locally and works for me:

  • Migrating to the new schema and persisting the existing settings
  • Creating a new settings row when a game is accessed for the first time
  • Adding new games does not require a schema version bump

const identifier = this.activeGame.settingsIdentifier;
const game = await this.games.get(identifier);

if (game !== undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: NGL I'm a tiny bit irked that the gameSpecific checks !== undefined while the corresponding code for global settings checks === undefined 🙈

@anttimaki anttimaki merged commit 447b733 into ebkr:develop Aug 19, 2024
1 check 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.

2 participants