-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: settings migration #371
Conversation
src/main.ts
Outdated
@@ -198,9 +198,9 @@ const createWindow = async () => { | |||
app.whenReady().then(async () => { | |||
await initSettings() | |||
appSettings = await getSettings() | |||
nativeTheme.themeSource = appSettings.appearance.theme | |||
nativeTheme.themeSource = appSettings.general.appearance.theme |
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.
Changes in this file are intended for testing purposes and will be reverted before merging.
case '1.0': | ||
return migrate(v1.migrate(settings)) | ||
case '2.0': | ||
return settings |
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.
This function will run recursively until the latest version of the schema is reached.
export function migrate( | ||
settings: z.infer<typeof AppSettingsSchema> | ||
): v2.AppSettings { |
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.
Every schema should export a migrate
function that takes the current version and returns the next.
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.
LGTM! Will have another look once test commit is removed
src/types/settings.ts
Outdated
@@ -3,7 +3,7 @@ import { | |||
ProxySettingsSchema, | |||
RecorderSettingsSchema, | |||
UsageReportSettingsSchema, | |||
} from '@/schemas/appSettings' | |||
} from '@/schemas/settings/v2' |
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.
To avoid updating imports every time we introduce a new version we should add export to schemas/settings/index.ts
export * from './v2'
This reverts commit 5fb2026.
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.
@e-fisher The test commit has been reverted.
export const AppSettingsSchema = z.object({ | ||
version: z.literal('2.0'), |
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.
This is the same as v1, but I left some breadcrumbs to help us with the first migration when the time comes so no functional change at this time.
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.
LGTM! 👍
Description
This PR adds migrations to the settings schema, ensuring that changes to its structure remain backward-compatible. This allows the settings to work properly even when the schema is updated.
The same pattern will be applied to the Generator schema on a separate PR.
How to Test
This PR contains one extra commit that is intended to be used for testing purposes and will be reverted before merging.
Before testing this branch, make sure your local settings file (
k6-studio-dev.json
) containsusageReport.enabled
false
andappearance.theme
aslight
so you can validate the changes.Once the settings are saved, the file structure should look like this instead:
Checklist
npm run lint
) and all checks pass.npm test
) and all tests pass.Screenshots (if appropriate):
Related PR(s)/Issue(s)
Resolves #265