@contember/schema-migrations 2.1.0-beta.2 → 2.2.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/index.cjs +3 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +3 -0
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/MigrationDescriber.cjs.map +1 -1
- package/dist/development/src/MigrationDescriber.js.map +1 -1
- package/dist/development/src/SchemaDiffer.cjs +27 -12
- package/dist/development/src/SchemaDiffer.cjs.map +1 -1
- package/dist/development/src/SchemaDiffer.js +27 -12
- package/dist/development/src/SchemaDiffer.js.map +1 -1
- package/dist/development/src/SchemaMigrator.cjs.map +1 -1
- package/dist/development/src/SchemaMigrator.js.map +1 -1
- package/dist/development/src/modifications/ModificationHandler.cjs.map +1 -1
- package/dist/development/src/modifications/ModificationHandler.js.map +1 -1
- package/dist/development/src/modifications/ModificationHandlerFactory.cjs +2 -0
- package/dist/development/src/modifications/ModificationHandlerFactory.cjs.map +1 -1
- package/dist/development/src/modifications/ModificationHandlerFactory.js +2 -0
- package/dist/development/src/modifications/ModificationHandlerFactory.js.map +1 -1
- package/dist/development/src/modifications/NoopModification.cjs.map +1 -1
- package/dist/development/src/modifications/NoopModification.js.map +1 -1
- package/dist/development/src/modifications/acl/PatchAclSchemaModification.cjs.map +1 -1
- package/dist/development/src/modifications/acl/PatchAclSchemaModification.js.map +1 -1
- package/dist/development/src/modifications/acl/UpdateAclSchemaModification.cjs.map +1 -1
- package/dist/development/src/modifications/acl/UpdateAclSchemaModification.js.map +1 -1
- package/dist/development/src/modifications/actions/CreateTargetModification.cjs.map +1 -1
- package/dist/development/src/modifications/actions/CreateTargetModification.js.map +1 -1
- package/dist/development/src/modifications/actions/CreateTriggerModification.cjs.map +1 -1
- package/dist/development/src/modifications/actions/CreateTriggerModification.js.map +1 -1
- package/dist/development/src/modifications/actions/PatchTriggerModification.cjs.map +1 -1
- package/dist/development/src/modifications/actions/PatchTriggerModification.js.map +1 -1
- package/dist/development/src/modifications/actions/RemoveTargetModification.cjs.map +1 -1
- package/dist/development/src/modifications/actions/RemoveTargetModification.js.map +1 -1
- package/dist/development/src/modifications/actions/RemoveTriggerModification.cjs.map +1 -1
- package/dist/development/src/modifications/actions/RemoveTriggerModification.js.map +1 -1
- package/dist/development/src/modifications/actions/UpdateTargetModification.cjs.map +1 -1
- package/dist/development/src/modifications/actions/UpdateTargetModification.js.map +1 -1
- package/dist/development/src/modifications/actions/UpdateTriggerModification.cjs.map +1 -1
- package/dist/development/src/modifications/actions/UpdateTriggerModification.js.map +1 -1
- package/dist/development/src/modifications/columns/CreateColumnModification.cjs.map +1 -1
- package/dist/development/src/modifications/columns/CreateColumnModification.js.map +1 -1
- package/dist/development/src/modifications/columns/UpdateColumnDefinitionModification.cjs.map +1 -1
- package/dist/development/src/modifications/columns/UpdateColumnDefinitionModification.js.map +1 -1
- package/dist/development/src/modifications/columns/UpdateColumnNameModification.cjs.map +1 -1
- package/dist/development/src/modifications/columns/UpdateColumnNameModification.js.map +1 -1
- package/dist/development/src/modifications/columns/columnUtils.cjs.map +1 -1
- package/dist/development/src/modifications/columns/columnUtils.js.map +1 -1
- package/dist/development/src/modifications/constraints/CreateUniqueConstraintModification.cjs.map +1 -1
- package/dist/development/src/modifications/constraints/CreateUniqueConstraintModification.js.map +1 -1
- package/dist/development/src/modifications/constraints/RemoveUniqueConstraintModification.cjs.map +1 -1
- package/dist/development/src/modifications/constraints/RemoveUniqueConstraintModification.js.map +1 -1
- package/dist/development/src/modifications/differs/RemoveChangedFieldDiffer.cjs.map +1 -1
- package/dist/development/src/modifications/differs/RemoveChangedFieldDiffer.js.map +1 -1
- package/dist/development/src/modifications/differs/RemoveViewDiffer.cjs +4 -1
- package/dist/development/src/modifications/differs/RemoveViewDiffer.cjs.map +1 -1
- package/dist/development/src/modifications/differs/RemoveViewDiffer.js +5 -2
- package/dist/development/src/modifications/differs/RemoveViewDiffer.js.map +1 -1
- package/dist/development/src/modifications/differs/UpdateViewDiffer.cjs +45 -0
- package/dist/development/src/modifications/differs/UpdateViewDiffer.cjs.map +1 -0
- package/dist/development/src/modifications/differs/UpdateViewDiffer.js +45 -0
- package/dist/development/src/modifications/differs/UpdateViewDiffer.js.map +1 -0
- package/dist/development/src/modifications/entities/CreateEntityModification.cjs.map +1 -1
- package/dist/development/src/modifications/entities/CreateEntityModification.js.map +1 -1
- package/dist/development/src/modifications/entities/CreateViewModification.cjs.map +1 -1
- package/dist/development/src/modifications/entities/CreateViewModification.js.map +1 -1
- package/dist/development/src/modifications/entities/RemoveEntityModification.cjs.map +1 -1
- package/dist/development/src/modifications/entities/RemoveEntityModification.js.map +1 -1
- package/dist/development/src/modifications/entities/ToggleEventLogModification.cjs.map +1 -1
- package/dist/development/src/modifications/entities/ToggleEventLogModification.js.map +1 -1
- package/dist/development/src/modifications/entities/UpdateEntityNameModification.cjs.map +1 -1
- package/dist/development/src/modifications/entities/UpdateEntityNameModification.js.map +1 -1
- package/dist/development/src/modifications/entities/UpdateEntityOrderByModification.cjs.map +1 -1
- package/dist/development/src/modifications/entities/UpdateEntityOrderByModification.js.map +1 -1
- package/dist/development/src/modifications/entities/UpdateEntityTableNameModification.cjs.map +1 -1
- package/dist/development/src/modifications/entities/UpdateEntityTableNameModification.js.map +1 -1
- package/dist/development/src/modifications/entities/UpdateViewModification.cjs.map +1 -1
- package/dist/development/src/modifications/entities/UpdateViewModification.js.map +1 -1
- package/dist/development/src/modifications/enums/CreateEnumModification.cjs.map +1 -1
- package/dist/development/src/modifications/enums/CreateEnumModification.js.map +1 -1
- package/dist/development/src/modifications/enums/RemoveEnumModification.cjs.map +1 -1
- package/dist/development/src/modifications/enums/RemoveEnumModification.js.map +1 -1
- package/dist/development/src/modifications/enums/UpdateEnumModification.cjs.map +1 -1
- package/dist/development/src/modifications/enums/UpdateEnumModification.js.map +1 -1
- package/dist/development/src/modifications/enums/enumUtils.cjs.map +1 -1
- package/dist/development/src/modifications/enums/enumUtils.js.map +1 -1
- package/dist/development/src/modifications/fields/RemoveFieldModification.cjs.map +1 -1
- package/dist/development/src/modifications/fields/RemoveFieldModification.js.map +1 -1
- package/dist/development/src/modifications/fields/UpdateFieldNameModification.cjs +10 -4
- package/dist/development/src/modifications/fields/UpdateFieldNameModification.cjs.map +1 -1
- package/dist/development/src/modifications/fields/UpdateFieldNameModification.js +10 -4
- package/dist/development/src/modifications/fields/UpdateFieldNameModification.js.map +1 -1
- package/dist/development/src/modifications/indexes/CreateIndexModification.cjs +23 -7
- package/dist/development/src/modifications/indexes/CreateIndexModification.cjs.map +1 -1
- package/dist/development/src/modifications/indexes/CreateIndexModification.js +23 -7
- package/dist/development/src/modifications/indexes/CreateIndexModification.js.map +1 -1
- package/dist/development/src/modifications/indexes/RemoveIndexModification.cjs +52 -17
- package/dist/development/src/modifications/indexes/RemoveIndexModification.cjs.map +1 -1
- package/dist/development/src/modifications/indexes/RemoveIndexModification.js +52 -17
- package/dist/development/src/modifications/indexes/RemoveIndexModification.js.map +1 -1
- package/dist/development/src/modifications/relations/ConvertManyHasManyToJoiningEntityModification.cjs +140 -0
- package/dist/development/src/modifications/relations/ConvertManyHasManyToJoiningEntityModification.cjs.map +1 -0
- package/dist/development/src/modifications/relations/ConvertManyHasManyToJoiningEntityModification.js +140 -0
- package/dist/development/src/modifications/relations/ConvertManyHasManyToJoiningEntityModification.js.map +1 -0
- package/dist/development/src/modifications/relations/ConvertOneHasManyToManyHasManyRelationModification.cjs.map +1 -1
- package/dist/development/src/modifications/relations/ConvertOneHasManyToManyHasManyRelationModification.js.map +1 -1
- package/dist/development/src/modifications/relations/ConvertOneHasManyToOneHasOneRelationModification.cjs.map +1 -1
- package/dist/development/src/modifications/relations/ConvertOneHasManyToOneHasOneRelationModification.js.map +1 -1
- package/dist/development/src/modifications/relations/ConvertOneToManyRelationModification.cjs.map +1 -1
- package/dist/development/src/modifications/relations/ConvertOneToManyRelationModification.js.map +1 -1
- package/dist/development/src/modifications/relations/CreateRelationInverseSideModification.cjs.map +1 -1
- package/dist/development/src/modifications/relations/CreateRelationInverseSideModification.js.map +1 -1
- package/dist/development/src/modifications/relations/CreateRelationModification.cjs.map +1 -1
- package/dist/development/src/modifications/relations/CreateRelationModification.js.map +1 -1
- package/dist/development/src/modifications/relations/DisableOrphanRemovalModification.cjs.map +1 -1
- package/dist/development/src/modifications/relations/DisableOrphanRemovalModification.js.map +1 -1
- package/dist/development/src/modifications/relations/EnableOrphanRemovalModification.cjs.map +1 -1
- package/dist/development/src/modifications/relations/EnableOrphanRemovalModification.js.map +1 -1
- package/dist/development/src/modifications/relations/MakeRelationNotNullModification.cjs.map +1 -1
- package/dist/development/src/modifications/relations/MakeRelationNotNullModification.js.map +1 -1
- package/dist/development/src/modifications/relations/MakeRelationNullableModification.cjs.map +1 -1
- package/dist/development/src/modifications/relations/MakeRelationNullableModification.js.map +1 -1
- package/dist/development/src/modifications/relations/ToggleJunctionEventLogModification.cjs.map +1 -1
- package/dist/development/src/modifications/relations/ToggleJunctionEventLogModification.js.map +1 -1
- package/dist/development/src/modifications/relations/UpdateRelationOnDeleteModification.cjs.map +1 -1
- package/dist/development/src/modifications/relations/UpdateRelationOnDeleteModification.js.map +1 -1
- package/dist/development/src/modifications/relations/UpdateRelationOrderByModification.cjs.map +1 -1
- package/dist/development/src/modifications/relations/UpdateRelationOrderByModification.js.map +1 -1
- package/dist/development/src/modifications/relations/helpers.cjs.map +1 -1
- package/dist/development/src/modifications/relations/helpers.js.map +1 -1
- package/dist/development/src/modifications/settings/UpdateSettingsModification.cjs.map +1 -1
- package/dist/development/src/modifications/settings/UpdateSettingsModification.js.map +1 -1
- package/dist/development/src/modifications/upgrade/RemoveIndexNamesModification.cjs.map +1 -1
- package/dist/development/src/modifications/upgrade/RemoveIndexNamesModification.js.map +1 -1
- package/dist/development/src/modifications/utils/createJunctionTable.cjs.map +1 -1
- package/dist/development/src/modifications/utils/createJunctionTable.js.map +1 -1
- package/dist/development/src/modifications/utils/diffUtils.cjs.map +1 -1
- package/dist/development/src/modifications/utils/diffUtils.js.map +1 -1
- package/dist/development/src/modifications/utils/schemaUpdateUtils.cjs.map +1 -1
- package/dist/development/src/modifications/utils/schemaUpdateUtils.js.map +1 -1
- package/dist/development/src/modifications/utils/viewDependencies.cjs +15 -1
- package/dist/development/src/modifications/utils/viewDependencies.cjs.map +1 -1
- package/dist/development/src/modifications/utils/viewDependencies.js +16 -2
- package/dist/development/src/modifications/utils/viewDependencies.js.map +1 -1
- package/dist/development/src/modifications/validation/PatchValidationSchemaModification.cjs.map +1 -1
- package/dist/development/src/modifications/validation/PatchValidationSchemaModification.js.map +1 -1
- package/dist/development/src/modifications/validation/UpdateValidationSchemaModification.cjs.map +1 -1
- package/dist/development/src/modifications/validation/UpdateValidationSchemaModification.js.map +1 -1
- package/dist/production/index.cjs +3 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +3 -0
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/MigrationDescriber.cjs.map +1 -1
- package/dist/production/src/MigrationDescriber.js.map +1 -1
- package/dist/production/src/SchemaDiffer.cjs +27 -12
- package/dist/production/src/SchemaDiffer.cjs.map +1 -1
- package/dist/production/src/SchemaDiffer.js +27 -12
- package/dist/production/src/SchemaDiffer.js.map +1 -1
- package/dist/production/src/SchemaMigrator.cjs.map +1 -1
- package/dist/production/src/SchemaMigrator.js.map +1 -1
- package/dist/production/src/modifications/ModificationHandler.cjs.map +1 -1
- package/dist/production/src/modifications/ModificationHandler.js.map +1 -1
- package/dist/production/src/modifications/ModificationHandlerFactory.cjs +2 -0
- package/dist/production/src/modifications/ModificationHandlerFactory.cjs.map +1 -1
- package/dist/production/src/modifications/ModificationHandlerFactory.js +2 -0
- package/dist/production/src/modifications/ModificationHandlerFactory.js.map +1 -1
- package/dist/production/src/modifications/NoopModification.cjs.map +1 -1
- package/dist/production/src/modifications/NoopModification.js.map +1 -1
- package/dist/production/src/modifications/acl/PatchAclSchemaModification.cjs.map +1 -1
- package/dist/production/src/modifications/acl/PatchAclSchemaModification.js.map +1 -1
- package/dist/production/src/modifications/acl/UpdateAclSchemaModification.cjs.map +1 -1
- package/dist/production/src/modifications/acl/UpdateAclSchemaModification.js.map +1 -1
- package/dist/production/src/modifications/actions/CreateTargetModification.cjs.map +1 -1
- package/dist/production/src/modifications/actions/CreateTargetModification.js.map +1 -1
- package/dist/production/src/modifications/actions/CreateTriggerModification.cjs.map +1 -1
- package/dist/production/src/modifications/actions/CreateTriggerModification.js.map +1 -1
- package/dist/production/src/modifications/actions/PatchTriggerModification.cjs.map +1 -1
- package/dist/production/src/modifications/actions/PatchTriggerModification.js.map +1 -1
- package/dist/production/src/modifications/actions/RemoveTargetModification.cjs.map +1 -1
- package/dist/production/src/modifications/actions/RemoveTargetModification.js.map +1 -1
- package/dist/production/src/modifications/actions/RemoveTriggerModification.cjs.map +1 -1
- package/dist/production/src/modifications/actions/RemoveTriggerModification.js.map +1 -1
- package/dist/production/src/modifications/actions/UpdateTargetModification.cjs.map +1 -1
- package/dist/production/src/modifications/actions/UpdateTargetModification.js.map +1 -1
- package/dist/production/src/modifications/actions/UpdateTriggerModification.cjs.map +1 -1
- package/dist/production/src/modifications/actions/UpdateTriggerModification.js.map +1 -1
- package/dist/production/src/modifications/columns/CreateColumnModification.cjs.map +1 -1
- package/dist/production/src/modifications/columns/CreateColumnModification.js.map +1 -1
- package/dist/production/src/modifications/columns/UpdateColumnDefinitionModification.cjs.map +1 -1
- package/dist/production/src/modifications/columns/UpdateColumnDefinitionModification.js.map +1 -1
- package/dist/production/src/modifications/columns/UpdateColumnNameModification.cjs.map +1 -1
- package/dist/production/src/modifications/columns/UpdateColumnNameModification.js.map +1 -1
- package/dist/production/src/modifications/columns/columnUtils.cjs.map +1 -1
- package/dist/production/src/modifications/columns/columnUtils.js.map +1 -1
- package/dist/production/src/modifications/constraints/CreateUniqueConstraintModification.cjs.map +1 -1
- package/dist/production/src/modifications/constraints/CreateUniqueConstraintModification.js.map +1 -1
- package/dist/production/src/modifications/constraints/RemoveUniqueConstraintModification.cjs.map +1 -1
- package/dist/production/src/modifications/constraints/RemoveUniqueConstraintModification.js.map +1 -1
- package/dist/production/src/modifications/differs/RemoveChangedFieldDiffer.cjs.map +1 -1
- package/dist/production/src/modifications/differs/RemoveChangedFieldDiffer.js.map +1 -1
- package/dist/production/src/modifications/differs/RemoveViewDiffer.cjs +4 -1
- package/dist/production/src/modifications/differs/RemoveViewDiffer.cjs.map +1 -1
- package/dist/production/src/modifications/differs/RemoveViewDiffer.js +5 -2
- package/dist/production/src/modifications/differs/RemoveViewDiffer.js.map +1 -1
- package/dist/production/src/modifications/differs/UpdateViewDiffer.cjs +45 -0
- package/dist/production/src/modifications/differs/UpdateViewDiffer.cjs.map +1 -0
- package/dist/production/src/modifications/differs/UpdateViewDiffer.js +45 -0
- package/dist/production/src/modifications/differs/UpdateViewDiffer.js.map +1 -0
- package/dist/production/src/modifications/entities/CreateEntityModification.cjs.map +1 -1
- package/dist/production/src/modifications/entities/CreateEntityModification.js.map +1 -1
- package/dist/production/src/modifications/entities/CreateViewModification.cjs.map +1 -1
- package/dist/production/src/modifications/entities/CreateViewModification.js.map +1 -1
- package/dist/production/src/modifications/entities/RemoveEntityModification.cjs.map +1 -1
- package/dist/production/src/modifications/entities/RemoveEntityModification.js.map +1 -1
- package/dist/production/src/modifications/entities/ToggleEventLogModification.cjs.map +1 -1
- package/dist/production/src/modifications/entities/ToggleEventLogModification.js.map +1 -1
- package/dist/production/src/modifications/entities/UpdateEntityNameModification.cjs.map +1 -1
- package/dist/production/src/modifications/entities/UpdateEntityNameModification.js.map +1 -1
- package/dist/production/src/modifications/entities/UpdateEntityOrderByModification.cjs.map +1 -1
- package/dist/production/src/modifications/entities/UpdateEntityOrderByModification.js.map +1 -1
- package/dist/production/src/modifications/entities/UpdateEntityTableNameModification.cjs.map +1 -1
- package/dist/production/src/modifications/entities/UpdateEntityTableNameModification.js.map +1 -1
- package/dist/production/src/modifications/entities/UpdateViewModification.cjs.map +1 -1
- package/dist/production/src/modifications/entities/UpdateViewModification.js.map +1 -1
- package/dist/production/src/modifications/enums/CreateEnumModification.cjs.map +1 -1
- package/dist/production/src/modifications/enums/CreateEnumModification.js.map +1 -1
- package/dist/production/src/modifications/enums/RemoveEnumModification.cjs.map +1 -1
- package/dist/production/src/modifications/enums/RemoveEnumModification.js.map +1 -1
- package/dist/production/src/modifications/enums/UpdateEnumModification.cjs.map +1 -1
- package/dist/production/src/modifications/enums/UpdateEnumModification.js.map +1 -1
- package/dist/production/src/modifications/enums/enumUtils.cjs.map +1 -1
- package/dist/production/src/modifications/enums/enumUtils.js.map +1 -1
- package/dist/production/src/modifications/fields/RemoveFieldModification.cjs.map +1 -1
- package/dist/production/src/modifications/fields/RemoveFieldModification.js.map +1 -1
- package/dist/production/src/modifications/fields/UpdateFieldNameModification.cjs +10 -4
- package/dist/production/src/modifications/fields/UpdateFieldNameModification.cjs.map +1 -1
- package/dist/production/src/modifications/fields/UpdateFieldNameModification.js +10 -4
- package/dist/production/src/modifications/fields/UpdateFieldNameModification.js.map +1 -1
- package/dist/production/src/modifications/indexes/CreateIndexModification.cjs +23 -7
- package/dist/production/src/modifications/indexes/CreateIndexModification.cjs.map +1 -1
- package/dist/production/src/modifications/indexes/CreateIndexModification.js +23 -7
- package/dist/production/src/modifications/indexes/CreateIndexModification.js.map +1 -1
- package/dist/production/src/modifications/indexes/RemoveIndexModification.cjs +52 -17
- package/dist/production/src/modifications/indexes/RemoveIndexModification.cjs.map +1 -1
- package/dist/production/src/modifications/indexes/RemoveIndexModification.js +52 -17
- package/dist/production/src/modifications/indexes/RemoveIndexModification.js.map +1 -1
- package/dist/production/src/modifications/relations/ConvertManyHasManyToJoiningEntityModification.cjs +140 -0
- package/dist/production/src/modifications/relations/ConvertManyHasManyToJoiningEntityModification.cjs.map +1 -0
- package/dist/production/src/modifications/relations/ConvertManyHasManyToJoiningEntityModification.js +140 -0
- package/dist/production/src/modifications/relations/ConvertManyHasManyToJoiningEntityModification.js.map +1 -0
- package/dist/production/src/modifications/relations/ConvertOneHasManyToManyHasManyRelationModification.cjs.map +1 -1
- package/dist/production/src/modifications/relations/ConvertOneHasManyToManyHasManyRelationModification.js.map +1 -1
- package/dist/production/src/modifications/relations/ConvertOneHasManyToOneHasOneRelationModification.cjs.map +1 -1
- package/dist/production/src/modifications/relations/ConvertOneHasManyToOneHasOneRelationModification.js.map +1 -1
- package/dist/production/src/modifications/relations/ConvertOneToManyRelationModification.cjs.map +1 -1
- package/dist/production/src/modifications/relations/ConvertOneToManyRelationModification.js.map +1 -1
- package/dist/production/src/modifications/relations/CreateRelationInverseSideModification.cjs.map +1 -1
- package/dist/production/src/modifications/relations/CreateRelationInverseSideModification.js.map +1 -1
- package/dist/production/src/modifications/relations/CreateRelationModification.cjs.map +1 -1
- package/dist/production/src/modifications/relations/CreateRelationModification.js.map +1 -1
- package/dist/production/src/modifications/relations/DisableOrphanRemovalModification.cjs.map +1 -1
- package/dist/production/src/modifications/relations/DisableOrphanRemovalModification.js.map +1 -1
- package/dist/production/src/modifications/relations/EnableOrphanRemovalModification.cjs.map +1 -1
- package/dist/production/src/modifications/relations/EnableOrphanRemovalModification.js.map +1 -1
- package/dist/production/src/modifications/relations/MakeRelationNotNullModification.cjs.map +1 -1
- package/dist/production/src/modifications/relations/MakeRelationNotNullModification.js.map +1 -1
- package/dist/production/src/modifications/relations/MakeRelationNullableModification.cjs.map +1 -1
- package/dist/production/src/modifications/relations/MakeRelationNullableModification.js.map +1 -1
- package/dist/production/src/modifications/relations/ToggleJunctionEventLogModification.cjs.map +1 -1
- package/dist/production/src/modifications/relations/ToggleJunctionEventLogModification.js.map +1 -1
- package/dist/production/src/modifications/relations/UpdateRelationOnDeleteModification.cjs.map +1 -1
- package/dist/production/src/modifications/relations/UpdateRelationOnDeleteModification.js.map +1 -1
- package/dist/production/src/modifications/relations/UpdateRelationOrderByModification.cjs.map +1 -1
- package/dist/production/src/modifications/relations/UpdateRelationOrderByModification.js.map +1 -1
- package/dist/production/src/modifications/relations/helpers.cjs.map +1 -1
- package/dist/production/src/modifications/relations/helpers.js.map +1 -1
- package/dist/production/src/modifications/settings/UpdateSettingsModification.cjs.map +1 -1
- package/dist/production/src/modifications/settings/UpdateSettingsModification.js.map +1 -1
- package/dist/production/src/modifications/upgrade/RemoveIndexNamesModification.cjs.map +1 -1
- package/dist/production/src/modifications/upgrade/RemoveIndexNamesModification.js.map +1 -1
- package/dist/production/src/modifications/utils/createJunctionTable.cjs.map +1 -1
- package/dist/production/src/modifications/utils/createJunctionTable.js.map +1 -1
- package/dist/production/src/modifications/utils/diffUtils.cjs.map +1 -1
- package/dist/production/src/modifications/utils/diffUtils.js.map +1 -1
- package/dist/production/src/modifications/utils/schemaUpdateUtils.cjs.map +1 -1
- package/dist/production/src/modifications/utils/schemaUpdateUtils.js.map +1 -1
- package/dist/production/src/modifications/utils/viewDependencies.cjs +15 -1
- package/dist/production/src/modifications/utils/viewDependencies.cjs.map +1 -1
- package/dist/production/src/modifications/utils/viewDependencies.js +16 -2
- package/dist/production/src/modifications/utils/viewDependencies.js.map +1 -1
- package/dist/production/src/modifications/validation/PatchValidationSchemaModification.cjs.map +1 -1
- package/dist/production/src/modifications/validation/PatchValidationSchemaModification.js.map +1 -1
- package/dist/production/src/modifications/validation/UpdateValidationSchemaModification.cjs.map +1 -1
- package/dist/production/src/modifications/validation/UpdateValidationSchemaModification.js.map +1 -1
- package/dist/tests/cases/integration/convertManyHasManyToJoiningEntity.test.d.ts +2 -0
- package/dist/tests/cases/integration/convertManyHasManyToJoiningEntity.test.d.ts.map +1 -0
- package/dist/tests/cases/integration/skipNonModelDiffers.test.d.ts +2 -0
- package/dist/tests/cases/integration/skipNonModelDiffers.test.d.ts.map +1 -0
- package/dist/tests/src/tests.d.ts +4 -3
- package/dist/tests/src/tests.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/MigrationDescriber.d.ts +2 -2
- package/dist/types/MigrationDescriber.d.ts.map +1 -1
- package/dist/types/SchemaDiffer.d.ts +12 -5
- package/dist/types/SchemaDiffer.d.ts.map +1 -1
- package/dist/types/SchemaMigrator.d.ts +2 -2
- package/dist/types/SchemaMigrator.d.ts.map +1 -1
- package/dist/types/index.d.ts +6 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modifications/ModificationHandler.d.ts +2 -2
- package/dist/types/modifications/ModificationHandler.d.ts.map +1 -1
- package/dist/types/modifications/ModificationHandlerFactory.d.ts +1 -1
- package/dist/types/modifications/ModificationHandlerFactory.d.ts.map +1 -1
- package/dist/types/modifications/NoopModification.d.ts +2 -2
- package/dist/types/modifications/NoopModification.d.ts.map +1 -1
- package/dist/types/modifications/acl/PatchAclSchemaModification.d.ts +3 -3
- package/dist/types/modifications/acl/PatchAclSchemaModification.d.ts.map +1 -1
- package/dist/types/modifications/acl/UpdateAclSchemaModification.d.ts +4 -4
- package/dist/types/modifications/acl/UpdateAclSchemaModification.d.ts.map +1 -1
- package/dist/types/modifications/acl/index.d.ts +2 -2
- package/dist/types/modifications/acl/index.d.ts.map +1 -1
- package/dist/types/modifications/actions/CreateTargetModification.d.ts +4 -4
- package/dist/types/modifications/actions/CreateTargetModification.d.ts.map +1 -1
- package/dist/types/modifications/actions/CreateTriggerModification.d.ts +4 -4
- package/dist/types/modifications/actions/CreateTriggerModification.d.ts.map +1 -1
- package/dist/types/modifications/actions/PatchTriggerModification.d.ts +3 -3
- package/dist/types/modifications/actions/PatchTriggerModification.d.ts.map +1 -1
- package/dist/types/modifications/actions/RemoveTargetModification.d.ts +4 -4
- package/dist/types/modifications/actions/RemoveTargetModification.d.ts.map +1 -1
- package/dist/types/modifications/actions/RemoveTriggerModification.d.ts +4 -4
- package/dist/types/modifications/actions/RemoveTriggerModification.d.ts.map +1 -1
- package/dist/types/modifications/actions/UpdateTargetModification.d.ts +4 -4
- package/dist/types/modifications/actions/UpdateTargetModification.d.ts.map +1 -1
- package/dist/types/modifications/actions/UpdateTriggerModification.d.ts +4 -4
- package/dist/types/modifications/actions/UpdateTriggerModification.d.ts.map +1 -1
- package/dist/types/modifications/actions/index.d.ts +4 -4
- package/dist/types/modifications/actions/index.d.ts.map +1 -1
- package/dist/types/modifications/columns/CreateColumnModification.d.ts +4 -4
- package/dist/types/modifications/columns/CreateColumnModification.d.ts.map +1 -1
- package/dist/types/modifications/columns/UpdateColumnDefinitionModification.d.ts +4 -4
- package/dist/types/modifications/columns/UpdateColumnDefinitionModification.d.ts.map +1 -1
- package/dist/types/modifications/columns/UpdateColumnNameModification.d.ts +4 -4
- package/dist/types/modifications/columns/UpdateColumnNameModification.d.ts.map +1 -1
- package/dist/types/modifications/columns/index.d.ts +3 -3
- package/dist/types/modifications/columns/index.d.ts.map +1 -1
- package/dist/types/modifications/constraints/CreateUniqueConstraintModification.d.ts +4 -4
- package/dist/types/modifications/constraints/CreateUniqueConstraintModification.d.ts.map +1 -1
- package/dist/types/modifications/constraints/RemoveUniqueConstraintModification.d.ts +4 -4
- package/dist/types/modifications/constraints/RemoveUniqueConstraintModification.d.ts.map +1 -1
- package/dist/types/modifications/constraints/index.d.ts +3 -3
- package/dist/types/modifications/constraints/index.d.ts.map +1 -1
- package/dist/types/modifications/differs/RemoveChangedFieldDiffer.d.ts +2 -2
- package/dist/types/modifications/differs/RemoveChangedFieldDiffer.d.ts.map +1 -1
- package/dist/types/modifications/differs/RemoveViewDiffer.d.ts +14 -3
- package/dist/types/modifications/differs/RemoveViewDiffer.d.ts.map +1 -1
- package/dist/types/modifications/differs/UpdateViewDiffer.d.ts +19 -0
- package/dist/types/modifications/differs/UpdateViewDiffer.d.ts.map +1 -0
- package/dist/types/modifications/differs/index.d.ts +3 -2
- package/dist/types/modifications/differs/index.d.ts.map +1 -1
- package/dist/types/modifications/entities/CreateEntityModification.d.ts +4 -4
- package/dist/types/modifications/entities/CreateEntityModification.d.ts.map +1 -1
- package/dist/types/modifications/entities/CreateViewModification.d.ts +4 -4
- package/dist/types/modifications/entities/CreateViewModification.d.ts.map +1 -1
- package/dist/types/modifications/entities/RemoveEntityModification.d.ts +4 -4
- package/dist/types/modifications/entities/RemoveEntityModification.d.ts.map +1 -1
- package/dist/types/modifications/entities/ToggleEventLogModification.d.ts +4 -4
- package/dist/types/modifications/entities/ToggleEventLogModification.d.ts.map +1 -1
- package/dist/types/modifications/entities/UpdateEntityNameModification.d.ts +3 -3
- package/dist/types/modifications/entities/UpdateEntityNameModification.d.ts.map +1 -1
- package/dist/types/modifications/entities/UpdateEntityOrderByModification.d.ts +4 -4
- package/dist/types/modifications/entities/UpdateEntityOrderByModification.d.ts.map +1 -1
- package/dist/types/modifications/entities/UpdateEntityTableNameModification.d.ts +4 -4
- package/dist/types/modifications/entities/UpdateEntityTableNameModification.d.ts.map +1 -1
- package/dist/types/modifications/entities/UpdateViewModification.d.ts +3 -3
- package/dist/types/modifications/entities/UpdateViewModification.d.ts.map +1 -1
- package/dist/types/modifications/entities/index.d.ts +7 -7
- package/dist/types/modifications/entities/index.d.ts.map +1 -1
- package/dist/types/modifications/enums/CreateEnumModification.d.ts +4 -4
- package/dist/types/modifications/enums/CreateEnumModification.d.ts.map +1 -1
- package/dist/types/modifications/enums/RemoveEnumModification.d.ts +4 -4
- package/dist/types/modifications/enums/RemoveEnumModification.d.ts.map +1 -1
- package/dist/types/modifications/enums/UpdateEnumModification.d.ts +4 -4
- package/dist/types/modifications/enums/UpdateEnumModification.d.ts.map +1 -1
- package/dist/types/modifications/enums/index.d.ts +3 -3
- package/dist/types/modifications/enums/index.d.ts.map +1 -1
- package/dist/types/modifications/fields/RemoveFieldModification.d.ts +4 -4
- package/dist/types/modifications/fields/RemoveFieldModification.d.ts.map +1 -1
- package/dist/types/modifications/fields/UpdateFieldNameModification.d.ts +3 -3
- package/dist/types/modifications/fields/UpdateFieldNameModification.d.ts.map +1 -1
- package/dist/types/modifications/fields/index.d.ts +2 -2
- package/dist/types/modifications/fields/index.d.ts.map +1 -1
- package/dist/types/modifications/index.d.ts +13 -13
- package/dist/types/modifications/index.d.ts.map +1 -1
- package/dist/types/modifications/indexes/CreateIndexModification.d.ts +4 -4
- package/dist/types/modifications/indexes/CreateIndexModification.d.ts.map +1 -1
- package/dist/types/modifications/indexes/RemoveIndexModification.d.ts +18 -6
- package/dist/types/modifications/indexes/RemoveIndexModification.d.ts.map +1 -1
- package/dist/types/modifications/indexes/index.d.ts +2 -2
- package/dist/types/modifications/indexes/index.d.ts.map +1 -1
- package/dist/types/modifications/relations/ConvertManyHasManyToJoiningEntityModification.d.ts +52 -0
- package/dist/types/modifications/relations/ConvertManyHasManyToJoiningEntityModification.d.ts.map +1 -0
- package/dist/types/modifications/relations/ConvertOneHasManyToManyHasManyRelationModification.d.ts +5 -5
- package/dist/types/modifications/relations/ConvertOneHasManyToManyHasManyRelationModification.d.ts.map +1 -1
- package/dist/types/modifications/relations/ConvertOneHasManyToOneHasOneRelationModification.d.ts +4 -4
- package/dist/types/modifications/relations/ConvertOneHasManyToOneHasOneRelationModification.d.ts.map +1 -1
- package/dist/types/modifications/relations/ConvertOneToManyRelationModification.d.ts +4 -4
- package/dist/types/modifications/relations/ConvertOneToManyRelationModification.d.ts.map +1 -1
- package/dist/types/modifications/relations/CreateRelationInverseSideModification.d.ts +4 -4
- package/dist/types/modifications/relations/CreateRelationInverseSideModification.d.ts.map +1 -1
- package/dist/types/modifications/relations/CreateRelationModification.d.ts +5 -5
- package/dist/types/modifications/relations/CreateRelationModification.d.ts.map +1 -1
- package/dist/types/modifications/relations/DisableOrphanRemovalModification.d.ts +4 -4
- package/dist/types/modifications/relations/DisableOrphanRemovalModification.d.ts.map +1 -1
- package/dist/types/modifications/relations/EnableOrphanRemovalModification.d.ts +4 -4
- package/dist/types/modifications/relations/EnableOrphanRemovalModification.d.ts.map +1 -1
- package/dist/types/modifications/relations/MakeRelationNotNullModification.d.ts +4 -4
- package/dist/types/modifications/relations/MakeRelationNotNullModification.d.ts.map +1 -1
- package/dist/types/modifications/relations/MakeRelationNullableModification.d.ts +4 -4
- package/dist/types/modifications/relations/MakeRelationNullableModification.d.ts.map +1 -1
- package/dist/types/modifications/relations/ToggleJunctionEventLogModification.d.ts +4 -4
- package/dist/types/modifications/relations/ToggleJunctionEventLogModification.d.ts.map +1 -1
- package/dist/types/modifications/relations/UpdateRelationOnDeleteModification.d.ts +4 -4
- package/dist/types/modifications/relations/UpdateRelationOnDeleteModification.d.ts.map +1 -1
- package/dist/types/modifications/relations/UpdateRelationOrderByModification.d.ts +4 -4
- package/dist/types/modifications/relations/UpdateRelationOrderByModification.d.ts.map +1 -1
- package/dist/types/modifications/relations/index.d.ts +12 -11
- package/dist/types/modifications/relations/index.d.ts.map +1 -1
- package/dist/types/modifications/settings/UpdateSettingsModification.d.ts +4 -4
- package/dist/types/modifications/settings/UpdateSettingsModification.d.ts.map +1 -1
- package/dist/types/modifications/settings/index.d.ts +1 -1
- package/dist/types/modifications/settings/index.d.ts.map +1 -1
- package/dist/types/modifications/upgrade/RemoveIndexNamesModification.d.ts +3 -3
- package/dist/types/modifications/upgrade/RemoveIndexNamesModification.d.ts.map +1 -1
- package/dist/types/modifications/utils/diffUtils.d.ts +1 -1
- package/dist/types/modifications/utils/diffUtils.d.ts.map +1 -1
- package/dist/types/modifications/utils/viewDependencies.d.ts +11 -1
- package/dist/types/modifications/utils/viewDependencies.d.ts.map +1 -1
- package/dist/types/modifications/validation/PatchValidationSchemaModification.d.ts +3 -3
- package/dist/types/modifications/validation/PatchValidationSchemaModification.d.ts.map +1 -1
- package/dist/types/modifications/validation/UpdateValidationSchemaModification.d.ts +4 -4
- package/dist/types/modifications/validation/UpdateValidationSchemaModification.d.ts.map +1 -1
- package/dist/types/modifications/validation/index.d.ts +2 -2
- package/dist/types/modifications/validation/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/MigrationDescriber.ts +2 -2
- package/src/SchemaDiffer.ts +52 -25
- package/src/SchemaMigrator.ts +2 -2
- package/src/index.ts +6 -6
- package/src/modifications/ModificationHandler.ts +2 -2
- package/src/modifications/ModificationHandlerFactory.ts +21 -19
- package/src/modifications/NoopModification.ts +2 -2
- package/src/modifications/acl/PatchAclSchemaModification.ts +3 -3
- package/src/modifications/acl/UpdateAclSchemaModification.ts +3 -3
- package/src/modifications/acl/index.ts +2 -2
- package/src/modifications/actions/CreateTargetModification.ts +2 -2
- package/src/modifications/actions/CreateTriggerModification.ts +2 -2
- package/src/modifications/actions/PatchTriggerModification.ts +3 -3
- package/src/modifications/actions/RemoveTargetModification.ts +2 -2
- package/src/modifications/actions/RemoveTriggerModification.ts +2 -2
- package/src/modifications/actions/UpdateTargetModification.ts +2 -2
- package/src/modifications/actions/UpdateTriggerModification.ts +3 -3
- package/src/modifications/actions/index.ts +4 -4
- package/src/modifications/columns/CreateColumnModification.ts +5 -5
- package/src/modifications/columns/UpdateColumnDefinitionModification.ts +6 -6
- package/src/modifications/columns/UpdateColumnNameModification.ts +3 -3
- package/src/modifications/columns/columnUtils.ts +1 -1
- package/src/modifications/columns/index.ts +3 -3
- package/src/modifications/constraints/CreateUniqueConstraintModification.ts +4 -4
- package/src/modifications/constraints/RemoveUniqueConstraintModification.ts +4 -4
- package/src/modifications/constraints/index.ts +3 -3
- package/src/modifications/differs/RemoveChangedFieldDiffer.ts +3 -3
- package/src/modifications/differs/RemoveViewDiffer.ts +17 -5
- package/src/modifications/differs/UpdateViewDiffer.ts +58 -0
- package/src/modifications/differs/index.ts +3 -2
- package/src/modifications/entities/CreateEntityModification.ts +5 -5
- package/src/modifications/entities/CreateViewModification.ts +3 -3
- package/src/modifications/entities/RemoveEntityModification.ts +4 -4
- package/src/modifications/entities/ToggleEventLogModification.ts +3 -3
- package/src/modifications/entities/UpdateEntityNameModification.ts +12 -7
- package/src/modifications/entities/UpdateEntityOrderByModification.ts +2 -2
- package/src/modifications/entities/UpdateEntityTableNameModification.ts +2 -2
- package/src/modifications/entities/UpdateViewModification.ts +2 -2
- package/src/modifications/entities/index.ts +7 -7
- package/src/modifications/enums/CreateEnumModification.ts +3 -3
- package/src/modifications/enums/RemoveEnumModification.ts +2 -2
- package/src/modifications/enums/UpdateEnumModification.ts +4 -4
- package/src/modifications/enums/enumUtils.ts +1 -1
- package/src/modifications/enums/index.ts +3 -3
- package/src/modifications/fields/RemoveFieldModification.ts +3 -3
- package/src/modifications/fields/UpdateFieldNameModification.ts +26 -10
- package/src/modifications/fields/index.ts +2 -2
- package/src/modifications/index.ts +13 -13
- package/src/modifications/indexes/CreateIndexModification.ts +47 -11
- package/src/modifications/indexes/RemoveIndexModification.ts +92 -23
- package/src/modifications/indexes/index.ts +2 -2
- package/src/modifications/relations/ConvertManyHasManyToJoiningEntityModification.ts +218 -0
- package/src/modifications/relations/ConvertOneHasManyToManyHasManyRelationModification.ts +7 -7
- package/src/modifications/relations/ConvertOneHasManyToOneHasOneRelationModification.ts +6 -6
- package/src/modifications/relations/ConvertOneToManyRelationModification.ts +6 -6
- package/src/modifications/relations/CreateRelationInverseSideModification.ts +3 -3
- package/src/modifications/relations/CreateRelationModification.ts +9 -9
- package/src/modifications/relations/DisableOrphanRemovalModification.ts +3 -3
- package/src/modifications/relations/EnableOrphanRemovalModification.ts +3 -3
- package/src/modifications/relations/MakeRelationNotNullModification.ts +4 -4
- package/src/modifications/relations/MakeRelationNullableModification.ts +4 -4
- package/src/modifications/relations/ToggleJunctionEventLogModification.ts +5 -5
- package/src/modifications/relations/UpdateRelationOnDeleteModification.ts +5 -5
- package/src/modifications/relations/UpdateRelationOrderByModification.ts +3 -3
- package/src/modifications/relations/helpers.ts +1 -1
- package/src/modifications/relations/index.ts +12 -11
- package/src/modifications/settings/UpdateSettingsModification.ts +2 -2
- package/src/modifications/settings/index.ts +1 -1
- package/src/modifications/upgrade/RemoveIndexNamesModification.ts +2 -2
- package/src/modifications/utils/createJunctionTable.ts +3 -3
- package/src/modifications/utils/diffUtils.ts +2 -2
- package/src/modifications/utils/schemaUpdateUtils.ts +3 -3
- package/src/modifications/utils/viewDependencies.ts +26 -2
- package/src/modifications/validation/PatchValidationSchemaModification.ts +3 -3
- package/src/modifications/validation/UpdateValidationSchemaModification.ts +3 -3
- package/src/modifications/validation/index.ts +2 -2
- package/tests/cases/integration/convertManyHasManyToJoiningEntity.test.ts +339 -0
- package/tests/cases/integration/convertManyHasOneToOneHasOneRelation.test.ts +2 -2
- package/tests/cases/integration/convertOneHasManyToManyHasManyRelation.test.ts +2 -2
- package/tests/cases/integration/convertOneToManyRelation.test.ts +2 -2
- package/tests/cases/integration/createAndDropIndex.test.ts +482 -3
- package/tests/cases/integration/createColumn.test.ts +29 -2
- package/tests/cases/integration/createEntity.test.ts +2 -2
- package/tests/cases/integration/createEnum.test.ts +2 -2
- package/tests/cases/integration/createManyHasMany.test.ts +2 -2
- package/tests/cases/integration/createManyHasOne.test.ts +2 -2
- package/tests/cases/integration/createOneHasMany.test.ts +2 -2
- package/tests/cases/integration/createOneHasOne.test.ts +2 -2
- package/tests/cases/integration/createRelationInverseSide.test.ts +2 -2
- package/tests/cases/integration/createUnique.test.ts +3 -3
- package/tests/cases/integration/disableOrphanRemoval.test.ts +2 -2
- package/tests/cases/integration/enableOrphanRemoval.test.ts +2 -2
- package/tests/cases/integration/makeColumnNotNull.test.ts +2 -2
- package/tests/cases/integration/makeRelationNotNull.test.ts +2 -2
- package/tests/cases/integration/makeRelationNullable.test.ts +2 -2
- package/tests/cases/integration/patchAclSchema.test.ts +2 -2
- package/tests/cases/integration/patchTrigger.test.ts +1 -1
- package/tests/cases/integration/removeEntity.test.ts +2 -2
- package/tests/cases/integration/removeEnum.test.ts +2 -2
- package/tests/cases/integration/removeField.test.ts +3 -3
- package/tests/cases/integration/skipNonModelDiffers.test.ts +97 -0
- package/tests/cases/integration/toggleEventLog.test.ts +2 -2
- package/tests/cases/integration/toggleJunctionEventLog.test.ts +2 -2
- package/tests/cases/integration/updateColumnDefinition.test.ts +3 -3
- package/tests/cases/integration/updateEntityName.test.ts +2 -2
- package/tests/cases/integration/updateEntityOrderBy.test.ts +2 -2
- package/tests/cases/integration/updateEnum.test.ts +2 -2
- package/tests/cases/integration/updateFieldName.test.ts +38 -3
- package/tests/cases/integration/updateRelationOnDelete.test.ts +2 -2
- package/tests/cases/integration/updateRelationOrderBy.test.ts +2 -2
- package/tests/cases/integration/updateView.test.ts +221 -233
- package/tests/src/tests.ts +6 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaUpdateUtils.cjs","sources":["../../../../../../packages/schema-migrations/src/modifications/utils/schemaUpdateUtils.ts"],"sourcesContent":["import { Acl, Model, Schema, Writable } from '@contember/schema'\nimport { SchemaUpdateError } from '../exceptions'\nimport { isDefined } from '../../utils/isDefined'\nimport { isInverseRelation, isOwningRelation, isRelation, PredicateDefinitionProcessor } from '@contember/schema-utils'\nimport { VERSION_ACL_PATCH, VERSION_REMOVE_RELATION_INVERSE_SIDE } from '../ModificationVersions'\n\nexport type SchemaUpdater = (args: { schema: Schema }) => Schema\nexport type ModelUpdater = (args: { schema: Schema; model: Model.Schema }) => Model.Schema\nexport type EntityUpdater = (args: { schema: Schema; model: Model.Schema; entity: Model.Entity }) => Model.Entity\nexport type FieldUpdater<In extends Model.AnyField, Out extends Model.AnyField> = (args: {\n\tschema: Schema\n\tmodel: Model.Schema\n\tentity: Model.Entity\n\tfield: In\n}) => Out | undefined\nexport type AclUpdater = (args: { schema: Schema; acl: Acl.Schema }) => Acl.Schema\nexport type AclRoleUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n}) => Acl.RolePermissions\nexport type AclPermissionsUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n\tentities: Acl.Permissions\n}) => Acl.Permissions\n\nexport type AclEntityPermissionsUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n\tentities: Acl.Permissions\n\tentityName: string\n\tentityPermissions: Acl.EntityPermissions\n}) => Acl.EntityPermissions\n\nexport type EntityAclEveryPredicatesUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n\tentities: Acl.Permissions\n\tentityName: string\n\tentityPermissions: Acl.EntityPermissions\n\tpredicate: Acl.PredicateDefinition\n}) => Acl.PredicateDefinition\n\nexport const updateSchema = (...schemaUpdater: (SchemaUpdater | undefined)[]): SchemaUpdater => args =>\n\tschemaUpdater.filter(isDefined).reduce((schema, updater) => updater({ ...args, schema }), args.schema)\n\nexport const updateAcl = (updater: AclUpdater): SchemaUpdater => args => ({\n\t...args.schema,\n\tacl: updater({ schema: args.schema, acl: args.schema.acl }),\n})\n\nexport const updateAclEveryRole = (...updater: AclRoleUpdater[]): AclUpdater => args => ({\n\t...args.acl,\n\troles: Object.fromEntries(\n\t\tupdater.reduce(\n\t\t\t(acc, updater) => acc.map(([name, role]) => [name, updater({ ...args, role })]),\n\t\t\tObject.entries(args.acl.roles),\n\t\t),\n\t),\n})\n\nexport const updateAclEntities = (updater: AclPermissionsUpdater): AclRoleUpdater => args => ({\n\t...args.role,\n\tentities: updater({ ...args, entities: args.role.entities }),\n})\n\nexport const updateAclEveryEntity = (...updater: AclEntityPermissionsUpdater[]): AclRoleUpdater => args => ({\n\t...args.role,\n\tentities: Object.fromEntries(\n\t\tupdater.reduce(\n\t\t\t(acc, updater) =>\n\t\t\t\tacc.map(([entity, entityPermissions]) => [\n\t\t\t\t\tentity,\n\t\t\t\t\tupdater({\n\t\t\t\t\t\t...args,\n\t\t\t\t\t\tentities: args.role.entities,\n\t\t\t\t\t\tentityName: entity,\n\t\t\t\t\t\tentityPermissions,\n\t\t\t\t\t}),\n\t\t\t\t]),\n\t\t\tObject.entries(args.role.entities),\n\t\t),\n\t),\n})\n\ntype EntityAclFieldPermissionsUpdater = (\n\tfieldPermissions: Acl.FieldPermissions,\n\tentityName: string,\n\toperation: Acl.Operation,\n) => Acl.FieldPermissions\ntype EntityOperationHandler = {\n\t[K in keyof Required<Acl.EntityOperations>]: (\n\t\tvalue: Exclude<Acl.EntityOperations[K], undefined>,\n\t) => Acl.EntityOperations[K]\n}\n\nexport const updateAclFieldPermissions =\n\t(updater: EntityAclFieldPermissionsUpdater): AclEntityPermissionsUpdater => ({ entityPermissions, entityName }) => {\n\t\tconst operations: Writable<Acl.EntityOperations> = {}\n\t\tconst handlers: EntityOperationHandler = {\n\t\t\tcreate: value => updater(value, entityName, Acl.Operation.create),\n\t\t\tupdate: value => updater(value, entityName, Acl.Operation.update),\n\t\t\tread: value => updater(value, entityName, Acl.Operation.read),\n\t\t\tdelete: value => value,\n\t\t\tcustomPrimary: value => value,\n\t\t\trefreshMaterializedView: value => value,\n\t\t\tnoRoot: value => value,\n\t\t}\n\t\tconst types: (keyof Acl.EntityOperations)[] = ['create', 'update', 'read', 'delete', 'customPrimary', 'noRoot']\n\t\tfor (const key of types) {\n\t\t\tif (key in entityPermissions.operations) {\n\t\t\t\toperations[key] = handlers[key](entityPermissions.operations[key] as any) as any\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t...entityPermissions,\n\t\t\toperations,\n\t\t}\n\t}\n\nexport const updateAclEveryPredicate = (updater: EntityAclEveryPredicatesUpdater): AclEntityPermissionsUpdater => args => {\n\treturn {\n\t\t...args.entityPermissions,\n\t\tpredicates: Object.fromEntries(\n\t\t\tObject.entries(args.entityPermissions.predicates).map(([name, predicate]) => [\n\t\t\t\tname,\n\t\t\t\tupdater({\n\t\t\t\t\t...args,\n\t\t\t\t\tpredicate,\n\t\t\t\t}),\n\t\t\t]),\n\t\t),\n\t}\n}\n\nexport const updateModel = (...modelUpdate: (ModelUpdater | undefined)[]): SchemaUpdater => args => ({\n\t...args.schema,\n\tmodel: modelUpdate\n\t\t.filter((it): it is ModelUpdater => it !== undefined)\n\t\t.reduce((model, updater) => updater({ ...args, model }), args.schema.model),\n})\n\nexport const updateEntity = (name: string, entityUpdate: EntityUpdater): ModelUpdater => args => {\n\tif (!args.model.entities[name]) {\n\t\tthrow new SchemaUpdateError(`Entity ${name} not found`)\n\t}\n\treturn {\n\t\t...args.model,\n\t\tentities: {\n\t\t\t...args.model.entities,\n\t\t\t[name]: entityUpdate({ ...args, entity: args.model.entities[name] }),\n\t\t},\n\t}\n}\n\nexport const updateEveryEntity = (entityUpdate: EntityUpdater): ModelUpdater => args => ({\n\t...args.model,\n\tentities: Object.fromEntries(\n\t\tObject.entries(args.model.entities).map(([name, entity]) => [name, entityUpdate({ ...args, entity })]),\n\t),\n})\n\nexport const updateField =\n\t<In extends Model.AnyField = Model.AnyField, Out extends Model.AnyField = In>(name: string, fieldUpdater: FieldUpdater<In, Out>): EntityUpdater =>\n\targs => {\n\t\tconst { [name]: field, ...otherFields } = args.entity.fields\n\t\tif (!args.entity.fields[name]) {\n\t\t\tthrow new SchemaUpdateError(`Field ${args.entity.name}::${name} not found`)\n\t\t}\n\t\tconst updatedField = fieldUpdater({ ...args, field: args.entity.fields[name] as In })\n\n\t\treturn {\n\t\t\t...args.entity,\n\t\t\tfields: {\n\t\t\t\t...otherFields,\n\t\t\t\t...(updatedField ? { [name]: updatedField } : {}),\n\t\t\t},\n\t\t}\n\t}\n\nexport const updateEveryField = (fieldUpdater: FieldUpdater<Model.AnyField, Model.AnyField>): EntityUpdater => args => ({\n\t...args.entity,\n\tfields: Object.fromEntries(\n\t\tObject.entries(args.entity.fields)\n\t\t\t.map(([name, field]) => {\n\t\t\t\tconst updatedField = fieldUpdater({ ...args, field })\n\t\t\t\tif (!updatedField) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn [name, updatedField]\n\t\t\t})\n\t\t\t.filter(isDefined),\n\t),\n})\n\nexport const addField = (field: Model.AnyField): EntityUpdater => args => {\n\treturn {\n\t\t...args.entity,\n\t\tfields: {\n\t\t\t...args.entity.fields,\n\t\t\t[field.name]: field,\n\t\t},\n\t}\n}\n\nexport const removeField = (entityName: string, fieldName: string, version: number): SchemaUpdater => {\n\treturn ({ schema }) => {\n\t\tconst entity = schema.model.entities[entityName]\n\t\tconst field = entity.fields[fieldName]\n\t\treturn updateSchema(\n\t\t\tversion >= VERSION_ACL_PATCH\n\t\t\t\t? updateAcl(\n\t\t\t\t\tupdateAclEveryRole(\n\t\t\t\t\t\tupdateAclEveryEntity(\n\t\t\t\t\t\t\tupdateAclFieldPermissions((permissions, entityName) => {\n\t\t\t\t\t\t\t\tif (entityName !== entity.name) {\n\t\t\t\t\t\t\t\t\treturn permissions\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst { [fieldName]: field, ...other } = permissions\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...other,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tupdateAclEveryPredicate(({ predicate, entityName }) => {\n\t\t\t\t\t\t\t\tconst processor = new PredicateDefinitionProcessor(schema.model)\n\t\t\t\t\t\t\t\treturn processor.process(schema.model.entities[entityName], predicate, {\n\t\t\t\t\t\t\t\t\thandleColumn: ctx => ctx.entity.name === entity.name && ctx.column.name === field.name ? undefined : ctx.value,\n\t\t\t\t\t\t\t\t\thandleRelation: ctx => ctx.entity.name === entity.name && ctx.relation.name === field.name ? undefined : ctx.value,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t: undefined,\n\t\t\tisRelation(field)\n\t\t\t\t&& isOwningRelation(field)\n\t\t\t\t&& field.inversedBy\n\t\t\t\t&& version >= VERSION_REMOVE_RELATION_INVERSE_SIDE\n\t\t\t\t? removeField(field.target, field.inversedBy, version)\n\t\t\t\t: undefined,\n\t\t\tupdateModel(\n\t\t\t\tupdateEntity(entity.name, ({ entity }) => {\n\t\t\t\t\tconst { [field.name]: removed, ...fields } = entity.fields\n\t\t\t\t\tconst indexes = entity.indexes.filter(index => !index.fields.includes(field.name))\n\t\t\t\t\tconst unique = entity.unique.filter(index => !index.fields.includes(field.name))\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...entity,\n\t\t\t\t\t\tfields,\n\t\t\t\t\t\tindexes,\n\t\t\t\t\t\tunique,\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t\tisRelation(field) && isInverseRelation(field)\n\t\t\t\t\t? updateEntity(\n\t\t\t\t\t\tfield.target,\n\t\t\t\t\t\tupdateField<Model.AnyOwningRelation>(field.ownedBy, ({ field: { inversedBy, ...field } }) => field),\n\t\t\t\t\t)\n\t\t\t\t\t: undefined,\n\t\t\t),\n\t\t)({ schema })\n\t}\n}\n"],"names":["isDefined","schema","updater","Acl","SchemaUpdateError","VERSION_ACL_PATCH","entityName","field","PredicateDefinitionProcessor","isRelation","isOwningRelation","VERSION_REMOVE_RELATION_INVERSE_SIDE","entity","isInverseRelation"],"mappings":";;;;;;;AA+CO,MAAM,eAAe,IAAI,kBAAgE,CAAA,SAC/F,cAAc,OAAOA,UAAAA,SAAS,EAAE,OAAO,CAACC,SAAQ,YAAY,QAAQ,EAAE,GAAG,MAAM,QAAAA,SAAQ,GAAG,KAAK,MAAM;AAE/F,MAAM,YAAY,CAAC,YAAuC,CAAA,UAAS;AAAA,EACzE,GAAG,KAAK;AAAA,EACR,KAAK,QAAQ,EAAE,QAAQ,KAAK,QAAQ,KAAK,KAAK,OAAO,IAAA,CAAK;AAC3D;AAEO,MAAM,qBAAqB,IAAI,YAA0C,CAAA,UAAS;AAAA,EACxF,GAAG,KAAK;AAAA,EACR,OAAO,OAAO;AAAA,IACb,QAAQ;AAAA,MACP,CAAC,KAAKC,aAAY,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,MAAMA,SAAQ,EAAE,GAAG,MAAM,KAAA,CAAM,CAAC,CAAC;AAAA,MAC9E,OAAO,QAAQ,KAAK,IAAI,KAAK;AAAA,IAAA;AAAA,EAC9B;AAEF;AAEO,MAAM,oBAAoB,CAAC,YAAmD,CAAA,UAAS;AAAA,EAC7F,GAAG,KAAK;AAAA,EACR,UAAU,QAAQ,EAA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,KAAK,IACzC;AAAA,UACD,MAAM;AAAA,UACN,YAAqC,MAAM,SAAS,CAAC,EAAE,OAAO,EAAE,YAAY,GAAGN,OAAAA,EAAM,MAAQA,MAAK;AAAA,QAAA,IAEjG;AAAA,MAAA;AAAA,IACJ,EACC,EAAE,QAAAN,QAAA,CAAQ;AAAA,EACb;AACD;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"schemaUpdateUtils.cjs","sources":["../../../../../../packages/schema-migrations/src/modifications/utils/schemaUpdateUtils.ts"],"sourcesContent":["import { Acl, Model, Schema, Writable } from '@contember/schema'\nimport { SchemaUpdateError } from '../exceptions.js'\nimport { isDefined } from '../../utils/isDefined.js'\nimport { isInverseRelation, isOwningRelation, isRelation, PredicateDefinitionProcessor } from '@contember/schema-utils'\nimport { VERSION_ACL_PATCH, VERSION_REMOVE_RELATION_INVERSE_SIDE } from '../ModificationVersions.js'\n\nexport type SchemaUpdater = (args: { schema: Schema }) => Schema\nexport type ModelUpdater = (args: { schema: Schema; model: Model.Schema }) => Model.Schema\nexport type EntityUpdater = (args: { schema: Schema; model: Model.Schema; entity: Model.Entity }) => Model.Entity\nexport type FieldUpdater<In extends Model.AnyField, Out extends Model.AnyField> = (args: {\n\tschema: Schema\n\tmodel: Model.Schema\n\tentity: Model.Entity\n\tfield: In\n}) => Out | undefined\nexport type AclUpdater = (args: { schema: Schema; acl: Acl.Schema }) => Acl.Schema\nexport type AclRoleUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n}) => Acl.RolePermissions\nexport type AclPermissionsUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n\tentities: Acl.Permissions\n}) => Acl.Permissions\n\nexport type AclEntityPermissionsUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n\tentities: Acl.Permissions\n\tentityName: string\n\tentityPermissions: Acl.EntityPermissions\n}) => Acl.EntityPermissions\n\nexport type EntityAclEveryPredicatesUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n\tentities: Acl.Permissions\n\tentityName: string\n\tentityPermissions: Acl.EntityPermissions\n\tpredicate: Acl.PredicateDefinition\n}) => Acl.PredicateDefinition\n\nexport const updateSchema = (...schemaUpdater: (SchemaUpdater | undefined)[]): SchemaUpdater => args =>\n\tschemaUpdater.filter(isDefined).reduce((schema, updater) => updater({ ...args, schema }), args.schema)\n\nexport const updateAcl = (updater: AclUpdater): SchemaUpdater => args => ({\n\t...args.schema,\n\tacl: updater({ schema: args.schema, acl: args.schema.acl }),\n})\n\nexport const updateAclEveryRole = (...updater: AclRoleUpdater[]): AclUpdater => args => ({\n\t...args.acl,\n\troles: Object.fromEntries(\n\t\tupdater.reduce(\n\t\t\t(acc, updater) => acc.map(([name, role]) => [name, updater({ ...args, role })]),\n\t\t\tObject.entries(args.acl.roles),\n\t\t),\n\t),\n})\n\nexport const updateAclEntities = (updater: AclPermissionsUpdater): AclRoleUpdater => args => ({\n\t...args.role,\n\tentities: updater({ ...args, entities: args.role.entities }),\n})\n\nexport const updateAclEveryEntity = (...updater: AclEntityPermissionsUpdater[]): AclRoleUpdater => args => ({\n\t...args.role,\n\tentities: Object.fromEntries(\n\t\tupdater.reduce(\n\t\t\t(acc, updater) =>\n\t\t\t\tacc.map(([entity, entityPermissions]) => [\n\t\t\t\t\tentity,\n\t\t\t\t\tupdater({\n\t\t\t\t\t\t...args,\n\t\t\t\t\t\tentities: args.role.entities,\n\t\t\t\t\t\tentityName: entity,\n\t\t\t\t\t\tentityPermissions,\n\t\t\t\t\t}),\n\t\t\t\t]),\n\t\t\tObject.entries(args.role.entities),\n\t\t),\n\t),\n})\n\ntype EntityAclFieldPermissionsUpdater = (\n\tfieldPermissions: Acl.FieldPermissions,\n\tentityName: string,\n\toperation: Acl.Operation,\n) => Acl.FieldPermissions\ntype EntityOperationHandler = {\n\t[K in keyof Required<Acl.EntityOperations>]: (\n\t\tvalue: Exclude<Acl.EntityOperations[K], undefined>,\n\t) => Acl.EntityOperations[K]\n}\n\nexport const updateAclFieldPermissions =\n\t(updater: EntityAclFieldPermissionsUpdater): AclEntityPermissionsUpdater => ({ entityPermissions, entityName }) => {\n\t\tconst operations: Writable<Acl.EntityOperations> = {}\n\t\tconst handlers: EntityOperationHandler = {\n\t\t\tcreate: value => updater(value, entityName, Acl.Operation.create),\n\t\t\tupdate: value => updater(value, entityName, Acl.Operation.update),\n\t\t\tread: value => updater(value, entityName, Acl.Operation.read),\n\t\t\tdelete: value => value,\n\t\t\tcustomPrimary: value => value,\n\t\t\trefreshMaterializedView: value => value,\n\t\t\tnoRoot: value => value,\n\t\t}\n\t\tconst types: (keyof Acl.EntityOperations)[] = ['create', 'update', 'read', 'delete', 'customPrimary', 'noRoot']\n\t\tfor (const key of types) {\n\t\t\tif (key in entityPermissions.operations) {\n\t\t\t\toperations[key] = handlers[key](entityPermissions.operations[key] as any) as any\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t...entityPermissions,\n\t\t\toperations,\n\t\t}\n\t}\n\nexport const updateAclEveryPredicate = (updater: EntityAclEveryPredicatesUpdater): AclEntityPermissionsUpdater => args => {\n\treturn {\n\t\t...args.entityPermissions,\n\t\tpredicates: Object.fromEntries(\n\t\t\tObject.entries(args.entityPermissions.predicates).map(([name, predicate]) => [\n\t\t\t\tname,\n\t\t\t\tupdater({\n\t\t\t\t\t...args,\n\t\t\t\t\tpredicate,\n\t\t\t\t}),\n\t\t\t]),\n\t\t),\n\t}\n}\n\nexport const updateModel = (...modelUpdate: (ModelUpdater | undefined)[]): SchemaUpdater => args => ({\n\t...args.schema,\n\tmodel: modelUpdate\n\t\t.filter((it): it is ModelUpdater => it !== undefined)\n\t\t.reduce((model, updater) => updater({ ...args, model }), args.schema.model),\n})\n\nexport const updateEntity = (name: string, entityUpdate: EntityUpdater): ModelUpdater => args => {\n\tif (!args.model.entities[name]) {\n\t\tthrow new SchemaUpdateError(`Entity ${name} not found`)\n\t}\n\treturn {\n\t\t...args.model,\n\t\tentities: {\n\t\t\t...args.model.entities,\n\t\t\t[name]: entityUpdate({ ...args, entity: args.model.entities[name] }),\n\t\t},\n\t}\n}\n\nexport const updateEveryEntity = (entityUpdate: EntityUpdater): ModelUpdater => args => ({\n\t...args.model,\n\tentities: Object.fromEntries(\n\t\tObject.entries(args.model.entities).map(([name, entity]) => [name, entityUpdate({ ...args, entity })]),\n\t),\n})\n\nexport const updateField =\n\t<In extends Model.AnyField = Model.AnyField, Out extends Model.AnyField = In>(name: string, fieldUpdater: FieldUpdater<In, Out>): EntityUpdater =>\n\targs => {\n\t\tconst { [name]: field, ...otherFields } = args.entity.fields\n\t\tif (!args.entity.fields[name]) {\n\t\t\tthrow new SchemaUpdateError(`Field ${args.entity.name}::${name} not found`)\n\t\t}\n\t\tconst updatedField = fieldUpdater({ ...args, field: args.entity.fields[name] as In })\n\n\t\treturn {\n\t\t\t...args.entity,\n\t\t\tfields: {\n\t\t\t\t...otherFields,\n\t\t\t\t...(updatedField ? { [name]: updatedField } : {}),\n\t\t\t},\n\t\t}\n\t}\n\nexport const updateEveryField = (fieldUpdater: FieldUpdater<Model.AnyField, Model.AnyField>): EntityUpdater => args => ({\n\t...args.entity,\n\tfields: Object.fromEntries(\n\t\tObject.entries(args.entity.fields)\n\t\t\t.map(([name, field]) => {\n\t\t\t\tconst updatedField = fieldUpdater({ ...args, field })\n\t\t\t\tif (!updatedField) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn [name, updatedField]\n\t\t\t})\n\t\t\t.filter(isDefined),\n\t),\n})\n\nexport const addField = (field: Model.AnyField): EntityUpdater => args => {\n\treturn {\n\t\t...args.entity,\n\t\tfields: {\n\t\t\t...args.entity.fields,\n\t\t\t[field.name]: field,\n\t\t},\n\t}\n}\n\nexport const removeField = (entityName: string, fieldName: string, version: number): SchemaUpdater => {\n\treturn ({ schema }) => {\n\t\tconst entity = schema.model.entities[entityName]\n\t\tconst field = entity.fields[fieldName]\n\t\treturn updateSchema(\n\t\t\tversion >= VERSION_ACL_PATCH\n\t\t\t\t? updateAcl(\n\t\t\t\t\tupdateAclEveryRole(\n\t\t\t\t\t\tupdateAclEveryEntity(\n\t\t\t\t\t\t\tupdateAclFieldPermissions((permissions, entityName) => {\n\t\t\t\t\t\t\t\tif (entityName !== entity.name) {\n\t\t\t\t\t\t\t\t\treturn permissions\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst { [fieldName]: field, ...other } = permissions\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...other,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tupdateAclEveryPredicate(({ predicate, entityName }) => {\n\t\t\t\t\t\t\t\tconst processor = new PredicateDefinitionProcessor(schema.model)\n\t\t\t\t\t\t\t\treturn processor.process(schema.model.entities[entityName], predicate, {\n\t\t\t\t\t\t\t\t\thandleColumn: ctx => ctx.entity.name === entity.name && ctx.column.name === field.name ? undefined : ctx.value,\n\t\t\t\t\t\t\t\t\thandleRelation: ctx => ctx.entity.name === entity.name && ctx.relation.name === field.name ? undefined : ctx.value,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t: undefined,\n\t\t\tisRelation(field)\n\t\t\t\t&& isOwningRelation(field)\n\t\t\t\t&& field.inversedBy\n\t\t\t\t&& version >= VERSION_REMOVE_RELATION_INVERSE_SIDE\n\t\t\t\t? removeField(field.target, field.inversedBy, version)\n\t\t\t\t: undefined,\n\t\t\tupdateModel(\n\t\t\t\tupdateEntity(entity.name, ({ entity }) => {\n\t\t\t\t\tconst { [field.name]: removed, ...fields } = entity.fields\n\t\t\t\t\tconst indexes = entity.indexes.filter(index => !index.fields.includes(field.name))\n\t\t\t\t\tconst unique = entity.unique.filter(index => !index.fields.includes(field.name))\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...entity,\n\t\t\t\t\t\tfields,\n\t\t\t\t\t\tindexes,\n\t\t\t\t\t\tunique,\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t\tisRelation(field) && isInverseRelation(field)\n\t\t\t\t\t? updateEntity(\n\t\t\t\t\t\tfield.target,\n\t\t\t\t\t\tupdateField<Model.AnyOwningRelation>(field.ownedBy, ({ field: { inversedBy, ...field } }) => field),\n\t\t\t\t\t)\n\t\t\t\t\t: undefined,\n\t\t\t),\n\t\t)({ schema })\n\t}\n}\n"],"names":["isDefined","schema","updater","Acl","SchemaUpdateError","VERSION_ACL_PATCH","entityName","field","PredicateDefinitionProcessor","isRelation","isOwningRelation","VERSION_REMOVE_RELATION_INVERSE_SIDE","entity","isInverseRelation"],"mappings":";;;;;;;AA+CO,MAAM,eAAe,IAAI,kBAAgE,CAAA,SAC/F,cAAc,OAAOA,UAAAA,SAAS,EAAE,OAAO,CAACC,SAAQ,YAAY,QAAQ,EAAE,GAAG,MAAM,QAAAA,SAAQ,GAAG,KAAK,MAAM;AAE/F,MAAM,YAAY,CAAC,YAAuC,CAAA,UAAS;AAAA,EACzE,GAAG,KAAK;AAAA,EACR,KAAK,QAAQ,EAAE,QAAQ,KAAK,QAAQ,KAAK,KAAK,OAAO,IAAA,CAAK;AAC3D;AAEO,MAAM,qBAAqB,IAAI,YAA0C,CAAA,UAAS;AAAA,EACxF,GAAG,KAAK;AAAA,EACR,OAAO,OAAO;AAAA,IACb,QAAQ;AAAA,MACP,CAAC,KAAKC,aAAY,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,MAAMA,SAAQ,EAAE,GAAG,MAAM,KAAA,CAAM,CAAC,CAAC;AAAA,MAC9E,OAAO,QAAQ,KAAK,IAAI,KAAK;AAAA,IAAA;AAAA,EAC9B;AAEF;AAEO,MAAM,oBAAoB,CAAC,YAAmD,CAAA,UAAS;AAAA,EAC7F,GAAG,KAAK;AAAA,EACR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AK,KAAKI,8BAAkB,KAAK,IACzC;AAAA,UACD,MAAM;AAAA,UACN,YAAqC,MAAM,SAAS,CAAC,EAAE,OAAO,EAAE,YAAY,GAAGN,OAAAA,EAAM,MAAQA,MAAK;AAAA,QAAA,IAEjG;AAAA,MAAA;AAAA,IACJ,EACC,EAAE,QAAAN,QAAA,CAAQ;AAAA,EACb;AACD;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaUpdateUtils.js","sources":["../../../../../../packages/schema-migrations/src/modifications/utils/schemaUpdateUtils.ts"],"sourcesContent":["import { Acl, Model, Schema, Writable } from '@contember/schema'\nimport { SchemaUpdateError } from '../exceptions'\nimport { isDefined } from '../../utils/isDefined'\nimport { isInverseRelation, isOwningRelation, isRelation, PredicateDefinitionProcessor } from '@contember/schema-utils'\nimport { VERSION_ACL_PATCH, VERSION_REMOVE_RELATION_INVERSE_SIDE } from '../ModificationVersions'\n\nexport type SchemaUpdater = (args: { schema: Schema }) => Schema\nexport type ModelUpdater = (args: { schema: Schema; model: Model.Schema }) => Model.Schema\nexport type EntityUpdater = (args: { schema: Schema; model: Model.Schema; entity: Model.Entity }) => Model.Entity\nexport type FieldUpdater<In extends Model.AnyField, Out extends Model.AnyField> = (args: {\n\tschema: Schema\n\tmodel: Model.Schema\n\tentity: Model.Entity\n\tfield: In\n}) => Out | undefined\nexport type AclUpdater = (args: { schema: Schema; acl: Acl.Schema }) => Acl.Schema\nexport type AclRoleUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n}) => Acl.RolePermissions\nexport type AclPermissionsUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n\tentities: Acl.Permissions\n}) => Acl.Permissions\n\nexport type AclEntityPermissionsUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n\tentities: Acl.Permissions\n\tentityName: string\n\tentityPermissions: Acl.EntityPermissions\n}) => Acl.EntityPermissions\n\nexport type EntityAclEveryPredicatesUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n\tentities: Acl.Permissions\n\tentityName: string\n\tentityPermissions: Acl.EntityPermissions\n\tpredicate: Acl.PredicateDefinition\n}) => Acl.PredicateDefinition\n\nexport const updateSchema = (...schemaUpdater: (SchemaUpdater | undefined)[]): SchemaUpdater => args =>\n\tschemaUpdater.filter(isDefined).reduce((schema, updater) => updater({ ...args, schema }), args.schema)\n\nexport const updateAcl = (updater: AclUpdater): SchemaUpdater => args => ({\n\t...args.schema,\n\tacl: updater({ schema: args.schema, acl: args.schema.acl }),\n})\n\nexport const updateAclEveryRole = (...updater: AclRoleUpdater[]): AclUpdater => args => ({\n\t...args.acl,\n\troles: Object.fromEntries(\n\t\tupdater.reduce(\n\t\t\t(acc, updater) => acc.map(([name, role]) => [name, updater({ ...args, role })]),\n\t\t\tObject.entries(args.acl.roles),\n\t\t),\n\t),\n})\n\nexport const updateAclEntities = (updater: AclPermissionsUpdater): AclRoleUpdater => args => ({\n\t...args.role,\n\tentities: updater({ ...args, entities: args.role.entities }),\n})\n\nexport const updateAclEveryEntity = (...updater: AclEntityPermissionsUpdater[]): AclRoleUpdater => args => ({\n\t...args.role,\n\tentities: Object.fromEntries(\n\t\tupdater.reduce(\n\t\t\t(acc, updater) =>\n\t\t\t\tacc.map(([entity, entityPermissions]) => [\n\t\t\t\t\tentity,\n\t\t\t\t\tupdater({\n\t\t\t\t\t\t...args,\n\t\t\t\t\t\tentities: args.role.entities,\n\t\t\t\t\t\tentityName: entity,\n\t\t\t\t\t\tentityPermissions,\n\t\t\t\t\t}),\n\t\t\t\t]),\n\t\t\tObject.entries(args.role.entities),\n\t\t),\n\t),\n})\n\ntype EntityAclFieldPermissionsUpdater = (\n\tfieldPermissions: Acl.FieldPermissions,\n\tentityName: string,\n\toperation: Acl.Operation,\n) => Acl.FieldPermissions\ntype EntityOperationHandler = {\n\t[K in keyof Required<Acl.EntityOperations>]: (\n\t\tvalue: Exclude<Acl.EntityOperations[K], undefined>,\n\t) => Acl.EntityOperations[K]\n}\n\nexport const updateAclFieldPermissions =\n\t(updater: EntityAclFieldPermissionsUpdater): AclEntityPermissionsUpdater => ({ entityPermissions, entityName }) => {\n\t\tconst operations: Writable<Acl.EntityOperations> = {}\n\t\tconst handlers: EntityOperationHandler = {\n\t\t\tcreate: value => updater(value, entityName, Acl.Operation.create),\n\t\t\tupdate: value => updater(value, entityName, Acl.Operation.update),\n\t\t\tread: value => updater(value, entityName, Acl.Operation.read),\n\t\t\tdelete: value => value,\n\t\t\tcustomPrimary: value => value,\n\t\t\trefreshMaterializedView: value => value,\n\t\t\tnoRoot: value => value,\n\t\t}\n\t\tconst types: (keyof Acl.EntityOperations)[] = ['create', 'update', 'read', 'delete', 'customPrimary', 'noRoot']\n\t\tfor (const key of types) {\n\t\t\tif (key in entityPermissions.operations) {\n\t\t\t\toperations[key] = handlers[key](entityPermissions.operations[key] as any) as any\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t...entityPermissions,\n\t\t\toperations,\n\t\t}\n\t}\n\nexport const updateAclEveryPredicate = (updater: EntityAclEveryPredicatesUpdater): AclEntityPermissionsUpdater => args => {\n\treturn {\n\t\t...args.entityPermissions,\n\t\tpredicates: Object.fromEntries(\n\t\t\tObject.entries(args.entityPermissions.predicates).map(([name, predicate]) => [\n\t\t\t\tname,\n\t\t\t\tupdater({\n\t\t\t\t\t...args,\n\t\t\t\t\tpredicate,\n\t\t\t\t}),\n\t\t\t]),\n\t\t),\n\t}\n}\n\nexport const updateModel = (...modelUpdate: (ModelUpdater | undefined)[]): SchemaUpdater => args => ({\n\t...args.schema,\n\tmodel: modelUpdate\n\t\t.filter((it): it is ModelUpdater => it !== undefined)\n\t\t.reduce((model, updater) => updater({ ...args, model }), args.schema.model),\n})\n\nexport const updateEntity = (name: string, entityUpdate: EntityUpdater): ModelUpdater => args => {\n\tif (!args.model.entities[name]) {\n\t\tthrow new SchemaUpdateError(`Entity ${name} not found`)\n\t}\n\treturn {\n\t\t...args.model,\n\t\tentities: {\n\t\t\t...args.model.entities,\n\t\t\t[name]: entityUpdate({ ...args, entity: args.model.entities[name] }),\n\t\t},\n\t}\n}\n\nexport const updateEveryEntity = (entityUpdate: EntityUpdater): ModelUpdater => args => ({\n\t...args.model,\n\tentities: Object.fromEntries(\n\t\tObject.entries(args.model.entities).map(([name, entity]) => [name, entityUpdate({ ...args, entity })]),\n\t),\n})\n\nexport const updateField =\n\t<In extends Model.AnyField = Model.AnyField, Out extends Model.AnyField = In>(name: string, fieldUpdater: FieldUpdater<In, Out>): EntityUpdater =>\n\targs => {\n\t\tconst { [name]: field, ...otherFields } = args.entity.fields\n\t\tif (!args.entity.fields[name]) {\n\t\t\tthrow new SchemaUpdateError(`Field ${args.entity.name}::${name} not found`)\n\t\t}\n\t\tconst updatedField = fieldUpdater({ ...args, field: args.entity.fields[name] as In })\n\n\t\treturn {\n\t\t\t...args.entity,\n\t\t\tfields: {\n\t\t\t\t...otherFields,\n\t\t\t\t...(updatedField ? { [name]: updatedField } : {}),\n\t\t\t},\n\t\t}\n\t}\n\nexport const updateEveryField = (fieldUpdater: FieldUpdater<Model.AnyField, Model.AnyField>): EntityUpdater => args => ({\n\t...args.entity,\n\tfields: Object.fromEntries(\n\t\tObject.entries(args.entity.fields)\n\t\t\t.map(([name, field]) => {\n\t\t\t\tconst updatedField = fieldUpdater({ ...args, field })\n\t\t\t\tif (!updatedField) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn [name, updatedField]\n\t\t\t})\n\t\t\t.filter(isDefined),\n\t),\n})\n\nexport const addField = (field: Model.AnyField): EntityUpdater => args => {\n\treturn {\n\t\t...args.entity,\n\t\tfields: {\n\t\t\t...args.entity.fields,\n\t\t\t[field.name]: field,\n\t\t},\n\t}\n}\n\nexport const removeField = (entityName: string, fieldName: string, version: number): SchemaUpdater => {\n\treturn ({ schema }) => {\n\t\tconst entity = schema.model.entities[entityName]\n\t\tconst field = entity.fields[fieldName]\n\t\treturn updateSchema(\n\t\t\tversion >= VERSION_ACL_PATCH\n\t\t\t\t? updateAcl(\n\t\t\t\t\tupdateAclEveryRole(\n\t\t\t\t\t\tupdateAclEveryEntity(\n\t\t\t\t\t\t\tupdateAclFieldPermissions((permissions, entityName) => {\n\t\t\t\t\t\t\t\tif (entityName !== entity.name) {\n\t\t\t\t\t\t\t\t\treturn permissions\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst { [fieldName]: field, ...other } = permissions\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...other,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tupdateAclEveryPredicate(({ predicate, entityName }) => {\n\t\t\t\t\t\t\t\tconst processor = new PredicateDefinitionProcessor(schema.model)\n\t\t\t\t\t\t\t\treturn processor.process(schema.model.entities[entityName], predicate, {\n\t\t\t\t\t\t\t\t\thandleColumn: ctx => ctx.entity.name === entity.name && ctx.column.name === field.name ? undefined : ctx.value,\n\t\t\t\t\t\t\t\t\thandleRelation: ctx => ctx.entity.name === entity.name && ctx.relation.name === field.name ? undefined : ctx.value,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t: undefined,\n\t\t\tisRelation(field)\n\t\t\t\t&& isOwningRelation(field)\n\t\t\t\t&& field.inversedBy\n\t\t\t\t&& version >= VERSION_REMOVE_RELATION_INVERSE_SIDE\n\t\t\t\t? removeField(field.target, field.inversedBy, version)\n\t\t\t\t: undefined,\n\t\t\tupdateModel(\n\t\t\t\tupdateEntity(entity.name, ({ entity }) => {\n\t\t\t\t\tconst { [field.name]: removed, ...fields } = entity.fields\n\t\t\t\t\tconst indexes = entity.indexes.filter(index => !index.fields.includes(field.name))\n\t\t\t\t\tconst unique = entity.unique.filter(index => !index.fields.includes(field.name))\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...entity,\n\t\t\t\t\t\tfields,\n\t\t\t\t\t\tindexes,\n\t\t\t\t\t\tunique,\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t\tisRelation(field) && isInverseRelation(field)\n\t\t\t\t\t? updateEntity(\n\t\t\t\t\t\tfield.target,\n\t\t\t\t\t\tupdateField<Model.AnyOwningRelation>(field.ownedBy, ({ field: { inversedBy, ...field } }) => field),\n\t\t\t\t\t)\n\t\t\t\t\t: undefined,\n\t\t\t),\n\t\t)({ schema })\n\t}\n}\n"],"names":["updater","entityName","field","entity"],"mappings":";;;;;AA+CO,MAAM,eAAe,IAAI,kBAAgE,CAAA,SAC/F,cAAc,OAAO,SAAS,EAAE,OAAO,CAAC,QAAQ,YAAY,QAAQ,EAAE,GAAG,MAAM,QAAQ,GAAG,KAAK,MAAM;AAE/F,MAAM,YAAY,CAAC,YAAuC,CAAA,UAAS;AAAA,EACzE,GAAG,KAAK;AAAA,EACR,KAAK,QAAQ,EAAE,QAAQ,KAAK,QAAQ,KAAK,KAAK,OAAO,IAAA,CAAK;AAC3D;AAEO,MAAM,qBAAqB,IAAI,YAA0C,CAAA,UAAS;AAAA,EACxF,GAAG,KAAK;AAAA,EACR,OAAO,OAAO;AAAA,IACb,QAAQ;AAAA,MACP,CAAC,KAAKA,aAAY,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,MAAMA,SAAQ,EAAE,GAAG,MAAM,KAAA,CAAM,CAAC,CAAC;AAAA,MAC9E,OAAO,QAAQ,KAAK,IAAI,KAAK;AAAA,IAAA;AAAA,EAC9B;AAEF;AAEO,MAAM,oBAAoB,CAAC,YAAmD,CAAA,UAAS;AAAA,EAC7F,GAAG,KAAK;AAAA,EACR,UAAU,QAAQ,EAAE,GAAG,MAAM,UAAU,KAAK,KAAK,SAAA,CAAU;AAC5D;AAEO,MAAM,uBAAuB,IAAI,YAA2D,CA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AA,EACb;AACD;"}
|
|
1
|
+
{"version":3,"file":"schemaUpdateUtils.js","sources":["../../../../../../packages/schema-migrations/src/modifications/utils/schemaUpdateUtils.ts"],"sourcesContent":["import { Acl, Model, Schema, Writable } from '@contember/schema'\nimport { SchemaUpdateError } from '../exceptions.js'\nimport { isDefined } from '../../utils/isDefined.js'\nimport { isInverseRelation, isOwningRelation, isRelation, PredicateDefinitionProcessor } from '@contember/schema-utils'\nimport { VERSION_ACL_PATCH, VERSION_REMOVE_RELATION_INVERSE_SIDE } from '../ModificationVersions.js'\n\nexport type SchemaUpdater = (args: { schema: Schema }) => Schema\nexport type ModelUpdater = (args: { schema: Schema; model: Model.Schema }) => Model.Schema\nexport type EntityUpdater = (args: { schema: Schema; model: Model.Schema; entity: Model.Entity }) => Model.Entity\nexport type FieldUpdater<In extends Model.AnyField, Out extends Model.AnyField> = (args: {\n\tschema: Schema\n\tmodel: Model.Schema\n\tentity: Model.Entity\n\tfield: In\n}) => Out | undefined\nexport type AclUpdater = (args: { schema: Schema; acl: Acl.Schema }) => Acl.Schema\nexport type AclRoleUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n}) => Acl.RolePermissions\nexport type AclPermissionsUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n\tentities: Acl.Permissions\n}) => Acl.Permissions\n\nexport type AclEntityPermissionsUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n\tentities: Acl.Permissions\n\tentityName: string\n\tentityPermissions: Acl.EntityPermissions\n}) => Acl.EntityPermissions\n\nexport type EntityAclEveryPredicatesUpdater = (args: {\n\tschema: Schema\n\tacl: Acl.Schema\n\trole: Acl.RolePermissions\n\tentities: Acl.Permissions\n\tentityName: string\n\tentityPermissions: Acl.EntityPermissions\n\tpredicate: Acl.PredicateDefinition\n}) => Acl.PredicateDefinition\n\nexport const updateSchema = (...schemaUpdater: (SchemaUpdater | undefined)[]): SchemaUpdater => args =>\n\tschemaUpdater.filter(isDefined).reduce((schema, updater) => updater({ ...args, schema }), args.schema)\n\nexport const updateAcl = (updater: AclUpdater): SchemaUpdater => args => ({\n\t...args.schema,\n\tacl: updater({ schema: args.schema, acl: args.schema.acl }),\n})\n\nexport const updateAclEveryRole = (...updater: AclRoleUpdater[]): AclUpdater => args => ({\n\t...args.acl,\n\troles: Object.fromEntries(\n\t\tupdater.reduce(\n\t\t\t(acc, updater) => acc.map(([name, role]) => [name, updater({ ...args, role })]),\n\t\t\tObject.entries(args.acl.roles),\n\t\t),\n\t),\n})\n\nexport const updateAclEntities = (updater: AclPermissionsUpdater): AclRoleUpdater => args => ({\n\t...args.role,\n\tentities: updater({ ...args, entities: args.role.entities }),\n})\n\nexport const updateAclEveryEntity = (...updater: AclEntityPermissionsUpdater[]): AclRoleUpdater => args => ({\n\t...args.role,\n\tentities: Object.fromEntries(\n\t\tupdater.reduce(\n\t\t\t(acc, updater) =>\n\t\t\t\tacc.map(([entity, entityPermissions]) => [\n\t\t\t\t\tentity,\n\t\t\t\t\tupdater({\n\t\t\t\t\t\t...args,\n\t\t\t\t\t\tentities: args.role.entities,\n\t\t\t\t\t\tentityName: entity,\n\t\t\t\t\t\tentityPermissions,\n\t\t\t\t\t}),\n\t\t\t\t]),\n\t\t\tObject.entries(args.role.entities),\n\t\t),\n\t),\n})\n\ntype EntityAclFieldPermissionsUpdater = (\n\tfieldPermissions: Acl.FieldPermissions,\n\tentityName: string,\n\toperation: Acl.Operation,\n) => Acl.FieldPermissions\ntype EntityOperationHandler = {\n\t[K in keyof Required<Acl.EntityOperations>]: (\n\t\tvalue: Exclude<Acl.EntityOperations[K], undefined>,\n\t) => Acl.EntityOperations[K]\n}\n\nexport const updateAclFieldPermissions =\n\t(updater: EntityAclFieldPermissionsUpdater): AclEntityPermissionsUpdater => ({ entityPermissions, entityName }) => {\n\t\tconst operations: Writable<Acl.EntityOperations> = {}\n\t\tconst handlers: EntityOperationHandler = {\n\t\t\tcreate: value => updater(value, entityName, Acl.Operation.create),\n\t\t\tupdate: value => updater(value, entityName, Acl.Operation.update),\n\t\t\tread: value => updater(value, entityName, Acl.Operation.read),\n\t\t\tdelete: value => value,\n\t\t\tcustomPrimary: value => value,\n\t\t\trefreshMaterializedView: value => value,\n\t\t\tnoRoot: value => value,\n\t\t}\n\t\tconst types: (keyof Acl.EntityOperations)[] = ['create', 'update', 'read', 'delete', 'customPrimary', 'noRoot']\n\t\tfor (const key of types) {\n\t\t\tif (key in entityPermissions.operations) {\n\t\t\t\toperations[key] = handlers[key](entityPermissions.operations[key] as any) as any\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t...entityPermissions,\n\t\t\toperations,\n\t\t}\n\t}\n\nexport const updateAclEveryPredicate = (updater: EntityAclEveryPredicatesUpdater): AclEntityPermissionsUpdater => args => {\n\treturn {\n\t\t...args.entityPermissions,\n\t\tpredicates: Object.fromEntries(\n\t\t\tObject.entries(args.entityPermissions.predicates).map(([name, predicate]) => [\n\t\t\t\tname,\n\t\t\t\tupdater({\n\t\t\t\t\t...args,\n\t\t\t\t\tpredicate,\n\t\t\t\t}),\n\t\t\t]),\n\t\t),\n\t}\n}\n\nexport const updateModel = (...modelUpdate: (ModelUpdater | undefined)[]): SchemaUpdater => args => ({\n\t...args.schema,\n\tmodel: modelUpdate\n\t\t.filter((it): it is ModelUpdater => it !== undefined)\n\t\t.reduce((model, updater) => updater({ ...args, model }), args.schema.model),\n})\n\nexport const updateEntity = (name: string, entityUpdate: EntityUpdater): ModelUpdater => args => {\n\tif (!args.model.entities[name]) {\n\t\tthrow new SchemaUpdateError(`Entity ${name} not found`)\n\t}\n\treturn {\n\t\t...args.model,\n\t\tentities: {\n\t\t\t...args.model.entities,\n\t\t\t[name]: entityUpdate({ ...args, entity: args.model.entities[name] }),\n\t\t},\n\t}\n}\n\nexport const updateEveryEntity = (entityUpdate: EntityUpdater): ModelUpdater => args => ({\n\t...args.model,\n\tentities: Object.fromEntries(\n\t\tObject.entries(args.model.entities).map(([name, entity]) => [name, entityUpdate({ ...args, entity })]),\n\t),\n})\n\nexport const updateField =\n\t<In extends Model.AnyField = Model.AnyField, Out extends Model.AnyField = In>(name: string, fieldUpdater: FieldUpdater<In, Out>): EntityUpdater =>\n\targs => {\n\t\tconst { [name]: field, ...otherFields } = args.entity.fields\n\t\tif (!args.entity.fields[name]) {\n\t\t\tthrow new SchemaUpdateError(`Field ${args.entity.name}::${name} not found`)\n\t\t}\n\t\tconst updatedField = fieldUpdater({ ...args, field: args.entity.fields[name] as In })\n\n\t\treturn {\n\t\t\t...args.entity,\n\t\t\tfields: {\n\t\t\t\t...otherFields,\n\t\t\t\t...(updatedField ? { [name]: updatedField } : {}),\n\t\t\t},\n\t\t}\n\t}\n\nexport const updateEveryField = (fieldUpdater: FieldUpdater<Model.AnyField, Model.AnyField>): EntityUpdater => args => ({\n\t...args.entity,\n\tfields: Object.fromEntries(\n\t\tObject.entries(args.entity.fields)\n\t\t\t.map(([name, field]) => {\n\t\t\t\tconst updatedField = fieldUpdater({ ...args, field })\n\t\t\t\tif (!updatedField) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn [name, updatedField]\n\t\t\t})\n\t\t\t.filter(isDefined),\n\t),\n})\n\nexport const addField = (field: Model.AnyField): EntityUpdater => args => {\n\treturn {\n\t\t...args.entity,\n\t\tfields: {\n\t\t\t...args.entity.fields,\n\t\t\t[field.name]: field,\n\t\t},\n\t}\n}\n\nexport const removeField = (entityName: string, fieldName: string, version: number): SchemaUpdater => {\n\treturn ({ schema }) => {\n\t\tconst entity = schema.model.entities[entityName]\n\t\tconst field = entity.fields[fieldName]\n\t\treturn updateSchema(\n\t\t\tversion >= VERSION_ACL_PATCH\n\t\t\t\t? updateAcl(\n\t\t\t\t\tupdateAclEveryRole(\n\t\t\t\t\t\tupdateAclEveryEntity(\n\t\t\t\t\t\t\tupdateAclFieldPermissions((permissions, entityName) => {\n\t\t\t\t\t\t\t\tif (entityName !== entity.name) {\n\t\t\t\t\t\t\t\t\treturn permissions\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst { [fieldName]: field, ...other } = permissions\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...other,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tupdateAclEveryPredicate(({ predicate, entityName }) => {\n\t\t\t\t\t\t\t\tconst processor = new PredicateDefinitionProcessor(schema.model)\n\t\t\t\t\t\t\t\treturn processor.process(schema.model.entities[entityName], predicate, {\n\t\t\t\t\t\t\t\t\thandleColumn: ctx => ctx.entity.name === entity.name && ctx.column.name === field.name ? undefined : ctx.value,\n\t\t\t\t\t\t\t\t\thandleRelation: ctx => ctx.entity.name === entity.name && ctx.relation.name === field.name ? undefined : ctx.value,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t: undefined,\n\t\t\tisRelation(field)\n\t\t\t\t&& isOwningRelation(field)\n\t\t\t\t&& field.inversedBy\n\t\t\t\t&& version >= VERSION_REMOVE_RELATION_INVERSE_SIDE\n\t\t\t\t? removeField(field.target, field.inversedBy, version)\n\t\t\t\t: undefined,\n\t\t\tupdateModel(\n\t\t\t\tupdateEntity(entity.name, ({ entity }) => {\n\t\t\t\t\tconst { [field.name]: removed, ...fields } = entity.fields\n\t\t\t\t\tconst indexes = entity.indexes.filter(index => !index.fields.includes(field.name))\n\t\t\t\t\tconst unique = entity.unique.filter(index => !index.fields.includes(field.name))\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...entity,\n\t\t\t\t\t\tfields,\n\t\t\t\t\t\tindexes,\n\t\t\t\t\t\tunique,\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t\tisRelation(field) && isInverseRelation(field)\n\t\t\t\t\t? updateEntity(\n\t\t\t\t\t\tfield.target,\n\t\t\t\t\t\tupdateField<Model.AnyOwningRelation>(field.ownedBy, ({ field: { inversedBy, ...field } }) => field),\n\t\t\t\t\t)\n\t\t\t\t\t: undefined,\n\t\t\t),\n\t\t)({ schema })\n\t}\n}\n"],"names":["updater","entityName","field","entity"],"mappings":";;;;;AA+CO,MAAM,eAAe,IAAI,kBAAgE,CAAA,SAC/F,cAAc,OAAO,SAAS,EAAE,OAAO,CAAC,QAAQ,YAAY,QAAQ,EAAE,GAAG,MAAM,QAAQ,GAAG,KAAK,MAAM;AAE/F,MAAM,YAAY,CAAC,YAAuC,CAAA,UAAS;AAAA,EACzE,GAAG,KAAK;AAAA,EACR,KAAK,QAAQ,EAAE,QAAQ,KAAK,QAAQ,KAAK,KAAK,OAAO,IAAA,CAAK;AAC3D;AAEO,MAAM,qBAAqB,IAAI,YAA0C,CAAA,UAAS;AAAA,EACxF,GAAG,KAAK;AAAA,EACR,OAAO,OAAO;AAAA,IACb,QAAQ;AAAA,MACP,CAAC,KAAKA,aAAY,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,MAAMA,SAAQ,EAAE,GAAG,MAAM,KAAA,CAAM,CAAC,CAAC;AAAA,MAC9E,OAAO,QAAQ,KAAK,IAAI,KAAK;AAAA,IAAA;AAAA,EAC9B;AAEF;AAEO,MAAM,oBAAoB,CAAC,YAAmD,CAAA,UAAS;AAAA,EAC7F,GAAG,KAAK;AAAA,EACR,UAAU,QAAQ,EAAE,GAAG,MAAM,UAAU,KAAK,KAAK,SAAA,CAAU;AAC5D;AAEO,MAAM,uBAAuB,IAAI,YAA2D,CAAA,UAAS;AAAA,EAC3G,GAAG,KAAK;AAAA,EACR,UAAU,OAAO;AAAA,IAChB,QAAQ;AAAA,MACP,CAAC,KAAKA,aACL,IAAI,IAAI,CAAC,CAAC,QAAQ,iBAAiB,MAAM;AAAA,QACxC;AAAA,QACAA,SAAQ;AAAA,UACP,GAAG;AAAA,UACH,UAAU,KAAK,KAAK;AAAA,UACpB,YAAY;AAA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,SAAS,MAAM,OAAO,SAAY,IAAI;AAAA,gBACzG,gBAAgB,CAAA,QAAO,IAAI,OAAO,SAAS,OAAO,QAAQ,IAAI,SAAS,SAAS,MAAM,OAAO,SAAY,IAAI;AAAA,cAAA,CAC7G;AAAA,YACF,CAAC;AAAA,UAAA;AAAA,QACF;AAAA,MACD,IAEC;AAAA,MACH,WAAW,KAAK,KACZ,iBAAiB,KAAK,KACtB,MAAM,cACN,WAAW,uCACZ,YAAY,MAAM,QAAQ,MAAM,YAAY,OAAO,IACnD;AAAA,MACH;AAAA,QACC,aAAa,OAAO,MAAM,CAAC,EAAE,QAAAE,cAAa;AACzC,gBAAM,EAAE,CAAC,MAAM,IAAI,GAAG,SAAS,GAAG,OAAA,IAAWA,QAAO;AACpD,gBAAM,UAAUA,QAAO,QAAQ,OAAO,CAAA,UAAS,CAAC,MAAM,OAAO,SAAS,MAAM,IAAI,CAAC;AACjF,gBAAM,SAASA,QAAO,OAAO,OAAO,CAAA,UAAS,CAAC,MAAM,OAAO,SAAS,MAAM,IAAI,CAAC;AAC/E,iBAAO;AAAA,YACN,GAAGA;AAAAA,YACH;AAAA,YACA;AAAA,YACA;AAAA,UAAA;AAAA,QAEF,CAAC;AAAA,QACD,WAAW,KAAK,KAAK,kBAAkB,KAAK,IACzC;AAAA,UACD,MAAM;AAAA,UACN,YAAqC,MAAM,SAAS,CAAC,EAAE,OAAO,EAAE,YAAY,GAAGD,OAAAA,EAAM,MAAQA,MAAK;AAAA,QAAA,IAEjG;AAAA,MAAA;AAAA,IACJ,EACC,EAAE,OAAA,CAAQ;AAAA,EACb;AACD;"}
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const deepEqual = require("fast-deep-equal");
|
|
3
4
|
require("@contember/schema");
|
|
4
5
|
require("@contember/schema-utils");
|
|
5
6
|
const RemoveEntityModification = require("../entities/RemoveEntityModification.cjs");
|
|
6
|
-
|
|
7
|
+
const isReplaceableViewChange = (original, updated) => {
|
|
8
|
+
if (!original.view || !updated.view) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (original.view.materialized || updated.view.materialized) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const stripView = (entity) => {
|
|
15
|
+
const { view, ...rest } = entity;
|
|
16
|
+
return rest;
|
|
17
|
+
};
|
|
18
|
+
return deepEqual(stripView(original), stripView(updated));
|
|
19
|
+
};
|
|
7
20
|
const getEntityDependantViews = (model) => {
|
|
8
21
|
const dependants = new Map(Object.values(model.entities).map((it) => [it.name, /* @__PURE__ */ new Set()]));
|
|
9
22
|
for (const entity of Object.values(model.entities)) {
|
|
@@ -43,4 +56,5 @@ const cascadeRemoveDependantViews = (model, entities) => {
|
|
|
43
56
|
};
|
|
44
57
|
exports.cascadeRemoveDependantViews = cascadeRemoveDependantViews;
|
|
45
58
|
exports.getEntityDependantViews = getEntityDependantViews;
|
|
59
|
+
exports.isReplaceableViewChange = isReplaceableViewChange;
|
|
46
60
|
//# sourceMappingURL=viewDependencies.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewDependencies.cjs","sources":["../../../../../../packages/schema-migrations/src/modifications/utils/viewDependencies.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { Migration } from '../../Migration'\nimport { removeEntityModification } from '../entities'\n\ntype EntityDependantViews = Map<string, Set<Model.Entity>>\nexport const getEntityDependantViews = (model: Model.Schema): EntityDependantViews => {\n\tconst dependants: EntityDependantViews = new Map(Object.values(model.entities).map(it => [it.name, new Set()]))\n\tfor (const entity of Object.values(model.entities)) {\n\t\tif (!entity.view?.dependencies?.length) {\n\t\t\tcontinue\n\t\t}\n\t\tfor (const dependency of entity.view.dependencies) {\n\t\t\tconst entityDependants = dependants.get(dependency)\n\t\t\tif (!entityDependants) {\n\t\t\t\tthrow new Error()\n\t\t\t}\n\t\t\tentityDependants.add(entity)\n\t\t}\n\t}\n\treturn dependants\n}\n\nexport const cascadeRemoveDependantViews = (model: Model.Schema, entities: Model.Entity[]): Migration.Modification[] => {\n\tconst visited = new Set<string>()\n\tconst dependants = getEntityDependantViews(model)\n\tconst modifications: Migration.Modification[] = []\n\tconst removeCascade = (entity: Model.Entity) => {\n\t\tif (visited.has(entity.name)) {\n\t\t\treturn\n\t\t}\n\t\tvisited.add(entity.name)\n\t\tfor (const dependant of dependants.get(entity.name) ?? []) {\n\t\t\tremoveCascade(dependant)\n\t\t}\n\t\tif (entity.view) {\n\t\t\tmodifications.push(removeEntityModification.createModification({ entityName: entity.name }))\n\t\t}\n\t}\n\tfor (const entity of entities) {\n\t\tremoveCascade(entity)\n\t}\n\treturn modifications\n}\n"],"names":["removeEntityModification"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"viewDependencies.cjs","sources":["../../../../../../packages/schema-migrations/src/modifications/utils/viewDependencies.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport deepEqual from 'fast-deep-equal'\nimport { Migration } from '../../Migration.js'\nimport { removeEntityModification } from '../entities/index.js'\n\n/**\n * Determines whether a view change can be applied in-place via `CREATE OR REPLACE VIEW`,\n * i.e. without dropping & recreating the view (and cascading to its dependants).\n *\n * Postgres allows `CREATE OR REPLACE VIEW` only when the output columns stay the same\n * (it may append new columns at the end). We conservatively allow it only when the\n * entity is structurally identical and just the view metadata (`sql`/`dependencies`/`idSource`)\n * differs. Materialized views are never replaceable (no `CREATE OR REPLACE MATERIALIZED VIEW`).\n */\nexport const isReplaceableViewChange = (original: Model.Entity, updated: Model.Entity): boolean => {\n\tif (!original.view || !updated.view) {\n\t\treturn false\n\t}\n\tif (original.view.materialized || updated.view.materialized) {\n\t\treturn false\n\t}\n\tconst stripView = (entity: Model.Entity): Omit<Model.Entity, 'view'> => {\n\t\tconst { view, ...rest } = entity\n\t\treturn rest\n\t}\n\treturn deepEqual(stripView(original), stripView(updated))\n}\n\ntype EntityDependantViews = Map<string, Set<Model.Entity>>\nexport const getEntityDependantViews = (model: Model.Schema): EntityDependantViews => {\n\tconst dependants: EntityDependantViews = new Map(Object.values(model.entities).map(it => [it.name, new Set()]))\n\tfor (const entity of Object.values(model.entities)) {\n\t\tif (!entity.view?.dependencies?.length) {\n\t\t\tcontinue\n\t\t}\n\t\tfor (const dependency of entity.view.dependencies) {\n\t\t\tconst entityDependants = dependants.get(dependency)\n\t\t\tif (!entityDependants) {\n\t\t\t\tthrow new Error()\n\t\t\t}\n\t\t\tentityDependants.add(entity)\n\t\t}\n\t}\n\treturn dependants\n}\n\nexport const cascadeRemoveDependantViews = (model: Model.Schema, entities: Model.Entity[]): Migration.Modification[] => {\n\tconst visited = new Set<string>()\n\tconst dependants = getEntityDependantViews(model)\n\tconst modifications: Migration.Modification[] = []\n\tconst removeCascade = (entity: Model.Entity) => {\n\t\tif (visited.has(entity.name)) {\n\t\t\treturn\n\t\t}\n\t\tvisited.add(entity.name)\n\t\tfor (const dependant of dependants.get(entity.name) ?? []) {\n\t\t\tremoveCascade(dependant)\n\t\t}\n\t\tif (entity.view) {\n\t\t\tmodifications.push(removeEntityModification.createModification({ entityName: entity.name }))\n\t\t}\n\t}\n\tfor (const entity of entities) {\n\t\tremoveCascade(entity)\n\t}\n\treturn modifications\n}\n"],"names":["removeEntityModification"],"mappings":";;;;;;AAcO,MAAM,0BAA0B,CAAC,UAAwB,YAAmC;AAClG,MAAI,CAAC,SAAS,QAAQ,CAAC,QAAQ,MAAM;AACpC,WAAO;AAAA,EACR;AACA,MAAI,SAAS,KAAK,gBAAgB,QAAQ,KAAK,cAAc;AAC5D,WAAO;AAAA,EACR;AACA,QAAM,YAAY,CAAC,WAAqD;AACvE,UAAM,EAAE,MAAM,GAAG,KAAA,IAAS;AAC1B,WAAO;AAAA,EACR;AACA,SAAO,UAAU,UAAU,QAAQ,GAAG,UAAU,OAAO,CAAC;AACzD;AAGO,MAAM,0BAA0B,CAAC,UAA8C;AACrF,QAAM,aAAmC,IAAI,IAAI,OAAO,OAAO,MAAM,QAAQ,EAAE,IAAI,CAAA,OAAM,CAAC,GAAG,0BAAU,IAAA,CAAK,CAAC,CAAC;AAC9G,aAAW,UAAU,OAAO,OAAO,MAAM,QAAQ,GAAG;AACnD,QAAI,CAAC,OAAO,MAAM,cAAc,QAAQ;AACvC;AAAA,IACD;AACA,eAAW,cAAc,OAAO,KAAK,cAAc;AAClD,YAAM,mBAAmB,WAAW,IAAI,UAAU;AAClD,UAAI,CAAC,kBAAkB;AACtB,cAAM,IAAI,MAAA;AAAA,MACX;AACA,uBAAiB,IAAI,MAAM;AAAA,IAC5B;AAAA,EACD;AACA,SAAO;AACR;AAEO,MAAM,8BAA8B,CAAC,OAAqB,aAAuD;AACvH,QAAM,8BAAc,IAAA;AACpB,QAAM,aAAa,wBAAwB,KAAK;AAChD,QAAM,gBAA0C,CAAA;AAChD,QAAM,gBAAgB,CAAC,WAAyB;AAC/C,QAAI,QAAQ,IAAI,OAAO,IAAI,GAAG;AAC7B;AAAA,IACD;AACA,YAAQ,IAAI,OAAO,IAAI;AACvB,eAAW,aAAa,WAAW,IAAI,OAAO,IAAI,KAAK,IAAI;AAC1D,oBAAc,SAAS;AAAA,IACxB;AACA,QAAI,OAAO,MAAM;AAChB,oBAAc,KAAKA,yBAAAA,yBAAyB,mBAAmB,EAAE,YAAY,OAAO,KAAA,CAAM,CAAC;AAAA,IAC5F;AAAA,EACD;AACA,aAAW,UAAU,UAAU;AAC9B,kBAAc,MAAM;AAAA,EACrB;AACA,SAAO;AACR;;;;"}
|
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
import deepEqual from "fast-deep-equal";
|
|
1
2
|
import "@contember/schema";
|
|
2
3
|
import "@contember/schema-utils";
|
|
3
4
|
import { removeEntityModification } from "../entities/RemoveEntityModification.js";
|
|
4
|
-
|
|
5
|
+
const isReplaceableViewChange = (original, updated) => {
|
|
6
|
+
if (!original.view || !updated.view) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (original.view.materialized || updated.view.materialized) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const stripView = (entity) => {
|
|
13
|
+
const { view, ...rest } = entity;
|
|
14
|
+
return rest;
|
|
15
|
+
};
|
|
16
|
+
return deepEqual(stripView(original), stripView(updated));
|
|
17
|
+
};
|
|
5
18
|
const getEntityDependantViews = (model) => {
|
|
6
19
|
const dependants = new Map(Object.values(model.entities).map((it) => [it.name, /* @__PURE__ */ new Set()]));
|
|
7
20
|
for (const entity of Object.values(model.entities)) {
|
|
@@ -41,6 +54,7 @@ const cascadeRemoveDependantViews = (model, entities) => {
|
|
|
41
54
|
};
|
|
42
55
|
export {
|
|
43
56
|
cascadeRemoveDependantViews,
|
|
44
|
-
getEntityDependantViews
|
|
57
|
+
getEntityDependantViews,
|
|
58
|
+
isReplaceableViewChange
|
|
45
59
|
};
|
|
46
60
|
//# sourceMappingURL=viewDependencies.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewDependencies.js","sources":["../../../../../../packages/schema-migrations/src/modifications/utils/viewDependencies.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { Migration } from '../../Migration'\nimport { removeEntityModification } from '../entities'\n\ntype EntityDependantViews = Map<string, Set<Model.Entity>>\nexport const getEntityDependantViews = (model: Model.Schema): EntityDependantViews => {\n\tconst dependants: EntityDependantViews = new Map(Object.values(model.entities).map(it => [it.name, new Set()]))\n\tfor (const entity of Object.values(model.entities)) {\n\t\tif (!entity.view?.dependencies?.length) {\n\t\t\tcontinue\n\t\t}\n\t\tfor (const dependency of entity.view.dependencies) {\n\t\t\tconst entityDependants = dependants.get(dependency)\n\t\t\tif (!entityDependants) {\n\t\t\t\tthrow new Error()\n\t\t\t}\n\t\t\tentityDependants.add(entity)\n\t\t}\n\t}\n\treturn dependants\n}\n\nexport const cascadeRemoveDependantViews = (model: Model.Schema, entities: Model.Entity[]): Migration.Modification[] => {\n\tconst visited = new Set<string>()\n\tconst dependants = getEntityDependantViews(model)\n\tconst modifications: Migration.Modification[] = []\n\tconst removeCascade = (entity: Model.Entity) => {\n\t\tif (visited.has(entity.name)) {\n\t\t\treturn\n\t\t}\n\t\tvisited.add(entity.name)\n\t\tfor (const dependant of dependants.get(entity.name) ?? []) {\n\t\t\tremoveCascade(dependant)\n\t\t}\n\t\tif (entity.view) {\n\t\t\tmodifications.push(removeEntityModification.createModification({ entityName: entity.name }))\n\t\t}\n\t}\n\tfor (const entity of entities) {\n\t\tremoveCascade(entity)\n\t}\n\treturn modifications\n}\n"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"viewDependencies.js","sources":["../../../../../../packages/schema-migrations/src/modifications/utils/viewDependencies.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport deepEqual from 'fast-deep-equal'\nimport { Migration } from '../../Migration.js'\nimport { removeEntityModification } from '../entities/index.js'\n\n/**\n * Determines whether a view change can be applied in-place via `CREATE OR REPLACE VIEW`,\n * i.e. without dropping & recreating the view (and cascading to its dependants).\n *\n * Postgres allows `CREATE OR REPLACE VIEW` only when the output columns stay the same\n * (it may append new columns at the end). We conservatively allow it only when the\n * entity is structurally identical and just the view metadata (`sql`/`dependencies`/`idSource`)\n * differs. Materialized views are never replaceable (no `CREATE OR REPLACE MATERIALIZED VIEW`).\n */\nexport const isReplaceableViewChange = (original: Model.Entity, updated: Model.Entity): boolean => {\n\tif (!original.view || !updated.view) {\n\t\treturn false\n\t}\n\tif (original.view.materialized || updated.view.materialized) {\n\t\treturn false\n\t}\n\tconst stripView = (entity: Model.Entity): Omit<Model.Entity, 'view'> => {\n\t\tconst { view, ...rest } = entity\n\t\treturn rest\n\t}\n\treturn deepEqual(stripView(original), stripView(updated))\n}\n\ntype EntityDependantViews = Map<string, Set<Model.Entity>>\nexport const getEntityDependantViews = (model: Model.Schema): EntityDependantViews => {\n\tconst dependants: EntityDependantViews = new Map(Object.values(model.entities).map(it => [it.name, new Set()]))\n\tfor (const entity of Object.values(model.entities)) {\n\t\tif (!entity.view?.dependencies?.length) {\n\t\t\tcontinue\n\t\t}\n\t\tfor (const dependency of entity.view.dependencies) {\n\t\t\tconst entityDependants = dependants.get(dependency)\n\t\t\tif (!entityDependants) {\n\t\t\t\tthrow new Error()\n\t\t\t}\n\t\t\tentityDependants.add(entity)\n\t\t}\n\t}\n\treturn dependants\n}\n\nexport const cascadeRemoveDependantViews = (model: Model.Schema, entities: Model.Entity[]): Migration.Modification[] => {\n\tconst visited = new Set<string>()\n\tconst dependants = getEntityDependantViews(model)\n\tconst modifications: Migration.Modification[] = []\n\tconst removeCascade = (entity: Model.Entity) => {\n\t\tif (visited.has(entity.name)) {\n\t\t\treturn\n\t\t}\n\t\tvisited.add(entity.name)\n\t\tfor (const dependant of dependants.get(entity.name) ?? []) {\n\t\t\tremoveCascade(dependant)\n\t\t}\n\t\tif (entity.view) {\n\t\t\tmodifications.push(removeEntityModification.createModification({ entityName: entity.name }))\n\t\t}\n\t}\n\tfor (const entity of entities) {\n\t\tremoveCascade(entity)\n\t}\n\treturn modifications\n}\n"],"names":[],"mappings":";;;;AAcO,MAAM,0BAA0B,CAAC,UAAwB,YAAmC;AAClG,MAAI,CAAC,SAAS,QAAQ,CAAC,QAAQ,MAAM;AACpC,WAAO;AAAA,EACR;AACA,MAAI,SAAS,KAAK,gBAAgB,QAAQ,KAAK,cAAc;AAC5D,WAAO;AAAA,EACR;AACA,QAAM,YAAY,CAAC,WAAqD;AACvE,UAAM,EAAE,MAAM,GAAG,KAAA,IAAS;AAC1B,WAAO;AAAA,EACR;AACA,SAAO,UAAU,UAAU,QAAQ,GAAG,UAAU,OAAO,CAAC;AACzD;AAGO,MAAM,0BAA0B,CAAC,UAA8C;AACrF,QAAM,aAAmC,IAAI,IAAI,OAAO,OAAO,MAAM,QAAQ,EAAE,IAAI,CAAA,OAAM,CAAC,GAAG,0BAAU,IAAA,CAAK,CAAC,CAAC;AAC9G,aAAW,UAAU,OAAO,OAAO,MAAM,QAAQ,GAAG;AACnD,QAAI,CAAC,OAAO,MAAM,cAAc,QAAQ;AACvC;AAAA,IACD;AACA,eAAW,cAAc,OAAO,KAAK,cAAc;AAClD,YAAM,mBAAmB,WAAW,IAAI,UAAU;AAClD,UAAI,CAAC,kBAAkB;AACtB,cAAM,IAAI,MAAA;AAAA,MACX;AACA,uBAAiB,IAAI,MAAM;AAAA,IAC5B;AAAA,EACD;AACA,SAAO;AACR;AAEO,MAAM,8BAA8B,CAAC,OAAqB,aAAuD;AACvH,QAAM,8BAAc,IAAA;AACpB,QAAM,aAAa,wBAAwB,KAAK;AAChD,QAAM,gBAA0C,CAAA;AAChD,QAAM,gBAAgB,CAAC,WAAyB;AAC/C,QAAI,QAAQ,IAAI,OAAO,IAAI,GAAG;AAC7B;AAAA,IACD;AACA,YAAQ,IAAI,OAAO,IAAI;AACvB,eAAW,aAAa,WAAW,IAAI,OAAO,IAAI,KAAK,IAAI;AAC1D,oBAAc,SAAS;AAAA,IACxB;AACA,QAAI,OAAO,MAAM;AAChB,oBAAc,KAAK,yBAAyB,mBAAmB,EAAE,YAAY,OAAO,KAAA,CAAM,CAAC;AAAA,IAC5F;AAAA,EACD;AACA,aAAW,UAAU,UAAU;AAC9B,kBAAc,MAAM;AAAA,EACrB;AACA,SAAO;AACR;"}
|
package/dist/development/src/modifications/validation/PatchValidationSchemaModification.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PatchValidationSchemaModification.cjs","sources":["../../../../../../packages/schema-migrations/src/modifications/validation/PatchValidationSchemaModification.ts"],"sourcesContent":["import { SchemaUpdater } from '../utils/schemaUpdateUtils'\nimport { createModificationType, ModificationHandler } from '../ModificationHandler'\nimport { applyPatch, Operation } from 'rfc6902'\nimport deepCopy from '../../utils/deepCopy'\n\nexport class PatchValidationSchemaModificationHandler implements ModificationHandler<PatchValidationSchemaModificationData> {\n\tconstructor(private readonly data: PatchValidationSchemaModificationData) {}\n\n\tpublic createSql(): void {}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn ({ schema }) => {\n\t\t\tconst validation = deepCopy(schema.validation)\n\t\t\tconst result = applyPatch(validation, this.data.patch).filter(it => it !== null)\n\t\t\tif (result.length > 0) {\n\t\t\t\tthrow result[0]\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...schema,\n\t\t\t\tvalidation,\n\t\t\t}\n\t\t}\n\t}\n\n\tdescribe() {\n\t\treturn { message: 'Update validation schema' }\n\t}\n}\n\nexport interface PatchValidationSchemaModificationData {\n\tpatch: Operation[]\n}\n\nexport const patchValidationSchemaModification = createModificationType({\n\tid: 'patchValidationSchema',\n\thandler: PatchValidationSchemaModificationHandler,\n})\n"],"names":["applyPatch","createModificationType"],"mappings":";;;;;AAKO,MAAM,yCAA+G;AAAA,EAC3H,YAA6B,MAA6C;AAA7C,SAAA,OAAA;AAAA,EAA8C;AAAA,EAEpE,YAAkB;AAAA,EAAC;AAAA,EAEnB,mBAAkC;AACxC,WAAO,CAAC,EAAE,aAAa;AACtB,YAAM,aAAa,SAAS,OAAO,UAAU;AAC7C,YAAM,SAASA,QAAAA,WAAW,YAAY,KAAK,KAAK,KAAK,EAAE,OAAO,CAAA,OAAM,OAAO,IAAI;AAC/E,UAAI,OAAO,SAAS,GAAG;AACtB,cAAM,OAAO,CAAC;AAAA,MACf;AAEA,aAAO;AAAA,QACN,GAAG;AAAA,QACH;AAAA,MAAA;AAAA,IAEF;AAAA,EACD;AAAA,EAEA,WAAW;AACV,WAAO,EAAE,SAAS,2BAAA;AAAA,EACnB;AACD;AAMO,MAAM,oCAAoCC,oBAAAA,uBAAuB;AAAA,EACvE,IAAI;AAAA,EACJ,SAAS;AACV,CAAC;;;"}
|
|
1
|
+
{"version":3,"file":"PatchValidationSchemaModification.cjs","sources":["../../../../../../packages/schema-migrations/src/modifications/validation/PatchValidationSchemaModification.ts"],"sourcesContent":["import { SchemaUpdater } from '../utils/schemaUpdateUtils.js'\nimport { createModificationType, ModificationHandler } from '../ModificationHandler.js'\nimport { applyPatch, Operation } from 'rfc6902'\nimport deepCopy from '../../utils/deepCopy.js'\n\nexport class PatchValidationSchemaModificationHandler implements ModificationHandler<PatchValidationSchemaModificationData> {\n\tconstructor(private readonly data: PatchValidationSchemaModificationData) {}\n\n\tpublic createSql(): void {}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn ({ schema }) => {\n\t\t\tconst validation = deepCopy(schema.validation)\n\t\t\tconst result = applyPatch(validation, this.data.patch).filter(it => it !== null)\n\t\t\tif (result.length > 0) {\n\t\t\t\tthrow result[0]\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...schema,\n\t\t\t\tvalidation,\n\t\t\t}\n\t\t}\n\t}\n\n\tdescribe() {\n\t\treturn { message: 'Update validation schema' }\n\t}\n}\n\nexport interface PatchValidationSchemaModificationData {\n\tpatch: Operation[]\n}\n\nexport const patchValidationSchemaModification = createModificationType({\n\tid: 'patchValidationSchema',\n\thandler: PatchValidationSchemaModificationHandler,\n})\n"],"names":["applyPatch","createModificationType"],"mappings":";;;;;AAKO,MAAM,yCAA+G;AAAA,EAC3H,YAA6B,MAA6C;AAA7C,SAAA,OAAA;AAAA,EAA8C;AAAA,EAEpE,YAAkB;AAAA,EAAC;AAAA,EAEnB,mBAAkC;AACxC,WAAO,CAAC,EAAE,aAAa;AACtB,YAAM,aAAa,SAAS,OAAO,UAAU;AAC7C,YAAM,SAASA,QAAAA,WAAW,YAAY,KAAK,KAAK,KAAK,EAAE,OAAO,CAAA,OAAM,OAAO,IAAI;AAC/E,UAAI,OAAO,SAAS,GAAG;AACtB,cAAM,OAAO,CAAC;AAAA,MACf;AAEA,aAAO;AAAA,QACN,GAAG;AAAA,QACH;AAAA,MAAA;AAAA,IAEF;AAAA,EACD;AAAA,EAEA,WAAW;AACV,WAAO,EAAE,SAAS,2BAAA;AAAA,EACnB;AACD;AAMO,MAAM,oCAAoCC,oBAAAA,uBAAuB;AAAA,EACvE,IAAI;AAAA,EACJ,SAAS;AACV,CAAC;;;"}
|
package/dist/development/src/modifications/validation/PatchValidationSchemaModification.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PatchValidationSchemaModification.js","sources":["../../../../../../packages/schema-migrations/src/modifications/validation/PatchValidationSchemaModification.ts"],"sourcesContent":["import { SchemaUpdater } from '../utils/schemaUpdateUtils'\nimport { createModificationType, ModificationHandler } from '../ModificationHandler'\nimport { applyPatch, Operation } from 'rfc6902'\nimport deepCopy from '../../utils/deepCopy'\n\nexport class PatchValidationSchemaModificationHandler implements ModificationHandler<PatchValidationSchemaModificationData> {\n\tconstructor(private readonly data: PatchValidationSchemaModificationData) {}\n\n\tpublic createSql(): void {}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn ({ schema }) => {\n\t\t\tconst validation = deepCopy(schema.validation)\n\t\t\tconst result = applyPatch(validation, this.data.patch).filter(it => it !== null)\n\t\t\tif (result.length > 0) {\n\t\t\t\tthrow result[0]\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...schema,\n\t\t\t\tvalidation,\n\t\t\t}\n\t\t}\n\t}\n\n\tdescribe() {\n\t\treturn { message: 'Update validation schema' }\n\t}\n}\n\nexport interface PatchValidationSchemaModificationData {\n\tpatch: Operation[]\n}\n\nexport const patchValidationSchemaModification = createModificationType({\n\tid: 'patchValidationSchema',\n\thandler: PatchValidationSchemaModificationHandler,\n})\n"],"names":[],"mappings":";;;AAKO,MAAM,yCAA+G;AAAA,EAC3H,YAA6B,MAA6C;AAA7C,SAAA,OAAA;AAAA,EAA8C;AAAA,EAEpE,YAAkB;AAAA,EAAC;AAAA,EAEnB,mBAAkC;AACxC,WAAO,CAAC,EAAE,aAAa;AACtB,YAAM,aAAa,SAAS,OAAO,UAAU;AAC7C,YAAM,SAAS,WAAW,YAAY,KAAK,KAAK,KAAK,EAAE,OAAO,CAAA,OAAM,OAAO,IAAI;AAC/E,UAAI,OAAO,SAAS,GAAG;AACtB,cAAM,OAAO,CAAC;AAAA,MACf;AAEA,aAAO;AAAA,QACN,GAAG;AAAA,QACH;AAAA,MAAA;AAAA,IAEF;AAAA,EACD;AAAA,EAEA,WAAW;AACV,WAAO,EAAE,SAAS,2BAAA;AAAA,EACnB;AACD;AAMO,MAAM,oCAAoC,uBAAuB;AAAA,EACvE,IAAI;AAAA,EACJ,SAAS;AACV,CAAC;"}
|
|
1
|
+
{"version":3,"file":"PatchValidationSchemaModification.js","sources":["../../../../../../packages/schema-migrations/src/modifications/validation/PatchValidationSchemaModification.ts"],"sourcesContent":["import { SchemaUpdater } from '../utils/schemaUpdateUtils.js'\nimport { createModificationType, ModificationHandler } from '../ModificationHandler.js'\nimport { applyPatch, Operation } from 'rfc6902'\nimport deepCopy from '../../utils/deepCopy.js'\n\nexport class PatchValidationSchemaModificationHandler implements ModificationHandler<PatchValidationSchemaModificationData> {\n\tconstructor(private readonly data: PatchValidationSchemaModificationData) {}\n\n\tpublic createSql(): void {}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn ({ schema }) => {\n\t\t\tconst validation = deepCopy(schema.validation)\n\t\t\tconst result = applyPatch(validation, this.data.patch).filter(it => it !== null)\n\t\t\tif (result.length > 0) {\n\t\t\t\tthrow result[0]\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...schema,\n\t\t\t\tvalidation,\n\t\t\t}\n\t\t}\n\t}\n\n\tdescribe() {\n\t\treturn { message: 'Update validation schema' }\n\t}\n}\n\nexport interface PatchValidationSchemaModificationData {\n\tpatch: Operation[]\n}\n\nexport const patchValidationSchemaModification = createModificationType({\n\tid: 'patchValidationSchema',\n\thandler: PatchValidationSchemaModificationHandler,\n})\n"],"names":[],"mappings":";;;AAKO,MAAM,yCAA+G;AAAA,EAC3H,YAA6B,MAA6C;AAA7C,SAAA,OAAA;AAAA,EAA8C;AAAA,EAEpE,YAAkB;AAAA,EAAC;AAAA,EAEnB,mBAAkC;AACxC,WAAO,CAAC,EAAE,aAAa;AACtB,YAAM,aAAa,SAAS,OAAO,UAAU;AAC7C,YAAM,SAAS,WAAW,YAAY,KAAK,KAAK,KAAK,EAAE,OAAO,CAAA,OAAM,OAAO,IAAI;AAC/E,UAAI,OAAO,SAAS,GAAG;AACtB,cAAM,OAAO,CAAC;AAAA,MACf;AAEA,aAAO;AAAA,QACN,GAAG;AAAA,QACH;AAAA,MAAA;AAAA,IAEF;AAAA,EACD;AAAA,EAEA,WAAW;AACV,WAAO,EAAE,SAAS,2BAAA;AAAA,EACnB;AACD;AAMO,MAAM,oCAAoC,uBAAuB;AAAA,EACvE,IAAI;AAAA,EACJ,SAAS;AACV,CAAC;"}
|
package/dist/development/src/modifications/validation/UpdateValidationSchemaModification.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateValidationSchemaModification.cjs","sources":["../../../../../../packages/schema-migrations/src/modifications/validation/UpdateValidationSchemaModification.ts"],"sourcesContent":["import { Schema, Validation } from '@contember/schema'\nimport { SchemaUpdater } from '../utils/schemaUpdateUtils'\nimport { createModificationType, Differ, ModificationHandler } from '../ModificationHandler'\nimport deepEqual from 'fast-deep-equal'\nimport { createPatch } from 'rfc6902'\nimport { patchValidationSchemaModification } from './PatchValidationSchemaModification'\n\nexport class UpdateValidationSchemaModificationHandler implements ModificationHandler<UpdateValidationSchemaModificationData> {\n\tconstructor(private readonly data: UpdateValidationSchemaModificationData) {}\n\n\tpublic createSql(): void {}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn ({ schema }) => ({\n\t\t\t...schema,\n\t\t\tvalidation: this.data.schema,\n\t\t})\n\t}\n\n\tdescribe() {\n\t\treturn { message: 'Update validation schema' }\n\t}\n}\n\nexport interface UpdateValidationSchemaModificationData {\n\tschema: Validation.Schema\n}\n\nexport const updateValidationSchemaModification = createModificationType({\n\tid: 'updateValidationSchema',\n\thandler: UpdateValidationSchemaModificationHandler,\n})\n\nexport class UpdateValidationSchemaDiffer implements Differ {\n\tconstructor(\n\t\tprivate readonly options?: {\n\t\t\tmaxPatchSize?: number\n\t\t},\n\t) {\n\t}\n\n\tcreateDiff(originalSchema: Schema, updatedSchema: Schema) {\n\t\tif (deepEqual(originalSchema.validation, updatedSchema.validation)) {\n\t\t\treturn []\n\t\t}\n\t\tconst patch = createPatch(originalSchema.validation, updatedSchema.validation)\n\t\tif (patch.length <= (this.options?.maxPatchSize ?? 100)) {\n\t\t\treturn [patchValidationSchemaModification.createModification({ patch })]\n\t\t}\n\t\treturn [updateValidationSchemaModification.createModification({ schema: updatedSchema.validation })]\n\t}\n}\n"],"names":["createModificationType","createPatch","patchValidationSchemaModification"],"mappings":";;;;;;AAOO,MAAM,0CAAiH;AAAA,EAC7H,YAA6B,MAA8C;AAA9C,SAAA,OAAA;AAAA,EAA+C;AAAA,EAErE,YAAkB;AAAA,EAAC;AAAA,EAEnB,mBAAkC;AACxC,WAAO,CAAC,EAAE,cAAc;AAAA,MACvB,GAAG;AAAA,MACH,YAAY,KAAK,KAAK;AAAA,IAAA;AAAA,EAExB;AAAA,EAEA,WAAW;AACV,WAAO,EAAE,SAAS,2BAAA;AAAA,EACnB;AACD;AAMO,MAAM,qCAAqCA,oBAAAA,uBAAuB;AAAA,EACxE,IAAI;AAAA,EACJ,SAAS;AACV,CAAC;AAEM,MAAM,6BAA+C;AAAA,EAC3D,YACkB,SAGhB;AAHgB,SAAA,UAAA;AAAA,EAIlB;AAAA,EAEA,WAAW,gBAAwB,eAAuB;AACzD,QAAI,UAAU,eAAe,YAAY,cAAc,UAAU,GAAG;AACnE,aAAO,CAAA;AAAA,IACR;AACA,UAAM,QAAQC,QAAAA,YAAY,eAAe,YAAY,cAAc,UAAU;AAC7E,QAAI,MAAM,WAAW,KAAK,SAAS,gBAAgB,MAAM;AACxD,aAAO,CAACC,kCAAAA,kCAAkC,mBAAmB,EAAE,MAAA,CAAO,CAAC;AAAA,IACxE;AACA,WAAO,CAAC,mCAAmC,mBAAmB,EAAE,QAAQ,cAAc,WAAA,CAAY,CAAC;AAAA,EACpG;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"UpdateValidationSchemaModification.cjs","sources":["../../../../../../packages/schema-migrations/src/modifications/validation/UpdateValidationSchemaModification.ts"],"sourcesContent":["import { Schema, Validation } from '@contember/schema'\nimport { SchemaUpdater } from '../utils/schemaUpdateUtils.js'\nimport { createModificationType, Differ, ModificationHandler } from '../ModificationHandler.js'\nimport deepEqual from 'fast-deep-equal'\nimport { createPatch } from 'rfc6902'\nimport { patchValidationSchemaModification } from './PatchValidationSchemaModification.js'\n\nexport class UpdateValidationSchemaModificationHandler implements ModificationHandler<UpdateValidationSchemaModificationData> {\n\tconstructor(private readonly data: UpdateValidationSchemaModificationData) {}\n\n\tpublic createSql(): void {}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn ({ schema }) => ({\n\t\t\t...schema,\n\t\t\tvalidation: this.data.schema,\n\t\t})\n\t}\n\n\tdescribe() {\n\t\treturn { message: 'Update validation schema' }\n\t}\n}\n\nexport interface UpdateValidationSchemaModificationData {\n\tschema: Validation.Schema\n}\n\nexport const updateValidationSchemaModification = createModificationType({\n\tid: 'updateValidationSchema',\n\thandler: UpdateValidationSchemaModificationHandler,\n})\n\nexport class UpdateValidationSchemaDiffer implements Differ {\n\tconstructor(\n\t\tprivate readonly options?: {\n\t\t\tmaxPatchSize?: number\n\t\t},\n\t) {\n\t}\n\n\tcreateDiff(originalSchema: Schema, updatedSchema: Schema) {\n\t\tif (deepEqual(originalSchema.validation, updatedSchema.validation)) {\n\t\t\treturn []\n\t\t}\n\t\tconst patch = createPatch(originalSchema.validation, updatedSchema.validation)\n\t\tif (patch.length <= (this.options?.maxPatchSize ?? 100)) {\n\t\t\treturn [patchValidationSchemaModification.createModification({ patch })]\n\t\t}\n\t\treturn [updateValidationSchemaModification.createModification({ schema: updatedSchema.validation })]\n\t}\n}\n"],"names":["createModificationType","createPatch","patchValidationSchemaModification"],"mappings":";;;;;;AAOO,MAAM,0CAAiH;AAAA,EAC7H,YAA6B,MAA8C;AAA9C,SAAA,OAAA;AAAA,EAA+C;AAAA,EAErE,YAAkB;AAAA,EAAC;AAAA,EAEnB,mBAAkC;AACxC,WAAO,CAAC,EAAE,cAAc;AAAA,MACvB,GAAG;AAAA,MACH,YAAY,KAAK,KAAK;AAAA,IAAA;AAAA,EAExB;AAAA,EAEA,WAAW;AACV,WAAO,EAAE,SAAS,2BAAA;AAAA,EACnB;AACD;AAMO,MAAM,qCAAqCA,oBAAAA,uBAAuB;AAAA,EACxE,IAAI;AAAA,EACJ,SAAS;AACV,CAAC;AAEM,MAAM,6BAA+C;AAAA,EAC3D,YACkB,SAGhB;AAHgB,SAAA,UAAA;AAAA,EAIlB;AAAA,EAEA,WAAW,gBAAwB,eAAuB;AACzD,QAAI,UAAU,eAAe,YAAY,cAAc,UAAU,GAAG;AACnE,aAAO,CAAA;AAAA,IACR;AACA,UAAM,QAAQC,QAAAA,YAAY,eAAe,YAAY,cAAc,UAAU;AAC7E,QAAI,MAAM,WAAW,KAAK,SAAS,gBAAgB,MAAM;AACxD,aAAO,CAACC,kCAAAA,kCAAkC,mBAAmB,EAAE,MAAA,CAAO,CAAC;AAAA,IACxE;AACA,WAAO,CAAC,mCAAmC,mBAAmB,EAAE,QAAQ,cAAc,WAAA,CAAY,CAAC;AAAA,EACpG;AACD;;;;"}
|
package/dist/development/src/modifications/validation/UpdateValidationSchemaModification.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateValidationSchemaModification.js","sources":["../../../../../../packages/schema-migrations/src/modifications/validation/UpdateValidationSchemaModification.ts"],"sourcesContent":["import { Schema, Validation } from '@contember/schema'\nimport { SchemaUpdater } from '../utils/schemaUpdateUtils'\nimport { createModificationType, Differ, ModificationHandler } from '../ModificationHandler'\nimport deepEqual from 'fast-deep-equal'\nimport { createPatch } from 'rfc6902'\nimport { patchValidationSchemaModification } from './PatchValidationSchemaModification'\n\nexport class UpdateValidationSchemaModificationHandler implements ModificationHandler<UpdateValidationSchemaModificationData> {\n\tconstructor(private readonly data: UpdateValidationSchemaModificationData) {}\n\n\tpublic createSql(): void {}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn ({ schema }) => ({\n\t\t\t...schema,\n\t\t\tvalidation: this.data.schema,\n\t\t})\n\t}\n\n\tdescribe() {\n\t\treturn { message: 'Update validation schema' }\n\t}\n}\n\nexport interface UpdateValidationSchemaModificationData {\n\tschema: Validation.Schema\n}\n\nexport const updateValidationSchemaModification = createModificationType({\n\tid: 'updateValidationSchema',\n\thandler: UpdateValidationSchemaModificationHandler,\n})\n\nexport class UpdateValidationSchemaDiffer implements Differ {\n\tconstructor(\n\t\tprivate readonly options?: {\n\t\t\tmaxPatchSize?: number\n\t\t},\n\t) {\n\t}\n\n\tcreateDiff(originalSchema: Schema, updatedSchema: Schema) {\n\t\tif (deepEqual(originalSchema.validation, updatedSchema.validation)) {\n\t\t\treturn []\n\t\t}\n\t\tconst patch = createPatch(originalSchema.validation, updatedSchema.validation)\n\t\tif (patch.length <= (this.options?.maxPatchSize ?? 100)) {\n\t\t\treturn [patchValidationSchemaModification.createModification({ patch })]\n\t\t}\n\t\treturn [updateValidationSchemaModification.createModification({ schema: updatedSchema.validation })]\n\t}\n}\n"],"names":[],"mappings":";;;;AAOO,MAAM,0CAAiH;AAAA,EAC7H,YAA6B,MAA8C;AAA9C,SAAA,OAAA;AAAA,EAA+C;AAAA,EAErE,YAAkB;AAAA,EAAC;AAAA,EAEnB,mBAAkC;AACxC,WAAO,CAAC,EAAE,cAAc;AAAA,MACvB,GAAG;AAAA,MACH,YAAY,KAAK,KAAK;AAAA,IAAA;AAAA,EAExB;AAAA,EAEA,WAAW;AACV,WAAO,EAAE,SAAS,2BAAA;AAAA,EACnB;AACD;AAMO,MAAM,qCAAqC,uBAAuB;AAAA,EACxE,IAAI;AAAA,EACJ,SAAS;AACV,CAAC;AAEM,MAAM,6BAA+C;AAAA,EAC3D,YACkB,SAGhB;AAHgB,SAAA,UAAA;AAAA,EAIlB;AAAA,EAEA,WAAW,gBAAwB,eAAuB;AACzD,QAAI,UAAU,eAAe,YAAY,cAAc,UAAU,GAAG;AACnE,aAAO,CAAA;AAAA,IACR;AACA,UAAM,QAAQ,YAAY,eAAe,YAAY,cAAc,UAAU;AAC7E,QAAI,MAAM,WAAW,KAAK,SAAS,gBAAgB,MAAM;AACxD,aAAO,CAAC,kCAAkC,mBAAmB,EAAE,MAAA,CAAO,CAAC;AAAA,IACxE;AACA,WAAO,CAAC,mCAAmC,mBAAmB,EAAE,QAAQ,cAAc,WAAA,CAAY,CAAC;AAAA,EACpG;AACD;"}
|
|
1
|
+
{"version":3,"file":"UpdateValidationSchemaModification.js","sources":["../../../../../../packages/schema-migrations/src/modifications/validation/UpdateValidationSchemaModification.ts"],"sourcesContent":["import { Schema, Validation } from '@contember/schema'\nimport { SchemaUpdater } from '../utils/schemaUpdateUtils.js'\nimport { createModificationType, Differ, ModificationHandler } from '../ModificationHandler.js'\nimport deepEqual from 'fast-deep-equal'\nimport { createPatch } from 'rfc6902'\nimport { patchValidationSchemaModification } from './PatchValidationSchemaModification.js'\n\nexport class UpdateValidationSchemaModificationHandler implements ModificationHandler<UpdateValidationSchemaModificationData> {\n\tconstructor(private readonly data: UpdateValidationSchemaModificationData) {}\n\n\tpublic createSql(): void {}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn ({ schema }) => ({\n\t\t\t...schema,\n\t\t\tvalidation: this.data.schema,\n\t\t})\n\t}\n\n\tdescribe() {\n\t\treturn { message: 'Update validation schema' }\n\t}\n}\n\nexport interface UpdateValidationSchemaModificationData {\n\tschema: Validation.Schema\n}\n\nexport const updateValidationSchemaModification = createModificationType({\n\tid: 'updateValidationSchema',\n\thandler: UpdateValidationSchemaModificationHandler,\n})\n\nexport class UpdateValidationSchemaDiffer implements Differ {\n\tconstructor(\n\t\tprivate readonly options?: {\n\t\t\tmaxPatchSize?: number\n\t\t},\n\t) {\n\t}\n\n\tcreateDiff(originalSchema: Schema, updatedSchema: Schema) {\n\t\tif (deepEqual(originalSchema.validation, updatedSchema.validation)) {\n\t\t\treturn []\n\t\t}\n\t\tconst patch = createPatch(originalSchema.validation, updatedSchema.validation)\n\t\tif (patch.length <= (this.options?.maxPatchSize ?? 100)) {\n\t\t\treturn [patchValidationSchemaModification.createModification({ patch })]\n\t\t}\n\t\treturn [updateValidationSchemaModification.createModification({ schema: updatedSchema.validation })]\n\t}\n}\n"],"names":[],"mappings":";;;;AAOO,MAAM,0CAAiH;AAAA,EAC7H,YAA6B,MAA8C;AAA9C,SAAA,OAAA;AAAA,EAA+C;AAAA,EAErE,YAAkB;AAAA,EAAC;AAAA,EAEnB,mBAAkC;AACxC,WAAO,CAAC,EAAE,cAAc;AAAA,MACvB,GAAG;AAAA,MACH,YAAY,KAAK,KAAK;AAAA,IAAA;AAAA,EAExB;AAAA,EAEA,WAAW;AACV,WAAO,EAAE,SAAS,2BAAA;AAAA,EACnB;AACD;AAMO,MAAM,qCAAqC,uBAAuB;AAAA,EACxE,IAAI;AAAA,EACJ,SAAS;AACV,CAAC;AAEM,MAAM,6BAA+C;AAAA,EAC3D,YACkB,SAGhB;AAHgB,SAAA,UAAA;AAAA,EAIlB;AAAA,EAEA,WAAW,gBAAwB,eAAuB;AACzD,QAAI,UAAU,eAAe,YAAY,cAAc,UAAU,GAAG;AACnE,aAAO,CAAA;AAAA,IACR;AACA,UAAM,QAAQ,YAAY,eAAe,YAAY,cAAc,UAAU;AAC7E,QAAI,MAAM,WAAW,KAAK,SAAS,gBAAgB,MAAM;AACxD,aAAO,CAAC,kCAAkC,mBAAmB,EAAE,MAAA,CAAO,CAAC;AAAA,IACxE;AACA,WAAO,CAAC,mCAAmC,mBAAmB,EAAE,QAAQ,cAAc,WAAA,CAAY,CAAC;AAAA,EACpG;AACD;"}
|
|
@@ -24,6 +24,7 @@ const RemoveEnumModification = require("./src/modifications/enums/RemoveEnumModi
|
|
|
24
24
|
const UpdateEnumModification = require("./src/modifications/enums/UpdateEnumModification.cjs");
|
|
25
25
|
const RemoveFieldModification = require("./src/modifications/fields/RemoveFieldModification.cjs");
|
|
26
26
|
const UpdateFieldNameModification = require("./src/modifications/fields/UpdateFieldNameModification.cjs");
|
|
27
|
+
const ConvertManyHasManyToJoiningEntityModification = require("./src/modifications/relations/ConvertManyHasManyToJoiningEntityModification.cjs");
|
|
27
28
|
const ConvertOneHasManyToManyHasManyRelationModification = require("./src/modifications/relations/ConvertOneHasManyToManyHasManyRelationModification.cjs");
|
|
28
29
|
const ConvertOneToManyRelationModification = require("./src/modifications/relations/ConvertOneToManyRelationModification.cjs");
|
|
29
30
|
const CreateRelationInverseSideModification = require("./src/modifications/relations/CreateRelationInverseSideModification.cjs");
|
|
@@ -103,6 +104,8 @@ exports.RemoveFieldModificationHandler = RemoveFieldModification.RemoveFieldModi
|
|
|
103
104
|
exports.removeFieldModification = RemoveFieldModification.removeFieldModification;
|
|
104
105
|
exports.UpdateFieldNameModificationHandler = UpdateFieldNameModification.UpdateFieldNameModificationHandler;
|
|
105
106
|
exports.updateFieldNameModification = UpdateFieldNameModification.updateFieldNameModification;
|
|
107
|
+
exports.ConvertManyHasManyToJoiningEntityModificationHandler = ConvertManyHasManyToJoiningEntityModification.ConvertManyHasManyToJoiningEntityModificationHandler;
|
|
108
|
+
exports.convertManyHasManyToJoiningEntityModification = ConvertManyHasManyToJoiningEntityModification.convertManyHasManyToJoiningEntityModification;
|
|
106
109
|
exports.ConvertOneHasManyToManyHasManyRelationDiffer = ConvertOneHasManyToManyHasManyRelationModification.ConvertOneHasManyToManyHasManyRelationDiffer;
|
|
107
110
|
exports.ConvertOneHasManyToManyHasManyRelationModificationHandler = ConvertOneHasManyToManyHasManyRelationModification.ConvertOneHasManyToManyHasManyRelationModificationHandler;
|
|
108
111
|
exports.convertOneHasManyToManyHasManyRelationModification = ConvertOneHasManyToManyHasManyRelationModification.convertOneHasManyToManyHasManyRelationModification;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/production/index.js
CHANGED
|
@@ -22,6 +22,7 @@ import { RemoveEnumDiffer, RemoveEnumModificationHandler, removeEnumModification
|
|
|
22
22
|
import { UpdateEnumDiffer, UpdateEnumModificationHandler, updateEnumModification } from "./src/modifications/enums/UpdateEnumModification.js";
|
|
23
23
|
import { RemoveFieldDiffer, RemoveFieldModificationHandler, removeFieldModification } from "./src/modifications/fields/RemoveFieldModification.js";
|
|
24
24
|
import { UpdateFieldNameModificationHandler, updateFieldNameModification } from "./src/modifications/fields/UpdateFieldNameModification.js";
|
|
25
|
+
import { ConvertManyHasManyToJoiningEntityModificationHandler, convertManyHasManyToJoiningEntityModification } from "./src/modifications/relations/ConvertManyHasManyToJoiningEntityModification.js";
|
|
25
26
|
import { ConvertOneHasManyToManyHasManyRelationDiffer, ConvertOneHasManyToManyHasManyRelationModificationHandler, convertOneHasManyToManyHasManyRelationModification } from "./src/modifications/relations/ConvertOneHasManyToManyHasManyRelationModification.js";
|
|
26
27
|
import { ConvertOneToManyRelationDiffer, ConvertOneToManyRelationModificationHandler, convertOneToManyRelationModification } from "./src/modifications/relations/ConvertOneToManyRelationModification.js";
|
|
27
28
|
import { CreateRelationInverseSideDiffer, CreateRelationInverseSideModificationHandler, createRelationInverseSideModification } from "./src/modifications/relations/CreateRelationInverseSideModification.js";
|
|
@@ -42,6 +43,7 @@ import { SchemaUpdateError } from "./src/modifications/exceptions.js";
|
|
|
42
43
|
import { createEventTrigger, createEventTrxTrigger, dropEventTrigger, dropEventTrxTrigger } from "./src/modifications/utils/sqlUpdateUtils.js";
|
|
43
44
|
import { MigrationVersionHelper } from "@contember/engine-common";
|
|
44
45
|
export {
|
|
46
|
+
ConvertManyHasManyToJoiningEntityModificationHandler,
|
|
45
47
|
ConvertOneHasManyToManyHasManyRelationDiffer,
|
|
46
48
|
ConvertOneHasManyToManyHasManyRelationModificationHandler,
|
|
47
49
|
ConvertOneToManyRelationDiffer,
|
|
@@ -119,6 +121,7 @@ export {
|
|
|
119
121
|
VERSION_UPDATE_INDEX_FIELDS,
|
|
120
122
|
_REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE,
|
|
121
123
|
calculateMigrationChecksum,
|
|
124
|
+
convertManyHasManyToJoiningEntityModification,
|
|
122
125
|
convertOneHasManyToManyHasManyRelationModification,
|
|
123
126
|
convertOneToManyRelationModification,
|
|
124
127
|
createColumnModification,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationDescriber.cjs","sources":["../../../../packages/schema-migrations/src/MigrationDescriber.ts"],"sourcesContent":["import {\n\tcreateEntityModification,\n\tcreateViewModification,\n\temptyModificationDescriptionContext,\n\tModificationDescription,\n\tModificationDescriptionContext,\n\tModificationHandler,\n\tModificationHandlerCreateSqlOptions,\n\tModificationHandlerFactory,\n\tModificationHandlerOptions,\n\tSchemaUpdateError,\n} from './modifications'\nimport { createMigrationBuilder } from '@contember/database-migrations'\nimport { Migration } from './Migration'\nimport { Schema } from '@contember/schema'\n\nexport interface ModificationDescriptionResult {\n\tmodification: Migration.Modification\n\tschema: Schema\n\tdescription: ModificationDescription\n\thandler: ModificationHandler<any>\n\tgetSql: (options: ModificationHandlerCreateSqlOptions) => string\n}\n\nexport class MigrationDescriber {\n\tconstructor(private readonly modificationHandlerFactory: ModificationHandlerFactory) {\n\t}\n\n\tpublic describeModification(\n\t\tschema: Schema,\n\t\tmodification: Migration.Modification,\n\t\toptions: ModificationHandlerOptions,\n\t\tmodificationDescriptionContext: ModificationDescriptionContext = emptyModificationDescriptionContext,\n\t): ModificationDescriptionResult {\n\t\tconst modificationHandler = this.modificationHandlerFactory.create(\n\t\t\tmodification.modification,\n\t\t\tmodification,\n\t\t\tschema,\n\t\t\toptions,\n\t\t)\n\t\ttry {\n\t\t\tschema = modificationHandler.getSchemaUpdater()({ schema })\n\t\t} catch (e) {\n\t\t\tif (!(e instanceof SchemaUpdateError)) {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t\tthrow new SchemaUpdateError(e.message + '\\n for modification: \\n' + JSON.stringify(modification))\n\t\t}\n\t\treturn {\n\t\t\tmodification,\n\t\t\tschema,\n\t\t\tgetSql: options => {\n\t\t\t\tconst builder = createMigrationBuilder()\n\t\t\t\tmodificationHandler.createSql(builder, options)\n\t\t\t\treturn builder.getSql()\n\t\t\t},\n\t\t\tdescription: modificationHandler.describe(modificationDescriptionContext),\n\t\t\thandler: modificationHandler,\n\t\t}\n\t}\n\n\tpublic describeModifications(schema: Schema, migration: Migration): ModificationDescriptionResult[] {\n\t\tconst result = []\n\t\tconst createdEntities = []\n\t\tfor (const modification of migration.modifications) {\n\t\t\tif (modification.modification === createEntityModification.id || modification.modification === createViewModification.id) {\n\t\t\t\tcreatedEntities.push(modification.entity.name)\n\t\t\t}\n\t\t\tconst description = this.describeModification(\n\t\t\t\tschema,\n\t\t\t\tmodification,\n\t\t\t\t{\n\t\t\t\t\tformatVersion: migration.formatVersion,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcreatedEntities,\n\t\t\t\t},\n\t\t\t)\n\t\t\tschema = description.schema\n\t\t\tresult.push(description)\n\t\t}\n\t\treturn result\n\t}\n}\n"],"names":["emptyModificationDescriptionContext","SchemaUpdateError","options","createMigrationBuilder","createEntityModification","createViewModification"],"mappings":";;;;;;;;;;;;AAwBO,MAAM,mBAAmB;AAAA,EAC/B,YAA6B,4BAAwD;AAAxD,SAAA,6BAAA;AAAA,EAC7B;AAAA,EAEO,qBACN,QACA,cACA,SACA,iCAAiEA,oBAAAA,qCACjC;AAChC,UAAM,sBAAsB,KAAK,2BAA2B;AAAA,MAC3D,aAAa;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAED,QAAI;AACH,eAAS,oBAAoB,mBAAmB,EAAE,QAAQ;AAAA,IAC3D,SAAS,GAAG;AACX,UAAI,EAAE,aAAaC,WAAAA,oBAAoB;AACtC,cAAM;AAAA,MACP;AACA,YAAM,IAAIA,WAAAA,kBAAkB,EAAE,UAAU,4BAA4B,KAAK,UAAU,YAAY,CAAC;AAAA,IACjG;AACA,WAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA,QAAQ,CAAAC,aAAW;AAClB,cAAM,UAAUC,mBAAAA,uBAAA;AAChB,4BAAoB,UAAU,SAASD,QAAO;AAC9C,eAAO,QAAQ,OAAA;AAAA,MAChB;AAAA,MACA,aAAa,oBAAoB,SAAS,8BAA8B;AAAA,MACxE,SAAS;AAAA,IAAA;AAAA,EAEX;AAAA,EAEO,sBAAsB,QAAgB,WAAuD;AACnG,UAAM,SAAS,CAAA;AACf,UAAM,kBAAkB,CAAA;AACxB,eAAW,gBAAgB,UAAU,eAAe;AACnD,UAAI,aAAa,iBAAiBE,kDAAyB,MAAM,aAAa,iBAAiBC,uBAAAA,uBAAuB,IAAI;AACzH,wBAAgB,KAAK,aAAa,OAAO,IAAI;AAAA,MAC9C;AACA,YAAM,cAAc,KAAK;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,UACC,eAAe,UAAU;AAAA,QAAA;AAAA,QAE1B;AAAA,UACC;AAAA,QAAA;AAAA,MACD;AAED,eAAS,YAAY;AACrB,aAAO,KAAK,WAAW;AAAA,IACxB;AACA,WAAO;AAAA,EACR;AACD;;"}
|
|
1
|
+
{"version":3,"file":"MigrationDescriber.cjs","sources":["../../../../packages/schema-migrations/src/MigrationDescriber.ts"],"sourcesContent":["import {\n\tcreateEntityModification,\n\tcreateViewModification,\n\temptyModificationDescriptionContext,\n\tModificationDescription,\n\tModificationDescriptionContext,\n\tModificationHandler,\n\tModificationHandlerCreateSqlOptions,\n\tModificationHandlerFactory,\n\tModificationHandlerOptions,\n\tSchemaUpdateError,\n} from './modifications/index.js'\nimport { createMigrationBuilder } from '@contember/database-migrations'\nimport { Migration } from './Migration.js'\nimport { Schema } from '@contember/schema'\n\nexport interface ModificationDescriptionResult {\n\tmodification: Migration.Modification\n\tschema: Schema\n\tdescription: ModificationDescription\n\thandler: ModificationHandler<any>\n\tgetSql: (options: ModificationHandlerCreateSqlOptions) => string\n}\n\nexport class MigrationDescriber {\n\tconstructor(private readonly modificationHandlerFactory: ModificationHandlerFactory) {\n\t}\n\n\tpublic describeModification(\n\t\tschema: Schema,\n\t\tmodification: Migration.Modification,\n\t\toptions: ModificationHandlerOptions,\n\t\tmodificationDescriptionContext: ModificationDescriptionContext = emptyModificationDescriptionContext,\n\t): ModificationDescriptionResult {\n\t\tconst modificationHandler = this.modificationHandlerFactory.create(\n\t\t\tmodification.modification,\n\t\t\tmodification,\n\t\t\tschema,\n\t\t\toptions,\n\t\t)\n\t\ttry {\n\t\t\tschema = modificationHandler.getSchemaUpdater()({ schema })\n\t\t} catch (e) {\n\t\t\tif (!(e instanceof SchemaUpdateError)) {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t\tthrow new SchemaUpdateError(e.message + '\\n for modification: \\n' + JSON.stringify(modification))\n\t\t}\n\t\treturn {\n\t\t\tmodification,\n\t\t\tschema,\n\t\t\tgetSql: options => {\n\t\t\t\tconst builder = createMigrationBuilder()\n\t\t\t\tmodificationHandler.createSql(builder, options)\n\t\t\t\treturn builder.getSql()\n\t\t\t},\n\t\t\tdescription: modificationHandler.describe(modificationDescriptionContext),\n\t\t\thandler: modificationHandler,\n\t\t}\n\t}\n\n\tpublic describeModifications(schema: Schema, migration: Migration): ModificationDescriptionResult[] {\n\t\tconst result = []\n\t\tconst createdEntities = []\n\t\tfor (const modification of migration.modifications) {\n\t\t\tif (modification.modification === createEntityModification.id || modification.modification === createViewModification.id) {\n\t\t\t\tcreatedEntities.push(modification.entity.name)\n\t\t\t}\n\t\t\tconst description = this.describeModification(\n\t\t\t\tschema,\n\t\t\t\tmodification,\n\t\t\t\t{\n\t\t\t\t\tformatVersion: migration.formatVersion,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcreatedEntities,\n\t\t\t\t},\n\t\t\t)\n\t\t\tschema = description.schema\n\t\t\tresult.push(description)\n\t\t}\n\t\treturn result\n\t}\n}\n"],"names":["emptyModificationDescriptionContext","SchemaUpdateError","options","createMigrationBuilder","createEntityModification","createViewModification"],"mappings":";;;;;;;;;;;;AAwBO,MAAM,mBAAmB;AAAA,EAC/B,YAA6B,4BAAwD;AAAxD,SAAA,6BAAA;AAAA,EAC7B;AAAA,EAEO,qBACN,QACA,cACA,SACA,iCAAiEA,oBAAAA,qCACjC;AAChC,UAAM,sBAAsB,KAAK,2BAA2B;AAAA,MAC3D,aAAa;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAED,QAAI;AACH,eAAS,oBAAoB,mBAAmB,EAAE,QAAQ;AAAA,IAC3D,SAAS,GAAG;AACX,UAAI,EAAE,aAAaC,WAAAA,oBAAoB;AACtC,cAAM;AAAA,MACP;AACA,YAAM,IAAIA,WAAAA,kBAAkB,EAAE,UAAU,4BAA4B,KAAK,UAAU,YAAY,CAAC;AAAA,IACjG;AACA,WAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA,QAAQ,CAAAC,aAAW;AAClB,cAAM,UAAUC,mBAAAA,uBAAA;AAChB,4BAAoB,UAAU,SAASD,QAAO;AAC9C,eAAO,QAAQ,OAAA;AAAA,MAChB;AAAA,MACA,aAAa,oBAAoB,SAAS,8BAA8B;AAAA,MACxE,SAAS;AAAA,IAAA;AAAA,EAEX;AAAA,EAEO,sBAAsB,QAAgB,WAAuD;AACnG,UAAM,SAAS,CAAA;AACf,UAAM,kBAAkB,CAAA;AACxB,eAAW,gBAAgB,UAAU,eAAe;AACnD,UAAI,aAAa,iBAAiBE,kDAAyB,MAAM,aAAa,iBAAiBC,uBAAAA,uBAAuB,IAAI;AACzH,wBAAgB,KAAK,aAAa,OAAO,IAAI;AAAA,MAC9C;AACA,YAAM,cAAc,KAAK;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,UACC,eAAe,UAAU;AAAA,QAAA;AAAA,QAE1B;AAAA,UACC;AAAA,QAAA;AAAA,MACD;AAED,eAAS,YAAY;AACrB,aAAO,KAAK,WAAW;AAAA,IACxB;AACA,WAAO;AAAA,EACR;AACD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationDescriber.js","sources":["../../../../packages/schema-migrations/src/MigrationDescriber.ts"],"sourcesContent":["import {\n\tcreateEntityModification,\n\tcreateViewModification,\n\temptyModificationDescriptionContext,\n\tModificationDescription,\n\tModificationDescriptionContext,\n\tModificationHandler,\n\tModificationHandlerCreateSqlOptions,\n\tModificationHandlerFactory,\n\tModificationHandlerOptions,\n\tSchemaUpdateError,\n} from './modifications'\nimport { createMigrationBuilder } from '@contember/database-migrations'\nimport { Migration } from './Migration'\nimport { Schema } from '@contember/schema'\n\nexport interface ModificationDescriptionResult {\n\tmodification: Migration.Modification\n\tschema: Schema\n\tdescription: ModificationDescription\n\thandler: ModificationHandler<any>\n\tgetSql: (options: ModificationHandlerCreateSqlOptions) => string\n}\n\nexport class MigrationDescriber {\n\tconstructor(private readonly modificationHandlerFactory: ModificationHandlerFactory) {\n\t}\n\n\tpublic describeModification(\n\t\tschema: Schema,\n\t\tmodification: Migration.Modification,\n\t\toptions: ModificationHandlerOptions,\n\t\tmodificationDescriptionContext: ModificationDescriptionContext = emptyModificationDescriptionContext,\n\t): ModificationDescriptionResult {\n\t\tconst modificationHandler = this.modificationHandlerFactory.create(\n\t\t\tmodification.modification,\n\t\t\tmodification,\n\t\t\tschema,\n\t\t\toptions,\n\t\t)\n\t\ttry {\n\t\t\tschema = modificationHandler.getSchemaUpdater()({ schema })\n\t\t} catch (e) {\n\t\t\tif (!(e instanceof SchemaUpdateError)) {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t\tthrow new SchemaUpdateError(e.message + '\\n for modification: \\n' + JSON.stringify(modification))\n\t\t}\n\t\treturn {\n\t\t\tmodification,\n\t\t\tschema,\n\t\t\tgetSql: options => {\n\t\t\t\tconst builder = createMigrationBuilder()\n\t\t\t\tmodificationHandler.createSql(builder, options)\n\t\t\t\treturn builder.getSql()\n\t\t\t},\n\t\t\tdescription: modificationHandler.describe(modificationDescriptionContext),\n\t\t\thandler: modificationHandler,\n\t\t}\n\t}\n\n\tpublic describeModifications(schema: Schema, migration: Migration): ModificationDescriptionResult[] {\n\t\tconst result = []\n\t\tconst createdEntities = []\n\t\tfor (const modification of migration.modifications) {\n\t\t\tif (modification.modification === createEntityModification.id || modification.modification === createViewModification.id) {\n\t\t\t\tcreatedEntities.push(modification.entity.name)\n\t\t\t}\n\t\t\tconst description = this.describeModification(\n\t\t\t\tschema,\n\t\t\t\tmodification,\n\t\t\t\t{\n\t\t\t\t\tformatVersion: migration.formatVersion,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcreatedEntities,\n\t\t\t\t},\n\t\t\t)\n\t\t\tschema = description.schema\n\t\t\tresult.push(description)\n\t\t}\n\t\treturn result\n\t}\n}\n"],"names":["options"],"mappings":";;;;;;;;;;AAwBO,MAAM,mBAAmB;AAAA,EAC/B,YAA6B,4BAAwD;AAAxD,SAAA,6BAAA;AAAA,EAC7B;AAAA,EAEO,qBACN,QACA,cACA,SACA,iCAAiE,qCACjC;AAChC,UAAM,sBAAsB,KAAK,2BAA2B;AAAA,MAC3D,aAAa;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAED,QAAI;AACH,eAAS,oBAAoB,mBAAmB,EAAE,QAAQ;AAAA,IAC3D,SAAS,GAAG;AACX,UAAI,EAAE,aAAa,oBAAoB;AACtC,cAAM;AAAA,MACP;AACA,YAAM,IAAI,kBAAkB,EAAE,UAAU,4BAA4B,KAAK,UAAU,YAAY,CAAC;AAAA,IACjG;AACA,WAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA,QAAQ,CAAAA,aAAW;AAClB,cAAM,UAAU,uBAAA;AAChB,4BAAoB,UAAU,SAASA,QAAO;AAC9C,eAAO,QAAQ,OAAA;AAAA,MAChB;AAAA,MACA,aAAa,oBAAoB,SAAS,8BAA8B;AAAA,MACxE,SAAS;AAAA,IAAA;AAAA,EAEX;AAAA,EAEO,sBAAsB,QAAgB,WAAuD;AACnG,UAAM,SAAS,CAAA;AACf,UAAM,kBAAkB,CAAA;AACxB,eAAW,gBAAgB,UAAU,eAAe;AACnD,UAAI,aAAa,iBAAiB,yBAAyB,MAAM,aAAa,iBAAiB,uBAAuB,IAAI;AACzH,wBAAgB,KAAK,aAAa,OAAO,IAAI;AAAA,MAC9C;AACA,YAAM,cAAc,KAAK;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,UACC,eAAe,UAAU;AAAA,QAAA;AAAA,QAE1B;AAAA,UACC;AAAA,QAAA;AAAA,MACD;AAED,eAAS,YAAY;AACrB,aAAO,KAAK,WAAW;AAAA,IACxB;AACA,WAAO;AAAA,EACR;AACD;"}
|
|
1
|
+
{"version":3,"file":"MigrationDescriber.js","sources":["../../../../packages/schema-migrations/src/MigrationDescriber.ts"],"sourcesContent":["import {\n\tcreateEntityModification,\n\tcreateViewModification,\n\temptyModificationDescriptionContext,\n\tModificationDescription,\n\tModificationDescriptionContext,\n\tModificationHandler,\n\tModificationHandlerCreateSqlOptions,\n\tModificationHandlerFactory,\n\tModificationHandlerOptions,\n\tSchemaUpdateError,\n} from './modifications/index.js'\nimport { createMigrationBuilder } from '@contember/database-migrations'\nimport { Migration } from './Migration.js'\nimport { Schema } from '@contember/schema'\n\nexport interface ModificationDescriptionResult {\n\tmodification: Migration.Modification\n\tschema: Schema\n\tdescription: ModificationDescription\n\thandler: ModificationHandler<any>\n\tgetSql: (options: ModificationHandlerCreateSqlOptions) => string\n}\n\nexport class MigrationDescriber {\n\tconstructor(private readonly modificationHandlerFactory: ModificationHandlerFactory) {\n\t}\n\n\tpublic describeModification(\n\t\tschema: Schema,\n\t\tmodification: Migration.Modification,\n\t\toptions: ModificationHandlerOptions,\n\t\tmodificationDescriptionContext: ModificationDescriptionContext = emptyModificationDescriptionContext,\n\t): ModificationDescriptionResult {\n\t\tconst modificationHandler = this.modificationHandlerFactory.create(\n\t\t\tmodification.modification,\n\t\t\tmodification,\n\t\t\tschema,\n\t\t\toptions,\n\t\t)\n\t\ttry {\n\t\t\tschema = modificationHandler.getSchemaUpdater()({ schema })\n\t\t} catch (e) {\n\t\t\tif (!(e instanceof SchemaUpdateError)) {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t\tthrow new SchemaUpdateError(e.message + '\\n for modification: \\n' + JSON.stringify(modification))\n\t\t}\n\t\treturn {\n\t\t\tmodification,\n\t\t\tschema,\n\t\t\tgetSql: options => {\n\t\t\t\tconst builder = createMigrationBuilder()\n\t\t\t\tmodificationHandler.createSql(builder, options)\n\t\t\t\treturn builder.getSql()\n\t\t\t},\n\t\t\tdescription: modificationHandler.describe(modificationDescriptionContext),\n\t\t\thandler: modificationHandler,\n\t\t}\n\t}\n\n\tpublic describeModifications(schema: Schema, migration: Migration): ModificationDescriptionResult[] {\n\t\tconst result = []\n\t\tconst createdEntities = []\n\t\tfor (const modification of migration.modifications) {\n\t\t\tif (modification.modification === createEntityModification.id || modification.modification === createViewModification.id) {\n\t\t\t\tcreatedEntities.push(modification.entity.name)\n\t\t\t}\n\t\t\tconst description = this.describeModification(\n\t\t\t\tschema,\n\t\t\t\tmodification,\n\t\t\t\t{\n\t\t\t\t\tformatVersion: migration.formatVersion,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tcreatedEntities,\n\t\t\t\t},\n\t\t\t)\n\t\t\tschema = description.schema\n\t\t\tresult.push(description)\n\t\t}\n\t\treturn result\n\t}\n}\n"],"names":["options"],"mappings":";;;;;;;;;;AAwBO,MAAM,mBAAmB;AAAA,EAC/B,YAA6B,4BAAwD;AAAxD,SAAA,6BAAA;AAAA,EAC7B;AAAA,EAEO,qBACN,QACA,cACA,SACA,iCAAiE,qCACjC;AAChC,UAAM,sBAAsB,KAAK,2BAA2B;AAAA,MAC3D,aAAa;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAED,QAAI;AACH,eAAS,oBAAoB,mBAAmB,EAAE,QAAQ;AAAA,IAC3D,SAAS,GAAG;AACX,UAAI,EAAE,aAAa,oBAAoB;AACtC,cAAM;AAAA,MACP;AACA,YAAM,IAAI,kBAAkB,EAAE,UAAU,4BAA4B,KAAK,UAAU,YAAY,CAAC;AAAA,IACjG;AACA,WAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA,QAAQ,CAAAA,aAAW;AAClB,cAAM,UAAU,uBAAA;AAChB,4BAAoB,UAAU,SAASA,QAAO;AAC9C,eAAO,QAAQ,OAAA;AAAA,MAChB;AAAA,MACA,aAAa,oBAAoB,SAAS,8BAA8B;AAAA,MACxE,SAAS;AAAA,IAAA;AAAA,EAEX;AAAA,EAEO,sBAAsB,QAAgB,WAAuD;AACnG,UAAM,SAAS,CAAA;AACf,UAAM,kBAAkB,CAAA;AACxB,eAAW,gBAAgB,UAAU,eAAe;AACnD,UAAI,aAAa,iBAAiB,yBAAyB,MAAM,aAAa,iBAAiB,uBAAuB,IAAI;AACzH,wBAAgB,KAAK,aAAa,OAAO,IAAI;AAAA,MAC9C;AACA,YAAM,cAAc,KAAK;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,UACC,eAAe,UAAU;AAAA,QAAA;AAAA,QAE1B;AAAA,UACC;AAAA,QAAA;AAAA,MACD;AAED,eAAS,YAAY;AACrB,aAAO,KAAK,WAAW;AAAA,IACxB;AACA,WAAO;AAAA,EACR;AACD;"}
|
|
@@ -36,6 +36,7 @@ const UpdateValidationSchemaModification = require("./modifications/validation/U
|
|
|
36
36
|
require("./modifications/ModificationHandlerFactory.cjs");
|
|
37
37
|
const RemoveChangedFieldDiffer = require("./modifications/differs/RemoveChangedFieldDiffer.cjs");
|
|
38
38
|
const RemoveViewDiffer = require("./modifications/differs/RemoveViewDiffer.cjs");
|
|
39
|
+
const UpdateViewDiffer = require("./modifications/differs/UpdateViewDiffer.cjs");
|
|
39
40
|
const CreateIndexModification = require("./modifications/indexes/CreateIndexModification.cjs");
|
|
40
41
|
const RemoveIndexModification = require("./modifications/indexes/RemoveIndexModification.cjs");
|
|
41
42
|
const CreateTriggerModification = require("./modifications/actions/CreateTriggerModification.cjs");
|
|
@@ -54,7 +55,9 @@ class SchemaDiffer {
|
|
|
54
55
|
}
|
|
55
56
|
diffSchemas(originalSchema, updatedSchema, {
|
|
56
57
|
skipInitialSchemaValidation = false,
|
|
57
|
-
skipRecreateValidation = false
|
|
58
|
+
skipRecreateValidation = false,
|
|
59
|
+
skipNonModelDiffers = false,
|
|
60
|
+
recreateViews = false
|
|
58
61
|
} = {}) {
|
|
59
62
|
if (!skipInitialSchemaValidation) {
|
|
60
63
|
const originalErrors = schemaUtils.SchemaValidator.validate(originalSchema);
|
|
@@ -68,13 +71,13 @@ class SchemaDiffer {
|
|
|
68
71
|
}
|
|
69
72
|
const differs = [
|
|
70
73
|
new RemoveIndexNamesModification.RemoveIndexNamesDiffer(),
|
|
71
|
-
new UpdateSettingsModification.UpdateSettingsDiffer(),
|
|
74
|
+
...skipNonModelDiffers ? [] : [new UpdateSettingsModification.UpdateSettingsDiffer()],
|
|
72
75
|
new ConvertOneToManyRelationModification.ConvertOneToManyRelationDiffer(),
|
|
73
76
|
new ConvertOneHasManyToManyHasManyRelationModification.ConvertOneHasManyToManyHasManyRelationDiffer(),
|
|
74
77
|
new ConvertOneHasManyToOneHasOneRelationModification.ConvertOneHasManyToOneHasOneRelationDiffer(),
|
|
75
78
|
new RemoveUniqueConstraintModification.RemoveUniqueConstraintDiffer(),
|
|
76
79
|
new RemoveIndexModification.RemoveIndexDiffer(),
|
|
77
|
-
new RemoveViewDiffer.RemoveViewDiffer(),
|
|
80
|
+
new RemoveViewDiffer.RemoveViewDiffer(recreateViews),
|
|
78
81
|
new RemoveEntityModification.RemoveEntityDiffer(),
|
|
79
82
|
new RemoveFieldModification.RemoveFieldDiffer(),
|
|
80
83
|
new CreateEnumModification.CreateEnumDiffer(),
|
|
@@ -96,19 +99,24 @@ class SchemaDiffer {
|
|
|
96
99
|
new CreateColumnModification.CreateColumnDiffer(),
|
|
97
100
|
new CreateRelationModification.CreateRelationDiffer(),
|
|
98
101
|
new CreateViewModification.CreateViewDiffer(),
|
|
102
|
+
...recreateViews ? [] : [new UpdateViewDiffer.UpdateViewDiffer()],
|
|
99
103
|
new CreateRelationInverseSideModification.CreateRelationInverseSideDiffer(),
|
|
100
104
|
new CreateUniqueConstraintModification.CreateUniqueConstraintDiffer(),
|
|
101
105
|
new CreateIndexModification.CreateIndexDiffer(),
|
|
102
106
|
new RemoveEnumModification.RemoveEnumDiffer(),
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
...skipNonModelDiffers ? [] : [
|
|
108
|
+
new UpdateAclSchemaModification.UpdateAclSchemaDiffer(this.options),
|
|
109
|
+
new UpdateValidationSchemaModification.UpdateValidationSchemaDiffer(this.options)
|
|
110
|
+
],
|
|
105
111
|
new UpdateEntityOrderByModification.UpdateEntityOrderByDiffer(),
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
...skipNonModelDiffers ? [] : [
|
|
113
|
+
new UpdateTargetModification.UpdateTargetDiffer(),
|
|
114
|
+
new CreateTargetModification.CreateTargetDiffer(),
|
|
115
|
+
new UpdateTriggerModification.UpdateTriggerDiffer(this.options),
|
|
116
|
+
new CreateTriggerModification.CreateTriggerDiffer(),
|
|
117
|
+
new RemoveTriggerModification.RemoveTriggerDiffer(),
|
|
118
|
+
new RemoveTargetModification.RemoveTargetDiffer()
|
|
119
|
+
]
|
|
112
120
|
];
|
|
113
121
|
const diffs = [];
|
|
114
122
|
let appliedDiffsSchema = originalSchema;
|
|
@@ -118,7 +126,14 @@ class SchemaDiffer {
|
|
|
118
126
|
diffs.push(...differDiffs);
|
|
119
127
|
}
|
|
120
128
|
if (!skipRecreateValidation) {
|
|
121
|
-
const
|
|
129
|
+
const targetForCompare = skipNonModelDiffers ? {
|
|
130
|
+
...updatedSchema,
|
|
131
|
+
acl: appliedDiffsSchema.acl,
|
|
132
|
+
validation: appliedDiffsSchema.validation,
|
|
133
|
+
actions: appliedDiffsSchema.actions,
|
|
134
|
+
settings: appliedDiffsSchema.settings
|
|
135
|
+
} : updatedSchema;
|
|
136
|
+
const errors = schemaUtils.deepCompare(targetForCompare, appliedDiffsSchema, [], (path) => {
|
|
122
137
|
if (path[0] === "model" && path[1] === "entities" && (path[3] === "unique" || path[3] === "index")) {
|
|
123
138
|
return (a, b) => {
|
|
124
139
|
return schemaUtils.compareArraysIgnoreOrder(a, b, path);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaDiffer.cjs","sources":["../../../../packages/schema-migrations/src/SchemaDiffer.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport {\n\tcompareArraysIgnoreOrder,\n\tdeepCompare,\n\tisInverseRelation,\n\tisOwningRelation,\n\tisRelation,\n\tSchemaValidator,\n\tValidationError,\n} from '@contember/schema-utils'\nimport { SchemaMigrator } from './SchemaMigrator'\nimport { Migration } from './Migration'\nimport { ImplementationException } from './exceptions'\nimport {\n\tConvertOneHasManyToManyHasManyRelationDiffer,\n\tConvertOneToManyRelationDiffer,\n\tCreateColumnDiffer,\n\tCreateEntityDiffer,\n\tCreateEnumDiffer,\n\tCreateRelationDiffer,\n\tCreateRelationInverseSideDiffer,\n\tCreateUniqueConstraintDiffer,\n\tCreateViewDiffer,\n\tDiffer,\n\tDisableOrphanRemovalDiffer,\n\tEnableOrphanRemovalDiffer,\n\tMakeRelationNotNullDiffer,\n\tMakeRelationNullableDiffer,\n\tRemoveEntityDiffer,\n\tRemoveEnumDiffer,\n\tRemoveFieldDiffer,\n\tRemoveUniqueConstraintDiffer,\n\tToggleEventLogDiffer,\n\tToggleJunctionEventLogDiffer,\n\tUpdateAclSchemaDiffer,\n\tUpdateColumnDefinitionDiffer,\n\tUpdateColumnNameDiffer,\n\tUpdateEntityOrderByDiffer,\n\tUpdateEntityTableNameDiffer,\n\tUpdateEnumDiffer,\n\tUpdateRelationOnDeleteDiffer,\n\tUpdateRelationOrderByDiffer,\n\tUpdateValidationSchemaDiffer,\n\tVERSION_LATEST,\n} from './modifications'\nimport { RemoveChangedFieldDiffer, RemoveViewDiffer } from './modifications/differs'\nimport { CreateIndexDiffer, RemoveIndexDiffer } from './modifications/indexes'\nimport { CreateTriggerDiffer, RemoveTriggerDiffer, UpdateTriggerDiffer } from './modifications/actions'\nimport { UpdateTargetDiffer } from './modifications/actions/UpdateTargetModification'\nimport { CreateTargetDiffer } from './modifications/actions/CreateTargetModification'\nimport { RemoveTargetDiffer } from './modifications/actions/RemoveTargetModification'\nimport { UpdateSettingsDiffer } from './modifications/settings'\nimport { RemoveIndexNamesDiffer } from './modifications/upgrade/RemoveIndexNamesModification'\nimport { ConvertOneHasManyToOneHasOneRelationDiffer } from './modifications/relations/ConvertOneHasManyToOneHasOneRelationModification'\n\ntype DiffOptions = { skipRecreateValidation?: boolean; skipInitialSchemaValidation?: boolean }\n\nexport class SchemaDiffer {\n\tconstructor(\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t\tprivate readonly options?: {\n\t\t\tmaxPatchSize?: number\n\t\t},\n\t) {}\n\n\tdiffSchemas(originalSchema: Schema, updatedSchema: Schema, {\n\t\tskipInitialSchemaValidation = false,\n\t\tskipRecreateValidation = false,\n\t}: DiffOptions = {}): Migration.Modification[] {\n\t\tif (!skipInitialSchemaValidation) {\n\t\t\tconst originalErrors = SchemaValidator.validate(originalSchema)\n\t\t\tif (originalErrors.length > 0) {\n\t\t\t\tthrow new InvalidSchemaException('original schema is not valid', originalErrors)\n\t\t\t}\n\t\t}\n\t\tconst updatedErrors = SchemaValidator.validate(updatedSchema)\n\t\tif (updatedErrors.length > 0) {\n\t\t\tthrow new InvalidSchemaException('updated schema is not valid', updatedErrors)\n\t\t}\n\n\t\tconst differs: Differ[] = [\n\t\t\tnew RemoveIndexNamesDiffer(),\n\t\t\tnew UpdateSettingsDiffer(),\n\t\t\tnew ConvertOneToManyRelationDiffer(),\n\t\t\tnew ConvertOneHasManyToManyHasManyRelationDiffer(),\n\t\t\tnew ConvertOneHasManyToOneHasOneRelationDiffer(),\n\t\t\tnew RemoveUniqueConstraintDiffer(),\n\t\t\tnew RemoveIndexDiffer(),\n\t\t\tnew RemoveViewDiffer(),\n\t\t\tnew RemoveEntityDiffer(),\n\t\t\tnew RemoveFieldDiffer(),\n\t\t\tnew CreateEnumDiffer(),\n\t\t\tnew UpdateEntityTableNameDiffer(),\n\t\t\tnew ToggleEventLogDiffer(),\n\t\t\tnew ToggleJunctionEventLogDiffer(),\n\t\t\tnew UpdateColumnDefinitionDiffer(),\n\t\t\tnew UpdateColumnNameDiffer(),\n\t\t\tnew UpdateRelationOnDeleteDiffer(),\n\t\t\tnew MakeRelationNotNullDiffer(),\n\t\t\tnew MakeRelationNullableDiffer(),\n\t\t\tnew EnableOrphanRemovalDiffer(),\n\t\t\tnew DisableOrphanRemovalDiffer(),\n\t\t\tnew UpdateRelationOrderByDiffer(),\n\t\t\tnew UpdateEnumDiffer(),\n\t\t\tnew RemoveChangedFieldDiffer(it => !isRelation(it) || isOwningRelation(it)),\n\t\t\tnew RemoveChangedFieldDiffer(it => isRelation(it) && isInverseRelation(it)),\n\t\t\tnew CreateEntityDiffer(),\n\t\t\tnew CreateColumnDiffer(),\n\t\t\tnew CreateRelationDiffer(),\n\t\t\tnew CreateViewDiffer(),\n\t\t\tnew CreateRelationInverseSideDiffer(),\n\t\t\tnew CreateUniqueConstraintDiffer(),\n\t\t\tnew CreateIndexDiffer(),\n\t\t\tnew RemoveEnumDiffer(),\n\t\t\tnew UpdateAclSchemaDiffer(this.options),\n\t\t\tnew UpdateValidationSchemaDiffer(this.options),\n\t\t\tnew UpdateEntityOrderByDiffer(),\n\t\t\tnew UpdateTargetDiffer(),\n\t\t\tnew CreateTargetDiffer(),\n\t\t\tnew UpdateTriggerDiffer(this.options),\n\t\t\tnew CreateTriggerDiffer(),\n\t\t\tnew RemoveTriggerDiffer(),\n\t\t\tnew RemoveTargetDiffer(),\n\t\t]\n\n\t\tconst diffs: Migration.Modification[] = []\n\t\tlet appliedDiffsSchema = originalSchema\n\t\tfor (const differ of differs) {\n\t\t\tconst differDiffs = differ.createDiff(appliedDiffsSchema, updatedSchema)\n\t\t\tappliedDiffsSchema = this.schemaMigrator.applyModifications(appliedDiffsSchema, differDiffs, VERSION_LATEST)\n\t\t\tdiffs.push(...differDiffs)\n\t\t}\n\n\t\tif (!skipRecreateValidation) {\n\t\t\tconst errors = deepCompare(updatedSchema, appliedDiffsSchema, [], path => {\n\t\t\t\tif (path[0] === 'model' && path[1] === 'entities' && (path[3] === 'unique' || path[3] === 'index')) {\n\t\t\t\t\treturn (a, b) => {\n\t\t\t\t\t\treturn compareArraysIgnoreOrder(a, b, path)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn null\n\t\t\t})\n\t\t\tif (errors.length === 0) {\n\t\t\t\treturn diffs\n\t\t\t}\n\t\t\tlet message = 'Updated schema cannot be recreated by the generated diff:'\n\t\t\tfor (const err of errors) {\n\t\t\t\tmessage += '\\n\\t' + err.path.join('.') + ': ' + err.message\n\t\t\t}\n\t\t\tmessage += '\\n\\nPlease fill a bug report'\n\t\t\tthrow new ImplementationException(message)\n\t\t}\n\n\t\treturn diffs\n\t}\n}\n\nexport class InvalidSchemaException extends Error {\n\tconstructor(message: string, public readonly validationErrors: ValidationError[]) {\n\t\tsuper(message)\n\t}\n}\n"],"names":["SchemaValidator","RemoveIndexNamesDiffer","UpdateSettingsDiffer","ConvertOneToManyRelationDiffer","ConvertOneHasManyToManyHasManyRelationDiffer","ConvertOneHasManyToOneHasOneRelationDiffer","RemoveUniqueConstraintDiffer","RemoveIndexDiffer","RemoveViewDiffer","RemoveEntityDiffer","RemoveFieldDiffer","CreateEnumDiffer","UpdateEntityTableNameDiffer","ToggleEventLogDiffer","ToggleJunctionEventLogDiffer","UpdateColumnDefinitionDiffer","UpdateColumnNameDiffer","UpdateRelationOnDeleteDiffer","MakeRelationNotNullDiffer","MakeRelationNullableDiffer","EnableOrphanRemovalDiffer","DisableOrphanRemovalDiffer","UpdateRelationOrderByDiffer","UpdateEnumDiffer","RemoveChangedFieldDiffer","isRelation","isOwningRelation","isInverseRelation","CreateEntityDiffer","CreateColumnDiffer","CreateRelationDiffer","CreateViewDiffer","CreateRelationInverseSideDiffer","CreateUniqueConstraintDiffer","CreateIndexDiffer","RemoveEnumDiffer","UpdateAclSchemaDiffer","UpdateValidationSchemaDiffer","UpdateEntityOrderByDiffer","UpdateTargetDiffer","CreateTargetDiffer","UpdateTriggerDiffer","CreateTriggerDiffer","RemoveTriggerDiffer","RemoveTargetDiffer","VERSION_LATEST","deepCompare","compareArraysIgnoreOrder","ImplementationException"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDO,MAAM,aAAa;AAAA,EACzB,YACkB,gBACA,SAGhB;AAJgB,SAAA,iBAAA;AACA,SAAA,UAAA;AAAA,EAGf;AAAA,EAEH,YAAY,gBAAwB,eAAuB;AAAA,IAC1D,8BAA8B;AAAA,IAC9B,yBAAyB;AAAA,EAAA,IACT,IAA8B;AAC9C,QAAI,CAAC,6BAA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EACR;AACD;AAEO,MAAM,+BAA+B,MAAM;AAAA,EACjD,YAAY,SAAiC,kBAAqC;AACjF,UAAM,OAAO;AAD+B,SAAA,mBAAA;AAAA,EAE7C;AACD;;;"}
|
|
1
|
+
{"version":3,"file":"SchemaDiffer.cjs","sources":["../../../../packages/schema-migrations/src/SchemaDiffer.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport {\n\tcompareArraysIgnoreOrder,\n\tdeepCompare,\n\tisInverseRelation,\n\tisOwningRelation,\n\tisRelation,\n\tSchemaValidator,\n\tValidationError,\n} from '@contember/schema-utils'\nimport { SchemaMigrator } from './SchemaMigrator.js'\nimport { Migration } from './Migration.js'\nimport { ImplementationException } from './exceptions.js'\nimport {\n\tConvertOneHasManyToManyHasManyRelationDiffer,\n\tConvertOneToManyRelationDiffer,\n\tCreateColumnDiffer,\n\tCreateEntityDiffer,\n\tCreateEnumDiffer,\n\tCreateRelationDiffer,\n\tCreateRelationInverseSideDiffer,\n\tCreateUniqueConstraintDiffer,\n\tCreateViewDiffer,\n\tDiffer,\n\tDisableOrphanRemovalDiffer,\n\tEnableOrphanRemovalDiffer,\n\tMakeRelationNotNullDiffer,\n\tMakeRelationNullableDiffer,\n\tRemoveEntityDiffer,\n\tRemoveEnumDiffer,\n\tRemoveFieldDiffer,\n\tRemoveUniqueConstraintDiffer,\n\tToggleEventLogDiffer,\n\tToggleJunctionEventLogDiffer,\n\tUpdateAclSchemaDiffer,\n\tUpdateColumnDefinitionDiffer,\n\tUpdateColumnNameDiffer,\n\tUpdateEntityOrderByDiffer,\n\tUpdateEntityTableNameDiffer,\n\tUpdateEnumDiffer,\n\tUpdateRelationOnDeleteDiffer,\n\tUpdateRelationOrderByDiffer,\n\tUpdateValidationSchemaDiffer,\n\tVERSION_LATEST,\n} from './modifications/index.js'\nimport { RemoveChangedFieldDiffer, RemoveViewDiffer, UpdateViewDiffer } from './modifications/differs/index.js'\nimport { CreateIndexDiffer, RemoveIndexDiffer } from './modifications/indexes/index.js'\nimport { CreateTriggerDiffer, RemoveTriggerDiffer, UpdateTriggerDiffer } from './modifications/actions/index.js'\nimport { UpdateTargetDiffer } from './modifications/actions/UpdateTargetModification.js'\nimport { CreateTargetDiffer } from './modifications/actions/CreateTargetModification.js'\nimport { RemoveTargetDiffer } from './modifications/actions/RemoveTargetModification.js'\nimport { UpdateSettingsDiffer } from './modifications/settings/index.js'\nimport { RemoveIndexNamesDiffer } from './modifications/upgrade/RemoveIndexNamesModification.js'\nimport { ConvertOneHasManyToOneHasOneRelationDiffer } from './modifications/relations/ConvertOneHasManyToOneHasOneRelationModification.js'\n\nexport type DiffOptions = {\n\tskipRecreateValidation?: boolean\n\tskipInitialSchemaValidation?: boolean\n\tskipNonModelDiffers?: boolean\n\t/**\n\t * Disable the in-place `CREATE OR REPLACE VIEW` optimization and drop & recreate every\n\t * changed view (with its dependant cascade) instead. Escape hatch for views whose real\n\t * output columns drifted without a matching field change (which would otherwise fail at\n\t * execute time with `SQLSTATE 42P16`).\n\t */\n\trecreateViews?: boolean\n}\n\nexport class SchemaDiffer {\n\tconstructor(\n\t\tprivate readonly schemaMigrator: SchemaMigrator,\n\t\tprivate readonly options?: {\n\t\t\tmaxPatchSize?: number\n\t\t},\n\t) {}\n\n\tdiffSchemas(originalSchema: Schema, updatedSchema: Schema, {\n\t\tskipInitialSchemaValidation = false,\n\t\tskipRecreateValidation = false,\n\t\tskipNonModelDiffers = false,\n\t\trecreateViews = false,\n\t}: DiffOptions = {}): Migration.Modification[] {\n\t\tif (!skipInitialSchemaValidation) {\n\t\t\tconst originalErrors = SchemaValidator.validate(originalSchema)\n\t\t\tif (originalErrors.length > 0) {\n\t\t\t\tthrow new InvalidSchemaException('original schema is not valid', originalErrors)\n\t\t\t}\n\t\t}\n\t\tconst updatedErrors = SchemaValidator.validate(updatedSchema)\n\t\tif (updatedErrors.length > 0) {\n\t\t\tthrow new InvalidSchemaException('updated schema is not valid', updatedErrors)\n\t\t}\n\n\t\tconst differs: Differ[] = [\n\t\t\tnew RemoveIndexNamesDiffer(),\n\t\t\t...skipNonModelDiffers ? [] : [new UpdateSettingsDiffer()],\n\t\t\tnew ConvertOneToManyRelationDiffer(),\n\t\t\tnew ConvertOneHasManyToManyHasManyRelationDiffer(),\n\t\t\tnew ConvertOneHasManyToOneHasOneRelationDiffer(),\n\t\t\tnew RemoveUniqueConstraintDiffer(),\n\t\t\tnew RemoveIndexDiffer(),\n\t\t\tnew RemoveViewDiffer(recreateViews),\n\t\t\tnew RemoveEntityDiffer(),\n\t\t\tnew RemoveFieldDiffer(),\n\t\t\tnew CreateEnumDiffer(),\n\t\t\tnew UpdateEntityTableNameDiffer(),\n\t\t\tnew ToggleEventLogDiffer(),\n\t\t\tnew ToggleJunctionEventLogDiffer(),\n\t\t\tnew UpdateColumnDefinitionDiffer(),\n\t\t\tnew UpdateColumnNameDiffer(),\n\t\t\tnew UpdateRelationOnDeleteDiffer(),\n\t\t\tnew MakeRelationNotNullDiffer(),\n\t\t\tnew MakeRelationNullableDiffer(),\n\t\t\tnew EnableOrphanRemovalDiffer(),\n\t\t\tnew DisableOrphanRemovalDiffer(),\n\t\t\tnew UpdateRelationOrderByDiffer(),\n\t\t\tnew UpdateEnumDiffer(),\n\t\t\tnew RemoveChangedFieldDiffer(it => !isRelation(it) || isOwningRelation(it)),\n\t\t\tnew RemoveChangedFieldDiffer(it => isRelation(it) && isInverseRelation(it)),\n\t\t\tnew CreateEntityDiffer(),\n\t\t\tnew CreateColumnDiffer(),\n\t\t\tnew CreateRelationDiffer(),\n\t\t\tnew CreateViewDiffer(),\n\t\t\t...recreateViews ? [] : [new UpdateViewDiffer()],\n\t\t\tnew CreateRelationInverseSideDiffer(),\n\t\t\tnew CreateUniqueConstraintDiffer(),\n\t\t\tnew CreateIndexDiffer(),\n\t\t\tnew RemoveEnumDiffer(),\n\t\t\t...skipNonModelDiffers ? [] : [\n\t\t\t\tnew UpdateAclSchemaDiffer(this.options),\n\t\t\t\tnew UpdateValidationSchemaDiffer(this.options),\n\t\t\t],\n\t\t\tnew UpdateEntityOrderByDiffer(),\n\t\t\t...skipNonModelDiffers ? [] : [\n\t\t\t\tnew UpdateTargetDiffer(),\n\t\t\t\tnew CreateTargetDiffer(),\n\t\t\t\tnew UpdateTriggerDiffer(this.options),\n\t\t\t\tnew CreateTriggerDiffer(),\n\t\t\t\tnew RemoveTriggerDiffer(),\n\t\t\t\tnew RemoveTargetDiffer(),\n\t\t\t],\n\t\t]\n\n\t\tconst diffs: Migration.Modification[] = []\n\t\tlet appliedDiffsSchema = originalSchema\n\t\tfor (const differ of differs) {\n\t\t\tconst differDiffs = differ.createDiff(appliedDiffsSchema, updatedSchema)\n\t\t\tappliedDiffsSchema = this.schemaMigrator.applyModifications(appliedDiffsSchema, differDiffs, VERSION_LATEST)\n\t\t\tdiffs.push(...differDiffs)\n\t\t}\n\n\t\tif (!skipRecreateValidation) {\n\t\t\tconst targetForCompare = skipNonModelDiffers\n\t\t\t\t? {\n\t\t\t\t\t...updatedSchema,\n\t\t\t\t\tacl: appliedDiffsSchema.acl,\n\t\t\t\t\tvalidation: appliedDiffsSchema.validation,\n\t\t\t\t\tactions: appliedDiffsSchema.actions,\n\t\t\t\t\tsettings: appliedDiffsSchema.settings,\n\t\t\t\t}\n\t\t\t\t: updatedSchema\n\t\t\tconst errors = deepCompare(targetForCompare, appliedDiffsSchema, [], path => {\n\t\t\t\tif (path[0] === 'model' && path[1] === 'entities' && (path[3] === 'unique' || path[3] === 'index')) {\n\t\t\t\t\treturn (a, b) => {\n\t\t\t\t\t\treturn compareArraysIgnoreOrder(a, b, path)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn null\n\t\t\t})\n\t\t\tif (errors.length === 0) {\n\t\t\t\treturn diffs\n\t\t\t}\n\t\t\tlet message = 'Updated schema cannot be recreated by the generated diff:'\n\t\t\tfor (const err of errors) {\n\t\t\t\tmessage += '\\n\\t' + err.path.join('.') + ': ' + err.message\n\t\t\t}\n\t\t\tmessage += '\\n\\nPlease fill a bug report'\n\t\t\tthrow new ImplementationException(message)\n\t\t}\n\n\t\treturn diffs\n\t}\n}\n\nexport class InvalidSchemaException extends Error {\n\tconstructor(message: string, public readonly validationErrors: ValidationError[]) {\n\t\tsuper(message)\n\t}\n}\n"],"names":["SchemaValidator","RemoveIndexNamesDiffer","UpdateSettingsDiffer","ConvertOneToManyRelationDiffer","ConvertOneHasManyToManyHasManyRelationDiffer","ConvertOneHasManyToOneHasOneRelationDiffer","RemoveUniqueConstraintDiffer","RemoveIndexDiffer","RemoveViewDiffer","RemoveEntityDiffer","RemoveFieldDiffer","CreateEnumDiffer","UpdateEntityTableNameDiffer","ToggleEventLogDiffer","ToggleJunctionEventLogDiffer","UpdateColumnDefinitionDiffer","UpdateColumnNameDiffer","UpdateRelationOnDeleteDiffer","MakeRelationNotNullDiffer","MakeRelationNullableDiffer","EnableOrphanRemovalDiffer","DisableOrphanRemovalDiffer","UpdateRelationOrderByDiffer","UpdateEnumDiffer","RemoveChangedFieldDiffer","isRelation","isOwningRelation","isInverseRelation","CreateEntityDiffer","CreateColumnDiffer","CreateRelationDiffer","CreateViewDiffer","UpdateViewDiffer","CreateRelationInverseSideDiffer","CreateUniqueConstraintDiffer","CreateIndexDiffer","RemoveEnumDiffer","UpdateAclSchemaDiffer","UpdateValidationSchemaDiffer","UpdateEntityOrderByDiffer","UpdateTargetDiffer","CreateTargetDiffer","UpdateTriggerDiffer","CreateTriggerDiffer","RemoveTriggerDiffer","RemoveTargetDiffer","VERSION_LATEST","deepCompare","compareArraysIgnoreOrder","ImplementationException"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEO,MAAM,aAAa;AAAA,EACzB,YACkB,gBACA,SAGhB;AAJgB,SAAA,iBAAA;AACA,SAAA,UAAA;AAAA,EAGf;AAAA,EAEH,YAAY,gBAAwB,eAAuB;AAAA,IAC1D,8BAA8B;AAAA,IAC9B,yBAAyB;AAAA,IACzB,sBAAsB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