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
fixes 2-456: Preserve all data from strategy import #2720
fixes 2-456: Preserve all data from strategy import #2720
Conversation
Previously the strategy was to use the IMinimalStrategyRow. This PR changes to use the full data from the export in the import. * Discussion point: Should we see if we can add some invariants to our import/export so that we can write some proptests for it. One candidate is commutativity of import/export. On a fresh database importing and then exporting should yield the same file that was imported provided all flags are turned on
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
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.
Looks good, just 2 small comments
@@ -23,6 +23,16 @@ export interface IMinimalStrategy { | |||
parameters?: any[]; | |||
} | |||
|
|||
export interface IStrategyImport { |
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.
Looking at IMinimalStrategy
there's a missing property in IStrategyImport
:
editable?: boolean
Just checking if this is intentional
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.
Yeah, we call it builtIn in the export as well as built_in in the table. where editable is built_in === 0
. Unfortunately built_in is still an integer in our table for some reason :)
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.
Oh, I just checked the previous code using
unleash/src/lib/db/strategy-store.ts
Lines 127 to 133 in be045dc
eventDataToRow(data): IMinimalStrategyRow { | |
return { | |
name: data.name, | |
description: data.description, | |
parameters: JSON.stringify(data.parameters), | |
}; | |
} |
and I see that editable
although present in the type was completely ignored 👍
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.
yup :(
What
Previously when importing strategies we've used the same data type we've used for creating strategies (the minimal, a name, an optional description, optional parameters and an optional editable column). This meant that exporting strategies and then importing them would reactivate deprecated strategies. This PR changes to allow the import to preserve all the data coming in the export file.
Tests
Added four new tests, two new unit tests using our fake stores and two new e2e tests. Interestingly the ones in the fake store ran green before this change as well, probably because we just insert the parsed json object in the fake store, whereas the real store actually converts the object from camelCasing to the postgresql snake_casing standard.
Discussion points:
Mismatch between fake and real stores
This is inevitable since storing things in javascript arrays vs saving in a real database will have some differences, but this again shows the value of our e2e tests.
Invariants
Should we see if we can add some invariants to our import/export so that we can write some proptests for it? One candidate is commutativity of import/export. On a fresh database importing and then exporting should yield the same file that was imported provided all flags are turned on. Candidate for Q1 improvement of import/export.