-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Sync metadata generate migrations #2864
Conversation
TODOs/FIXMEs:
|
590a3b3
to
8bc5096
Compare
@@ -41,3 +44,22 @@ export const mapObjectMetadataByUniqueIdentifier = ( | |||
return acc; | |||
}, {}); | |||
}; | |||
|
|||
export const convertStringifiedFieldsToJSON = (fieldMetadata) => { |
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.
Maybe introduce a type: FieldMetadataFormattedForDiff
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 agree with @charlesBochet 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.
Great work! We will keep cleaning the code :)
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.
Great work ! :)
server/src/workspace/workspace-sync-metadata/decorators/metadata.decorator.ts
Show resolved
Hide resolved
server/src/workspace/workspace-sync-metadata/decorators/metadata.decorator.ts
Show resolved
Hide resolved
server/src/workspace/workspace-sync-metadata/decorators/metadata.decorator.ts
Show resolved
Hide resolved
server/src/workspace/workspace-sync-metadata/decorators/metadata.decorator.ts
Show resolved
Hide resolved
@@ -41,3 +44,22 @@ export const mapObjectMetadataByUniqueIdentifier = ( | |||
return acc; | |||
}, {}); | |||
}; | |||
|
|||
export const convertStringifiedFieldsToJSON = (fieldMetadata) => { |
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 agree with @charlesBochet on this
Context
We are introducing a new way to define standard object-metadata, this is a follow-up from #2807
This PR introduces relation setup using the same class and run the necessary migrations after the sync of metadata.
We will improve the documentation to explain how to add or edit standard objects.
yarn command workspace:sync-metadata -w "20202020-1c25-4d02-bf25-6aeccf7ea419"
should now call the new service and only update necessary objects/fields and run the migrations accordingly. A few things are not fully implemented yet such as migration updates/delete, I left a few TODO in the code.Important note: For objects and fields, I'm using their names as the key to run the diff, I'm using a map to simplify the diff and ensure we don't have any issue with ordering. This might not a good idea in the long run because if we want to change the name of an object or a field, the diff will interpret it as a different object/field and will run a CREATE/REMOVE instead of CHANGE action.
Note2: relationMetadata does not contain an isCustom field, we should add it before exposing relations to the API because the sync-metadata service should only affect non-custom entities and we have no easy way to filter them out as of today
Note3: I use stringify sometimes for the diff, this is because we sometimes store jsonb, for example targetColumnMap, defaultValues, options, etc... then I have to parse again before saving in DB, this could be improved in the future for readability
Here is an example of how you can use the new class. Note that extending BaseObjectMetadata will generate default fields such as ['id', 'createdAt', 'updatedAt']