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

MIG-85: implemented changes for partial migrations and fixed broken tests #379

Merged
merged 8 commits into from
Jun 7, 2022

Conversation

davideaquaro
Copy link
Contributor

Unit tests will be added once the current approach is confirmed

@@ -233,15 +237,36 @@ class Study extends Task {

Usage:

mdctl study [command]
mdctl study [command] --manifestObject
Copy link
Contributor

@nahueld nahueld Jun 3, 2022

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?

Copy link
Contributor Author

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


Options

--manifestObject - receives a valid manifest JSON object or the path to a manifest file
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

@nahueld nahueld Jun 3, 2022

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?

Copy link
Contributor

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

Copy link
Contributor Author

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')
Copy link
Contributor

@nahueld nahueld Jun 3, 2022

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

  1. 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
  2. I'd add part of this to validateManifest and may be rename it to validateAndCleanManifest

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

Copy link
Contributor

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)
Copy link
Contributor

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)

@davideaquaro davideaquaro changed the title DRAFT: (feat) implemented changes for partial migrations and fixed broken tests MIG-85: implemented changes for partial migrations and fixed broken tests Jun 7, 2022
Copy link
Contributor

@nahueld nahueld left a 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

@nahueld nahueld merged commit 2f9572a into Medable:develop Jun 7, 2022
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