-
Notifications
You must be signed in to change notification settings - Fork 14
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
MIG-85: implemented changes for partial migrations and fixed broken tests #379
Conversation
@@ -233,15 +237,36 @@ class Study extends Task { | |||
|
|||
Usage: | |||
|
|||
mdctl study [command] | |||
mdctl study [command] --manifestObject |
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.
given that we are adding this option to the CLI too may be we can call it manifest
instead of manifestObject
to make it consistent with the manifest
option in mdctl env export|import
command , what do you think?
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.
hi @nahueld I had that one initially, but weirdly it was somehow causing issues when generating the final manifest, so I decided to adopt a different name to avoid this
packages/mdctl-cli/tasks/study.js
Outdated
|
||
Options | ||
|
||
--manifestObject - receives a valid manifest JSON object or the path to a manifest file |
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.
I'd add that this is only valid during export
command, and it can only contain object instances, other org config objects can be exported through regular mdctl env export
command
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.
hi @nahueld , I added that in the "Notes" section but it makes sense to have it as part of the explanation of this flag. Thanks for that
@@ -22,6 +23,33 @@ class StudyManifestTools { | |||
}) | |||
} | |||
|
|||
validateManifest(manifestObject) { |
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.
IMO this function should be more of a responsibility of the study.js
module, this will decoupled "parsing"/"reading" the manifest that is ultimately an option passed to the CLI command, the buildManifestAndDependencies
should receive the manifest as a plain javascript object directly, validations on reading the file or performing a JSON.parse() can be done outside to fail first. what is your take on this?
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.
In the other hand this validation could be left here
if (!manifestJSON.object || manifestJSON.object !== 'manifest') {
throw Fault.create('kInvalidArgument', { reason: 'The argument is not a valid manifest' })
}
So basically:
- reading/parsing to the upper layer (CLI)
- making sure that that json is a manifest looks ok in here
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 makes sense, I will move the function in study.js and make sure the manifest is ok in here. Thanks for the advise ;)
if (manifestObject) { | ||
manifestJSON = this.validateManifest(manifestObject) | ||
|
||
ignoreKeys = Object.keys(manifestJSON).filter(key => typeof manifestJSON[key] === 'object') |
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.
I think this one can be improved slightly, overall it should work but we can make more secure
- Notice that arrays are also considered objects so it will pick up the "objects" from the manifest if passed through, this should not happen but it may be a good idea to account for incorrect usage
- I'd add part of this to
validateManifest
and may be rename it tovalidateAndCleanManifest
For example, inside validateAndCleanManifest:
return Object.keys(manifestJSON)
.filter(key => availableObjectNames.includes(key))
.reduce((acc,curr) => ({ ...acc, [curr]: manifestJSON[curr] })
The variable availableObjectNames can be this array that is somewhere else actually:
['c_study', 'c_task', 'c_visit_schedule', 'ec__document_template', 'c_group',
'c_anchor_date_template', 'c_fault', 'c_dmweb_report', 'c_site', 'c_task_assignment', 'c_participant_schedule',
'c_patient_flag', 'c_looker_integration_record', 'int__vendor_integration_record', 'int__model_mapping',
'int__pipeline', 'orac__studies', 'orac__sites', 'orac__forms', 'orac__form_questions', 'orac__events']
In the end we should only support granular export of these
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.
Finally if you decide to go with the approach above, the calculation of ignoreKeys can be simplified to:
ignoreKeys = Object.keys(manifestJSON)
.map(key => this.mapObjectNameToPlural(key))
async getStudyManifestEntities(org, study, manifestObject, orgReferenceProps) { | ||
const manifestEntities = [], | ||
// Define the available entities to export or get them from the manifest in input | ||
manifestKeys = (study) |
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.
By applying the refactors mentioned above, this line would be:
manifestKeys = study ? this.availableObjectNames : Object.keys(manifestObject)
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 are good to go
Unit tests will be added once the current approach is confirmed