@contember/schema-migrations 1.2.0-alpha.8 → 1.2.0-beta.1
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/src/Migration.d.ts +2 -0
- package/dist/src/Migration.d.ts.map +1 -1
- package/dist/src/Migration.js +2 -2
- package/dist/src/Migration.js.map +1 -1
- package/dist/src/MigrationCreator.d.ts +3 -1
- package/dist/src/MigrationCreator.d.ts.map +1 -1
- package/dist/src/MigrationCreator.js +2 -2
- package/dist/src/MigrationCreator.js.map +1 -1
- package/dist/src/MigrationDescriber.d.ts +1 -2
- package/dist/src/MigrationDescriber.d.ts.map +1 -1
- package/dist/src/MigrationDescriber.js +5 -7
- package/dist/src/MigrationDescriber.js.map +1 -1
- package/dist/src/MigrationFilesManager.d.ts.map +1 -1
- package/dist/src/MigrationFilesManager.js +10 -19
- package/dist/src/MigrationFilesManager.js.map +1 -1
- package/dist/src/MigrationsResolver.d.ts.map +1 -1
- package/dist/src/MigrationsResolver.js +1 -0
- package/dist/src/MigrationsResolver.js.map +1 -1
- package/dist/src/SchemaDiffer.d.ts +6 -1
- package/dist/src/SchemaDiffer.d.ts.map +1 -1
- package/dist/src/SchemaDiffer.js +46 -54
- package/dist/src/SchemaDiffer.js.map +1 -1
- package/dist/src/SchemaMigrator.d.ts +3 -2
- package/dist/src/SchemaMigrator.d.ts.map +1 -1
- package/dist/src/SchemaMigrator.js.map +1 -1
- package/dist/src/index.d.ts +1 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/modifications/ModificationHandler.d.ts +16 -8
- package/dist/src/modifications/ModificationHandler.d.ts.map +1 -1
- package/dist/src/modifications/ModificationHandler.js +9 -1
- package/dist/src/modifications/ModificationHandler.js.map +1 -1
- package/dist/src/modifications/ModificationHandlerFactory.d.ts +8 -7
- package/dist/src/modifications/ModificationHandlerFactory.d.ts.map +1 -1
- package/dist/src/modifications/ModificationHandlerFactory.js +43 -39
- package/dist/src/modifications/ModificationHandlerFactory.js.map +1 -1
- package/dist/src/modifications/acl/PatchAclSchemaModification.d.ts +13 -2
- package/dist/src/modifications/acl/PatchAclSchemaModification.d.ts.map +1 -1
- package/dist/src/modifications/acl/PatchAclSchemaModification.js +28 -28
- package/dist/src/modifications/acl/PatchAclSchemaModification.js.map +1 -1
- package/dist/src/modifications/acl/UpdateAclSchemaModification.d.ts +17 -3
- package/dist/src/modifications/acl/UpdateAclSchemaModification.d.ts.map +1 -1
- package/dist/src/modifications/acl/UpdateAclSchemaModification.js +33 -30
- package/dist/src/modifications/acl/UpdateAclSchemaModification.js.map +1 -1
- package/dist/src/modifications/columns/CreateColumnModification.d.ts +21 -3
- package/dist/src/modifications/columns/CreateColumnModification.d.ts.map +1 -1
- package/dist/src/modifications/columns/CreateColumnModification.js +72 -69
- package/dist/src/modifications/columns/CreateColumnModification.js.map +1 -1
- package/dist/src/modifications/columns/UpdateColumnDefinitionModification.d.ts +20 -4
- package/dist/src/modifications/columns/UpdateColumnDefinitionModification.d.ts.map +1 -1
- package/dist/src/modifications/columns/UpdateColumnDefinitionModification.js +78 -71
- package/dist/src/modifications/columns/UpdateColumnDefinitionModification.js.map +1 -1
- package/dist/src/modifications/columns/UpdateColumnNameModification.d.ts +18 -2
- package/dist/src/modifications/columns/UpdateColumnNameModification.d.ts.map +1 -1
- package/dist/src/modifications/columns/UpdateColumnNameModification.js +97 -94
- package/dist/src/modifications/columns/UpdateColumnNameModification.js.map +1 -1
- package/dist/src/modifications/constraints/CreateUniqueConstraintModification.d.ts +21 -3
- package/dist/src/modifications/constraints/CreateUniqueConstraintModification.d.ts.map +1 -1
- package/dist/src/modifications/constraints/CreateUniqueConstraintModification.js +72 -66
- package/dist/src/modifications/constraints/CreateUniqueConstraintModification.js.map +1 -1
- package/dist/src/modifications/constraints/RemoveUniqueConstraintModification.d.ts +18 -2
- package/dist/src/modifications/constraints/RemoveUniqueConstraintModification.d.ts.map +1 -1
- package/dist/src/modifications/constraints/RemoveUniqueConstraintModification.js +45 -42
- package/dist/src/modifications/constraints/RemoveUniqueConstraintModification.js.map +1 -1
- package/dist/src/modifications/differs/ChangeViewNonViewDiffer.js +1 -1
- package/dist/src/modifications/differs/RemoveChangedFieldDiffer.d.ts +1 -3
- package/dist/src/modifications/differs/RemoveChangedFieldDiffer.d.ts.map +1 -1
- package/dist/src/modifications/differs/RemoveChangedFieldDiffer.js +1 -1
- package/dist/src/modifications/differs/RemoveChangedViewDiffer.d.ts +1 -2
- package/dist/src/modifications/differs/RemoveChangedViewDiffer.d.ts.map +1 -1
- package/dist/src/modifications/differs/RemoveChangedViewDiffer.js +7 -20
- package/dist/src/modifications/differs/RemoveChangedViewDiffer.js.map +1 -1
- package/dist/src/modifications/entities/CreateEntityModification.d.ts +19 -2
- package/dist/src/modifications/entities/CreateEntityModification.d.ts.map +1 -1
- package/dist/src/modifications/entities/CreateEntityModification.js +66 -63
- package/dist/src/modifications/entities/CreateEntityModification.js.map +1 -1
- package/dist/src/modifications/entities/CreateViewModification.d.ts +21 -2
- package/dist/src/modifications/entities/CreateViewModification.d.ts.map +1 -1
- package/dist/src/modifications/entities/CreateViewModification.js +59 -56
- package/dist/src/modifications/entities/CreateViewModification.js.map +1 -1
- package/dist/src/modifications/entities/RemoveEntityModification.d.ts +22 -2
- package/dist/src/modifications/entities/RemoveEntityModification.d.ts.map +1 -1
- package/dist/src/modifications/entities/RemoveEntityModification.js +73 -70
- package/dist/src/modifications/entities/RemoveEntityModification.js.map +1 -1
- package/dist/src/modifications/entities/ToggleEventLogModification.d.ts +19 -2
- package/dist/src/modifications/entities/ToggleEventLogModification.d.ts.map +1 -1
- package/dist/src/modifications/entities/ToggleEventLogModification.js +57 -54
- package/dist/src/modifications/entities/ToggleEventLogModification.js.map +1 -1
- package/dist/src/modifications/entities/UpdateEntityNameModification.d.ts +18 -2
- package/dist/src/modifications/entities/UpdateEntityNameModification.d.ts.map +1 -1
- package/dist/src/modifications/entities/UpdateEntityNameModification.js +78 -78
- package/dist/src/modifications/entities/UpdateEntityNameModification.js.map +1 -1
- package/dist/src/modifications/entities/UpdateEntityTableNameModification.d.ts +18 -2
- package/dist/src/modifications/entities/UpdateEntityTableNameModification.d.ts.map +1 -1
- package/dist/src/modifications/entities/UpdateEntityTableNameModification.js +40 -34
- package/dist/src/modifications/entities/UpdateEntityTableNameModification.js.map +1 -1
- package/dist/src/modifications/entities/UpdateViewModification.d.ts +15 -3
- package/dist/src/modifications/entities/UpdateViewModification.d.ts.map +1 -1
- package/dist/src/modifications/entities/UpdateViewModification.js +28 -28
- package/dist/src/modifications/entities/UpdateViewModification.js.map +1 -1
- package/dist/src/modifications/enums/CreateEnumModification.d.ts +18 -2
- package/dist/src/modifications/enums/CreateEnumModification.d.ts.map +1 -1
- package/dist/src/modifications/enums/CreateEnumModification.js +42 -36
- package/dist/src/modifications/enums/CreateEnumModification.js.map +1 -1
- package/dist/src/modifications/enums/RemoveEnumModification.d.ts +18 -2
- package/dist/src/modifications/enums/RemoveEnumModification.d.ts.map +1 -1
- package/dist/src/modifications/enums/RemoveEnumModification.js +36 -33
- package/dist/src/modifications/enums/RemoveEnumModification.js.map +1 -1
- package/dist/src/modifications/enums/UpdateEnumModification.d.ts +19 -2
- package/dist/src/modifications/enums/UpdateEnumModification.d.ts.map +1 -1
- package/dist/src/modifications/enums/UpdateEnumModification.js +43 -40
- package/dist/src/modifications/enums/UpdateEnumModification.js.map +1 -1
- package/dist/src/modifications/fields/RemoveFieldModification.d.ts +20 -2
- package/dist/src/modifications/fields/RemoveFieldModification.d.ts.map +1 -1
- package/dist/src/modifications/fields/RemoveFieldModification.js +67 -64
- package/dist/src/modifications/fields/RemoveFieldModification.js.map +1 -1
- package/dist/src/modifications/fields/UpdateFieldNameModification.d.ts +18 -2
- package/dist/src/modifications/fields/UpdateFieldNameModification.d.ts.map +1 -1
- package/dist/src/modifications/fields/UpdateFieldNameModification.js +132 -132
- package/dist/src/modifications/fields/UpdateFieldNameModification.js.map +1 -1
- package/dist/src/modifications/index.d.ts +14 -0
- package/dist/src/modifications/index.d.ts.map +1 -0
- package/dist/src/modifications/index.js +32 -0
- package/dist/src/modifications/index.js.map +1 -0
- package/dist/src/modifications/indexes/CreateIndexModification.d.ts +18 -3
- package/dist/src/modifications/indexes/CreateIndexModification.d.ts.map +1 -1
- package/dist/src/modifications/indexes/CreateIndexModification.js +68 -65
- package/dist/src/modifications/indexes/CreateIndexModification.js.map +1 -1
- package/dist/src/modifications/indexes/RemoveIndexModification.d.ts +18 -2
- package/dist/src/modifications/indexes/RemoveIndexModification.d.ts.map +1 -1
- package/dist/src/modifications/indexes/RemoveIndexModification.js +47 -44
- package/dist/src/modifications/indexes/RemoveIndexModification.js.map +1 -1
- package/dist/src/modifications/relations/ConvertOneHasManyToManyHasManyRelationModification.d.ts +22 -3
- package/dist/src/modifications/relations/ConvertOneHasManyToManyHasManyRelationModification.d.ts.map +1 -1
- package/dist/src/modifications/relations/ConvertOneHasManyToManyHasManyRelationModification.js +68 -65
- package/dist/src/modifications/relations/ConvertOneHasManyToManyHasManyRelationModification.js.map +1 -1
- package/dist/src/modifications/relations/ConvertOneToManyRelationModification.d.ts +22 -2
- package/dist/src/modifications/relations/ConvertOneToManyRelationModification.d.ts.map +1 -1
- package/dist/src/modifications/relations/ConvertOneToManyRelationModification.js +81 -70
- package/dist/src/modifications/relations/ConvertOneToManyRelationModification.js.map +1 -1
- package/dist/src/modifications/relations/CreateRelationInverseSideModification.d.ts +18 -3
- package/dist/src/modifications/relations/CreateRelationInverseSideModification.d.ts.map +1 -1
- package/dist/src/modifications/relations/CreateRelationInverseSideModification.js +36 -33
- package/dist/src/modifications/relations/CreateRelationInverseSideModification.js.map +1 -1
- package/dist/src/modifications/relations/CreateRelationModification.d.ts +24 -3
- package/dist/src/modifications/relations/CreateRelationModification.d.ts.map +1 -1
- package/dist/src/modifications/relations/CreateRelationModification.js +99 -85
- package/dist/src/modifications/relations/CreateRelationModification.js.map +1 -1
- package/dist/src/modifications/relations/DisableOrphanRemovalModification.d.ts +18 -2
- package/dist/src/modifications/relations/DisableOrphanRemovalModification.d.ts.map +1 -1
- package/dist/src/modifications/relations/DisableOrphanRemovalModification.js +42 -39
- package/dist/src/modifications/relations/DisableOrphanRemovalModification.js.map +1 -1
- package/dist/src/modifications/relations/EnableOrphanRemovalModification.d.ts +18 -2
- package/dist/src/modifications/relations/EnableOrphanRemovalModification.d.ts.map +1 -1
- package/dist/src/modifications/relations/EnableOrphanRemovalModification.js +45 -42
- package/dist/src/modifications/relations/EnableOrphanRemovalModification.js.map +1 -1
- package/dist/src/modifications/relations/MakeRelationNotNullModification.d.ts +19 -2
- package/dist/src/modifications/relations/MakeRelationNotNullModification.d.ts.map +1 -1
- package/dist/src/modifications/relations/MakeRelationNotNullModification.js +55 -52
- package/dist/src/modifications/relations/MakeRelationNotNullModification.js.map +1 -1
- package/dist/src/modifications/relations/MakeRelationNullableModification.d.ts +18 -2
- package/dist/src/modifications/relations/MakeRelationNullableModification.d.ts.map +1 -1
- package/dist/src/modifications/relations/MakeRelationNullableModification.js +54 -51
- package/dist/src/modifications/relations/MakeRelationNullableModification.js.map +1 -1
- package/dist/src/modifications/relations/ToggleJunctionEventLogModification.d.ts +25 -0
- package/dist/src/modifications/relations/ToggleJunctionEventLogModification.d.ts.map +1 -0
- package/dist/src/modifications/relations/ToggleJunctionEventLogModification.js +84 -0
- package/dist/src/modifications/relations/ToggleJunctionEventLogModification.js.map +1 -0
- package/dist/src/modifications/relations/UpdateRelationOnDeleteModification.d.ts +18 -3
- package/dist/src/modifications/relations/UpdateRelationOnDeleteModification.d.ts.map +1 -1
- package/dist/src/modifications/relations/UpdateRelationOnDeleteModification.js +42 -39
- package/dist/src/modifications/relations/UpdateRelationOnDeleteModification.js.map +1 -1
- package/dist/src/modifications/relations/UpdateRelationOrderByModification.d.ts +18 -3
- package/dist/src/modifications/relations/UpdateRelationOrderByModification.d.ts.map +1 -1
- package/dist/src/modifications/relations/UpdateRelationOrderByModification.js +43 -40
- package/dist/src/modifications/relations/UpdateRelationOrderByModification.js.map +1 -1
- package/dist/src/modifications/relations/index.d.ts +1 -1
- package/dist/src/modifications/relations/index.d.ts.map +1 -1
- package/dist/src/modifications/relations/index.js +1 -1
- package/dist/src/modifications/relations/index.js.map +1 -1
- package/dist/src/modifications/settings/UpdateSettingsModification.d.ts +28 -0
- package/dist/src/modifications/settings/UpdateSettingsModification.d.ts.map +1 -0
- package/dist/src/modifications/settings/UpdateSettingsModification.js +64 -0
- package/dist/src/modifications/settings/UpdateSettingsModification.js.map +1 -0
- package/dist/src/modifications/settings/index.d.ts +2 -0
- package/dist/src/modifications/settings/index.d.ts.map +1 -0
- package/dist/src/modifications/settings/index.js +18 -0
- package/dist/src/modifications/settings/index.js.map +1 -0
- package/dist/src/modifications/utils/columnUtils.d.ts +3 -0
- package/dist/src/modifications/utils/columnUtils.d.ts.map +1 -0
- package/dist/src/modifications/utils/columnUtils.js +9 -0
- package/dist/src/modifications/utils/columnUtils.js.map +1 -0
- package/dist/src/modifications/utils/createJunctionTable.d.ts +2 -1
- package/dist/src/modifications/utils/createJunctionTable.d.ts.map +1 -1
- package/dist/src/modifications/utils/createJunctionTable.js +7 -5
- package/dist/src/modifications/utils/createJunctionTable.js.map +1 -1
- package/dist/src/modifications/utils/diffUtils.d.ts +14 -12
- package/dist/src/modifications/utils/diffUtils.d.ts.map +1 -1
- package/dist/src/modifications/utils/diffUtils.js.map +1 -1
- package/dist/src/modifications/utils/schemaMeta.d.ts +8 -0
- package/dist/src/modifications/utils/schemaMeta.d.ts.map +1 -0
- package/dist/src/modifications/utils/schemaMeta.js +13 -0
- package/dist/src/modifications/utils/schemaMeta.js.map +1 -0
- package/dist/src/modifications/utils/schemaUpdateUtils.d.ts +4 -2
- package/dist/src/modifications/utils/schemaUpdateUtils.d.ts.map +1 -1
- package/dist/src/modifications/utils/schemaUpdateUtils.js +24 -2
- package/dist/src/modifications/utils/schemaUpdateUtils.js.map +1 -1
- package/dist/src/modifications/utils/viewDependencies.d.ts +4 -2
- package/dist/src/modifications/utils/viewDependencies.d.ts.map +1 -1
- package/dist/src/modifications/utils/viewDependencies.js +29 -6
- package/dist/src/modifications/utils/viewDependencies.js.map +1 -1
- package/dist/src/modifications/validation/PatchValidationSchemaModification.d.ts +13 -2
- package/dist/src/modifications/validation/PatchValidationSchemaModification.d.ts.map +1 -1
- package/dist/src/modifications/validation/PatchValidationSchemaModification.js +28 -28
- package/dist/src/modifications/validation/PatchValidationSchemaModification.js.map +1 -1
- package/dist/src/modifications/validation/UpdateValidationSchemaModification.d.ts +17 -3
- package/dist/src/modifications/validation/UpdateValidationSchemaModification.d.ts.map +1 -1
- package/dist/src/modifications/validation/UpdateValidationSchemaModification.js +33 -30
- package/dist/src/modifications/validation/UpdateValidationSchemaModification.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/tests/cases/integration/convertOneHasManyToManyHasManyRelation.test.js +3 -2
- package/dist/tests/cases/integration/convertOneHasManyToManyHasManyRelation.test.js.map +1 -1
- package/dist/tests/cases/integration/createColumn.test.js +36 -0
- package/dist/tests/cases/integration/createColumn.test.js.map +1 -1
- package/dist/tests/cases/integration/createManyHasMany.test.js +3 -2
- package/dist/tests/cases/integration/createManyHasMany.test.js.map +1 -1
- package/dist/tests/cases/integration/createView.test.js +80 -0
- package/dist/tests/cases/integration/createView.test.js.map +1 -1
- package/dist/tests/cases/integration/removeField.test.js +72 -0
- package/dist/tests/cases/integration/removeField.test.js.map +1 -1
- package/dist/tests/cases/integration/takenIndexName.test.d.ts +2 -0
- package/dist/tests/cases/integration/takenIndexName.test.d.ts.map +1 -0
- package/dist/tests/cases/integration/takenIndexName.test.js +307 -0
- package/dist/tests/cases/integration/takenIndexName.test.js.map +1 -0
- package/dist/tests/cases/integration/updateColumnDefinition.test.js +160 -0
- package/dist/tests/cases/integration/updateColumnDefinition.test.js.map +1 -1
- package/dist/tests/scripts/checkCreateConsistentMigrations.js +5 -4
- package/dist/tests/scripts/checkCreateConsistentMigrations.js.map +1 -1
- package/dist/tests/src/tests.d.ts.map +1 -1
- package/dist/tests/src/tests.js +15 -5
- package/dist/tests/src/tests.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/Migration.ts +3 -1
- package/src/MigrationCreator.ts +2 -1
- package/src/MigrationDescriber.ts +8 -8
- package/src/MigrationFilesManager.ts +10 -20
- package/src/MigrationsResolver.ts +1 -0
- package/src/SchemaDiffer.ts +82 -85
- package/src/SchemaMigrator.ts +3 -2
- package/src/index.ts +1 -5
- package/src/modifications/ModificationHandler.ts +22 -9
- package/src/modifications/ModificationHandlerFactory.ts +69 -65
- package/src/modifications/acl/PatchAclSchemaModification.ts +7 -8
- package/src/modifications/acl/UpdateAclSchemaModification.ts +16 -15
- package/src/modifications/columns/CreateColumnModification.ts +21 -18
- package/src/modifications/columns/UpdateColumnDefinitionModification.ts +58 -47
- package/src/modifications/columns/UpdateColumnNameModification.ts +60 -53
- package/src/modifications/constraints/CreateUniqueConstraintModification.ts +23 -17
- package/src/modifications/constraints/RemoveUniqueConstraintModification.ts +18 -14
- package/src/modifications/differs/ChangeViewNonViewDiffer.ts +2 -2
- package/src/modifications/differs/RemoveChangedFieldDiffer.ts +2 -2
- package/src/modifications/differs/RemoveChangedViewDiffer.ts +9 -22
- package/src/modifications/entities/CreateEntityModification.ts +18 -9
- package/src/modifications/entities/CreateViewModification.ts +10 -8
- package/src/modifications/entities/RemoveEntityModification.ts +24 -16
- package/src/modifications/entities/ToggleEventLogModification.ts +20 -13
- package/src/modifications/entities/UpdateEntityNameModification.ts +11 -10
- package/src/modifications/entities/UpdateEntityTableNameModification.ts +18 -13
- package/src/modifications/entities/UpdateViewModification.ts +7 -7
- package/src/modifications/enums/CreateEnumModification.ts +18 -13
- package/src/modifications/enums/RemoveEnumModification.ts +14 -12
- package/src/modifications/enums/UpdateEnumModification.ts +15 -13
- package/src/modifications/fields/RemoveFieldModification.ts +20 -17
- package/src/modifications/fields/UpdateFieldNameModification.ts +18 -18
- package/src/modifications/index.ts +13 -0
- package/src/modifications/indexes/CreateIndexModification.ts +13 -12
- package/src/modifications/indexes/RemoveIndexModification.ts +12 -8
- package/src/modifications/relations/ConvertOneHasManyToManyHasManyRelationModification.ts +48 -29
- package/src/modifications/relations/ConvertOneToManyRelationModification.ts +50 -27
- package/src/modifications/relations/CreateRelationInverseSideModification.ts +15 -13
- package/src/modifications/relations/CreateRelationModification.ts +65 -35
- package/src/modifications/relations/DisableOrphanRemovalModification.ts +15 -12
- package/src/modifications/relations/EnableOrphanRemovalModification.ts +16 -13
- package/src/modifications/relations/MakeRelationNotNullModification.ts +16 -14
- package/src/modifications/relations/MakeRelationNullableModification.ts +17 -13
- package/src/modifications/relations/{ToggleManyHasManyEventLogModification.ts → ToggleJunctionEventLogModification.ts} +21 -14
- package/src/modifications/relations/UpdateRelationOnDeleteModification.ts +16 -14
- package/src/modifications/relations/UpdateRelationOrderByModification.ts +17 -14
- package/src/modifications/relations/index.ts +1 -1
- package/src/modifications/settings/UpdateSettingsModification.ts +87 -0
- package/src/modifications/settings/index.ts +1 -0
- package/src/modifications/utils/columnUtils.ts +5 -0
- package/src/modifications/utils/createJunctionTable.ts +7 -5
- package/src/modifications/utils/diffUtils.ts +12 -12
- package/src/modifications/utils/schemaMeta.ts +18 -0
- package/src/modifications/utils/schemaUpdateUtils.ts +22 -2
- package/src/modifications/utils/viewDependencies.ts +28 -5
- package/src/modifications/validation/PatchValidationSchemaModification.ts +7 -7
- package/src/modifications/validation/UpdateValidationSchemaModification.ts +17 -14
- package/src/tsconfig.json +2 -2
- package/tests/cases/integration/convertOneHasManyToManyHasManyRelation.test.ts +3 -2
- package/tests/cases/integration/createColumn.test.ts +33 -0
- package/tests/cases/integration/createManyHasMany.test.ts +3 -2
- package/tests/cases/integration/createView.test.ts +70 -0
- package/tests/cases/integration/removeField.test.ts +58 -0
- package/tests/cases/integration/takenIndexName.test.ts +314 -0
- package/tests/cases/integration/updateColumnDefinition.test.ts +138 -1
- package/tests/scripts/checkCreateConsistentMigrations.ts +3 -2
- package/tests/src/tests.ts +21 -11
- package/dist/src/modifications/relations/ToggleManyHasManyEventLogModification.d.ts +0 -8
- package/dist/src/modifications/relations/ToggleManyHasManyEventLogModification.d.ts.map +0 -1
- package/dist/src/modifications/relations/ToggleManyHasManyEventLogModification.js +0 -81
- package/dist/src/modifications/relations/ToggleManyHasManyEventLogModification.js.map +0 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Model } from '@contember/schema'
|
|
2
|
+
import { Migration } from '../../Migration'
|
|
3
|
+
import { removeEntityModification } from '../entities'
|
|
2
4
|
|
|
3
|
-
type
|
|
4
|
-
export const
|
|
5
|
-
const dependants:
|
|
5
|
+
type EntityDependantViews = Map<string, Set<Model.Entity>>
|
|
6
|
+
export const getEntityDependantViews = (model: Model.Schema): EntityDependantViews => {
|
|
7
|
+
const dependants: EntityDependantViews = new Map(Object.values(model.entities).map(it => [it.name, new Set()]))
|
|
6
8
|
for (const entity of Object.values(model.entities)) {
|
|
7
9
|
if (!entity.view?.dependencies?.length) {
|
|
8
10
|
continue
|
|
@@ -10,11 +12,32 @@ export const getViewDirectDependants = (model: Model.Schema): ViewDependants =>
|
|
|
10
12
|
for (const dependency of entity.view.dependencies) {
|
|
11
13
|
const entityDependants = dependants.get(dependency)
|
|
12
14
|
if (!entityDependants) {
|
|
13
|
-
|
|
14
|
-
continue
|
|
15
|
+
throw new Error()
|
|
15
16
|
}
|
|
16
17
|
entityDependants.add(entity)
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
return dependants
|
|
20
21
|
}
|
|
22
|
+
|
|
23
|
+
export const cascadeRemoveDependantViews = (model: Model.Schema, entities: Model.Entity[]): Migration.Modification[] => {
|
|
24
|
+
const removed = new Set<string>()
|
|
25
|
+
const dependants = getEntityDependantViews(model)
|
|
26
|
+
const modifications: Migration.Modification[] = []
|
|
27
|
+
const removeCascade = (entity: Model.Entity) => {
|
|
28
|
+
if (removed.has(entity.name)) {
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
removed.add(entity.name)
|
|
32
|
+
for (const dependant of dependants.get(entity.name) ?? []) {
|
|
33
|
+
removeCascade(dependant)
|
|
34
|
+
}
|
|
35
|
+
if (entity.view) {
|
|
36
|
+
modifications.push(removeEntityModification.createModification({ entityName: entity.name }))
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const entity of entities) {
|
|
40
|
+
removeCascade(entity)
|
|
41
|
+
}
|
|
42
|
+
return modifications
|
|
43
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { MigrationBuilder } from '@contember/database-migrations'
|
|
2
2
|
import { SchemaUpdater } from '../utils/schemaUpdateUtils'
|
|
3
|
-
import {
|
|
3
|
+
import { createModificationType, ModificationHandler } from '../ModificationHandler'
|
|
4
4
|
import { applyPatch, Operation } from 'rfc6902'
|
|
5
5
|
import deepCopy from '../../utils/deepCopy'
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
static id = 'patchValidationSchema'
|
|
7
|
+
export class PatchValidationSchemaModificationHandler implements ModificationHandler<PatchValidationSchemaModificationData> {
|
|
9
8
|
constructor(private readonly data: PatchValidationSchemaModificationData) {}
|
|
10
9
|
|
|
11
10
|
public createSql(builder: MigrationBuilder): void {}
|
|
@@ -28,12 +27,13 @@ export const PatchValidationSchemaModification: ModificationHandlerStatic<PatchV
|
|
|
28
27
|
describe() {
|
|
29
28
|
return { message: 'Update validation schema' }
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
static createModification(data: PatchValidationSchemaModificationData) {
|
|
33
|
-
return { modification: this.id, ...data }
|
|
34
|
-
}
|
|
35
30
|
}
|
|
36
31
|
|
|
37
32
|
export interface PatchValidationSchemaModificationData {
|
|
38
33
|
patch: Operation[]
|
|
39
34
|
}
|
|
35
|
+
|
|
36
|
+
export const patchValidationSchemaModification = createModificationType({
|
|
37
|
+
id: 'patchValidationSchema',
|
|
38
|
+
handler: PatchValidationSchemaModificationHandler,
|
|
39
|
+
})
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { MigrationBuilder } from '@contember/database-migrations'
|
|
2
2
|
import { Schema, Validation } from '@contember/schema'
|
|
3
3
|
import { SchemaUpdater } from '../utils/schemaUpdateUtils'
|
|
4
|
-
import {
|
|
4
|
+
import { createModificationType, Differ, ModificationHandler } from '../ModificationHandler'
|
|
5
5
|
import deepEqual from 'fast-deep-equal'
|
|
6
6
|
import { createPatch } from 'rfc6902'
|
|
7
|
-
import {
|
|
7
|
+
import { patchValidationSchemaModification } from './PatchValidationSchemaModification'
|
|
8
8
|
|
|
9
|
-
export
|
|
10
|
-
static id = 'updateValidationSchema'
|
|
9
|
+
export class UpdateValidationSchemaModificationHandler implements ModificationHandler<UpdateValidationSchemaModificationData> {
|
|
11
10
|
constructor(private readonly data: UpdateValidationSchemaModificationData) {}
|
|
12
11
|
|
|
13
12
|
public createSql(builder: MigrationBuilder): void {}
|
|
@@ -23,22 +22,26 @@ export const UpdateValidationSchemaModification: ModificationHandlerStatic<Updat
|
|
|
23
22
|
return { message: 'Update validation schema' }
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface UpdateValidationSchemaModificationData {
|
|
28
|
+
schema: Validation.Schema
|
|
29
|
+
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
export const updateValidationSchemaModification = createModificationType({
|
|
32
|
+
id: 'updateValidationSchema',
|
|
33
|
+
handler: UpdateValidationSchemaModificationHandler,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export class UpdateValidationSchemaDiffer implements Differ {
|
|
37
|
+
createDiff(originalSchema: Schema, updatedSchema: Schema) {
|
|
31
38
|
if (deepEqual(originalSchema.validation, updatedSchema.validation)) {
|
|
32
39
|
return []
|
|
33
40
|
}
|
|
34
41
|
const patch = createPatch(originalSchema.validation, updatedSchema.validation)
|
|
35
42
|
if (patch.length <= 20) {
|
|
36
|
-
return [
|
|
43
|
+
return [patchValidationSchemaModification.createModification({ patch })]
|
|
37
44
|
}
|
|
38
|
-
return [
|
|
45
|
+
return [updateValidationSchemaModification.createModification({ schema: updatedSchema.validation })]
|
|
39
46
|
}
|
|
40
47
|
}
|
|
41
|
-
|
|
42
|
-
export interface UpdateValidationSchemaModificationData {
|
|
43
|
-
schema: Validation.Schema
|
|
44
|
-
}
|
package/src/tsconfig.json
CHANGED
|
@@ -64,9 +64,10 @@ testMigrations('convert one has many to many has many', {
|
|
|
64
64
|
sql: SQL`
|
|
65
65
|
CREATE TABLE "article_categories" (
|
|
66
66
|
"article_id" uuid NOT NULL REFERENCES "article"("id") ON DELETE CASCADE,
|
|
67
|
-
"category_id" uuid NOT NULL REFERENCES "category"("id") ON DELETE CASCADE
|
|
68
|
-
"article_categories_pkey" PRIMARY KEY ("article_id", "category_id")
|
|
67
|
+
"category_id" uuid NOT NULL REFERENCES "category"("id") ON DELETE CASCADE
|
|
69
68
|
);
|
|
69
|
+
ALTER TABLE "article_categories"
|
|
70
|
+
ADD CONSTRAINT "article_categories_pkey" PRIMARY KEY ("article_id", "category_id");
|
|
70
71
|
|
|
71
72
|
CREATE TRIGGER "log_event" AFTER INSERT OR UPDATE OR DELETE
|
|
72
73
|
ON "article_categories" FOR EACH ROW
|
|
@@ -35,3 +35,36 @@ UPDATE "author" SET "name" = $pga$unnamed author$pga$;
|
|
|
35
35
|
SET CONSTRAINTS ALL IMMEDIATE; SET CONSTRAINTS ALL DEFERRED;
|
|
36
36
|
ALTER TABLE "author" ALTER "name" SET NOT NULL;`,
|
|
37
37
|
})
|
|
38
|
+
|
|
39
|
+
testMigrations('create a column with copy value', {
|
|
40
|
+
originalSchema: def.createModel({
|
|
41
|
+
Author: class Author {
|
|
42
|
+
email = def.stringColumn().unique()
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
updatedSchema: def.createModel({
|
|
46
|
+
Author: class Author {
|
|
47
|
+
name = def.stringColumn().notNull()
|
|
48
|
+
email = def.stringColumn().unique()
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
diff: [
|
|
52
|
+
{
|
|
53
|
+
modification: 'createColumn',
|
|
54
|
+
entityName: 'Author',
|
|
55
|
+
field: {
|
|
56
|
+
columnName: 'name',
|
|
57
|
+
name: 'name',
|
|
58
|
+
nullable: false,
|
|
59
|
+
type: Model.ColumnType.String,
|
|
60
|
+
columnType: 'text',
|
|
61
|
+
},
|
|
62
|
+
copyValue: 'email',
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
noDiff: true,
|
|
66
|
+
sql: SQL`ALTER TABLE "author" ADD "name" text;
|
|
67
|
+
UPDATE "author" SET "name" = "email"::text;
|
|
68
|
+
SET CONSTRAINTS ALL IMMEDIATE; SET CONSTRAINTS ALL DEFERRED;
|
|
69
|
+
ALTER TABLE "author" ALTER "name" SET NOT NULL;`,
|
|
70
|
+
})
|
|
@@ -90,9 +90,10 @@ testMigrations('create many has many relation (post with categories)', {
|
|
|
90
90
|
ADD "title" text;
|
|
91
91
|
CREATE TABLE "post_categories" (
|
|
92
92
|
"post_id" uuid NOT NULL REFERENCES "post"("id") ON DELETE CASCADE,
|
|
93
|
-
"category_id" uuid NOT NULL REFERENCES "category"("id") ON DELETE CASCADE
|
|
94
|
-
CONSTRAINT "post_categories_pkey" PRIMARY KEY ("post_id", "category_id")
|
|
93
|
+
"category_id" uuid NOT NULL REFERENCES "category"("id") ON DELETE CASCADE
|
|
95
94
|
);
|
|
95
|
+
ALTER TABLE "post_categories"
|
|
96
|
+
ADD CONSTRAINT "post_categories_pkey" PRIMARY KEY ("post_id", "category_id");
|
|
96
97
|
CREATE TRIGGER "log_event"
|
|
97
98
|
AFTER INSERT OR UPDATE OR DELETE
|
|
98
99
|
ON "post_categories"
|
|
@@ -86,3 +86,73 @@ testMigrations('create view', {
|
|
|
86
86
|
sql: SQL`CREATE VIEW "author_stats" AS SELECT 1;`,
|
|
87
87
|
})
|
|
88
88
|
|
|
89
|
+
|
|
90
|
+
namespace ViewAddRelationOriginalSchema {
|
|
91
|
+
export class Article {
|
|
92
|
+
title = def.stringColumn()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
export class Category {
|
|
97
|
+
name = def.stringColumn()
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
namespace ViewAddRelationUpdateSchema {
|
|
102
|
+
export class Article {
|
|
103
|
+
title = def.stringColumn()
|
|
104
|
+
category = def.manyHasOne(Category)
|
|
105
|
+
stats = def.oneHasOneInverse(ArticleStats, 'article')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export class Category {
|
|
109
|
+
name = def.stringColumn()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@def.View('SELECT 1')
|
|
113
|
+
export class ArticleStats {
|
|
114
|
+
article = def.oneHasOne(Article, 'stats')
|
|
115
|
+
visitCount = def.intColumn()
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
testMigrations('create a relation and a view', {
|
|
121
|
+
originalSchema: def.createModel(ViewAddRelationOriginalSchema), updatedSchema: def.createModel(ViewAddRelationUpdateSchema), diff: [
|
|
122
|
+
{
|
|
123
|
+
modification: 'createRelation',
|
|
124
|
+
entityName: 'Article',
|
|
125
|
+
owningSide: { name: 'category', nullable: true, type: 'ManyHasOne', target: 'Category', joiningColumn: { columnName: 'category_id', onDelete: 'restrict' } },
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
modification: 'createView',
|
|
129
|
+
entity: { name: 'ArticleStats',
|
|
130
|
+
primary: 'id',
|
|
131
|
+
primaryColumn: 'id',
|
|
132
|
+
unique: {},
|
|
133
|
+
indexes: {},
|
|
134
|
+
fields: { id: { name: 'id', columnName: 'id', nullable: false, type: 'Uuid', columnType: 'uuid' },
|
|
135
|
+
article: { name: 'article', inversedBy: 'stats', nullable: true, type: 'OneHasOne', target: 'Article', joiningColumn: { columnName: 'article_id', onDelete: 'restrict' } },
|
|
136
|
+
visitCount: { name: 'visitCount', columnName: 'visit_count', nullable: true, type: 'Integer', columnType: 'integer' } },
|
|
137
|
+
tableName: 'article_stats',
|
|
138
|
+
eventLog: { enabled: true },
|
|
139
|
+
view: { sql: 'SELECT 1' } },
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
modification: 'createRelationInverseSide',
|
|
143
|
+
entityName: 'Article',
|
|
144
|
+
relation: {
|
|
145
|
+
name: 'stats',
|
|
146
|
+
ownedBy: 'article',
|
|
147
|
+
target: 'ArticleStats',
|
|
148
|
+
type: 'OneHasOne',
|
|
149
|
+
nullable: true,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
sql: SQL`ALTER TABLE "article" ADD "category_id" uuid;
|
|
154
|
+
ALTER TABLE "article" ADD CONSTRAINT "fk_article_category_id_703b8b" FOREIGN KEY ("category_id") REFERENCES "category"("id") ON DELETE NO ACTION DEFERRABLE INITIALLY IMMEDIATE;
|
|
155
|
+
CREATE INDEX "article_category_id_index" ON "article" ("category_id");
|
|
156
|
+
CREATE VIEW "article_stats" AS SELECT 1;`,
|
|
157
|
+
})
|
|
158
|
+
|
|
@@ -2,6 +2,8 @@ import { testMigrations } from '../../src/tests'
|
|
|
2
2
|
import { SchemaBuilder } from '@contember/schema-definition'
|
|
3
3
|
import { Model } from '@contember/schema'
|
|
4
4
|
import { SQL } from '../../src/tags'
|
|
5
|
+
import { SchemaDefinition as def } from '@contember/schema-definition'
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
testMigrations('remove relation (many has one)', {
|
|
7
9
|
originalSchema: new SchemaBuilder()
|
|
@@ -128,3 +130,59 @@ testMigrations('remove relation inverse side', {
|
|
|
128
130
|
],
|
|
129
131
|
sql: SQL``,
|
|
130
132
|
})
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
namespace DropIndexOrigSchema {
|
|
136
|
+
|
|
137
|
+
@def.Unique('title', 'author')
|
|
138
|
+
@def.Index('title', 'author')
|
|
139
|
+
export class Article {
|
|
140
|
+
title = def.stringColumn()
|
|
141
|
+
author = def.manyHasOne(Author)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export class Author {
|
|
145
|
+
name = def.stringColumn()
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
namespace DropIndexUpSchema {
|
|
150
|
+
@def.Unique('title', 'author')
|
|
151
|
+
@def.Index('title', 'author')
|
|
152
|
+
export class Article {
|
|
153
|
+
title = def.stringColumn()
|
|
154
|
+
author = def.stringColumn()
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export class Author {
|
|
158
|
+
name = def.stringColumn()
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
testMigrations('test drop index / unique when removing a field', {
|
|
164
|
+
originalSchema: def.createModel(DropIndexOrigSchema),
|
|
165
|
+
updatedSchema: def.createModel(DropIndexUpSchema),
|
|
166
|
+
diff: [{
|
|
167
|
+
modification: 'removeField',
|
|
168
|
+
entityName: 'Article',
|
|
169
|
+
fieldName: 'author',
|
|
170
|
+
}, {
|
|
171
|
+
modification: 'createColumn',
|
|
172
|
+
entityName: 'Article',
|
|
173
|
+
field: { name: 'author', columnName: 'author', nullable: true, type: 'String', columnType: 'text' },
|
|
174
|
+
}, {
|
|
175
|
+
modification: 'createUniqueConstraint',
|
|
176
|
+
entityName: 'Article',
|
|
177
|
+
unique: { name: 'unique_Article_title_author_7157ea', fields: ['title', 'author'] },
|
|
178
|
+
}, {
|
|
179
|
+
modification: 'createIndex',
|
|
180
|
+
entityName: 'Article',
|
|
181
|
+
index: { name: 'idx_Article_title_author_7157ea', fields: ['title', 'author'] },
|
|
182
|
+
}],
|
|
183
|
+
sql: SQL`ALTER TABLE "article" DROP "author_id";
|
|
184
|
+
ALTER TABLE "article" ADD "author" text;
|
|
185
|
+
ALTER TABLE "article" ADD CONSTRAINT "unique_Article_title_author_7157ea" UNIQUE ("title", "author");
|
|
186
|
+
CREATE INDEX "idx_Article_title_author_7157ea" ON "article" ("title", "author");`,
|
|
187
|
+
})
|
|
188
|
+
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { test } from 'vitest'
|
|
2
|
+
import { testGenerateSql } from '../../src/tests'
|
|
3
|
+
import {
|
|
4
|
+
createEntityModification,
|
|
5
|
+
createRelationModification,
|
|
6
|
+
removeFieldModification,
|
|
7
|
+
updateEntityNameModification,
|
|
8
|
+
} from '../../../src'
|
|
9
|
+
import { emptyModelSchema } from '@contember/schema-utils'
|
|
10
|
+
import { Model } from '@contember/schema'
|
|
11
|
+
import { SQL } from '../../src/tags'
|
|
12
|
+
|
|
13
|
+
test('taken fk index name', () => {
|
|
14
|
+
testGenerateSql(emptyModelSchema, [
|
|
15
|
+
createEntityModification.createModification({
|
|
16
|
+
entity: {
|
|
17
|
+
fields: {
|
|
18
|
+
id: {
|
|
19
|
+
columnName: 'id',
|
|
20
|
+
name: 'id',
|
|
21
|
+
nullable: false,
|
|
22
|
+
type: Model.ColumnType.Uuid,
|
|
23
|
+
columnType: 'uuid',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
name: 'Post',
|
|
27
|
+
primary: 'id',
|
|
28
|
+
primaryColumn: 'id',
|
|
29
|
+
tableName: 'post',
|
|
30
|
+
unique: {},
|
|
31
|
+
eventLog: {
|
|
32
|
+
enabled: true,
|
|
33
|
+
},
|
|
34
|
+
indexes: {},
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
createEntityModification.createModification({
|
|
38
|
+
entity: {
|
|
39
|
+
fields: {
|
|
40
|
+
id: {
|
|
41
|
+
columnName: 'id',
|
|
42
|
+
name: 'id',
|
|
43
|
+
nullable: false,
|
|
44
|
+
type: Model.ColumnType.Uuid,
|
|
45
|
+
columnType: 'uuid',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
name: 'Author',
|
|
49
|
+
primary: 'id',
|
|
50
|
+
primaryColumn: 'id',
|
|
51
|
+
tableName: 'author',
|
|
52
|
+
unique: {},
|
|
53
|
+
eventLog: {
|
|
54
|
+
enabled: true,
|
|
55
|
+
},
|
|
56
|
+
indexes: {},
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
createRelationModification.createModification({
|
|
60
|
+
entityName: 'Post',
|
|
61
|
+
owningSide: {
|
|
62
|
+
name: 'author',
|
|
63
|
+
type: Model.RelationType.ManyHasOne,
|
|
64
|
+
target: 'Author',
|
|
65
|
+
joiningColumn: {
|
|
66
|
+
columnName: 'author_id',
|
|
67
|
+
onDelete: Model.OnDelete.cascade,
|
|
68
|
+
},
|
|
69
|
+
nullable: true,
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
}),
|
|
73
|
+
updateEntityNameModification.createModification({
|
|
74
|
+
entityName: 'Post',
|
|
75
|
+
newEntityName: 'Article',
|
|
76
|
+
tableName: 'article',
|
|
77
|
+
}),
|
|
78
|
+
createEntityModification.createModification({
|
|
79
|
+
entity: {
|
|
80
|
+
fields: {
|
|
81
|
+
id: {
|
|
82
|
+
columnName: 'id',
|
|
83
|
+
name: 'id',
|
|
84
|
+
nullable: false,
|
|
85
|
+
type: Model.ColumnType.Uuid,
|
|
86
|
+
columnType: 'uuid',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
name: 'Post',
|
|
90
|
+
primary: 'id',
|
|
91
|
+
primaryColumn: 'id',
|
|
92
|
+
tableName: 'post',
|
|
93
|
+
unique: {},
|
|
94
|
+
eventLog: {
|
|
95
|
+
enabled: true,
|
|
96
|
+
},
|
|
97
|
+
indexes: {},
|
|
98
|
+
},
|
|
99
|
+
}),
|
|
100
|
+
createRelationModification.createModification({
|
|
101
|
+
entityName: 'Post',
|
|
102
|
+
owningSide: {
|
|
103
|
+
name: 'author',
|
|
104
|
+
type: Model.RelationType.ManyHasOne,
|
|
105
|
+
target: 'Author',
|
|
106
|
+
joiningColumn: {
|
|
107
|
+
columnName: 'author_id',
|
|
108
|
+
onDelete: Model.OnDelete.cascade,
|
|
109
|
+
},
|
|
110
|
+
nullable: true,
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
}),
|
|
114
|
+
], SQL`CREATE TABLE "post" (
|
|
115
|
+
"id" uuid PRIMARY KEY NOT NULL
|
|
116
|
+
);
|
|
117
|
+
CREATE TRIGGER "log_event"
|
|
118
|
+
AFTER INSERT OR UPDATE OR DELETE ON "post"
|
|
119
|
+
FOR EACH ROW
|
|
120
|
+
EXECUTE PROCEDURE "system"."trigger_event"($pga$id$pga$);
|
|
121
|
+
CREATE CONSTRAINT TRIGGER "log_event_trx"
|
|
122
|
+
AFTER INSERT OR UPDATE OR DELETE ON "post"
|
|
123
|
+
DEFERRABLE INITIALLY DEFERRED
|
|
124
|
+
FOR EACH ROW
|
|
125
|
+
EXECUTE PROCEDURE "system"."trigger_event_commit"();
|
|
126
|
+
CREATE TABLE "author" (
|
|
127
|
+
"id" uuid PRIMARY KEY NOT NULL
|
|
128
|
+
);
|
|
129
|
+
CREATE TRIGGER "log_event"
|
|
130
|
+
AFTER INSERT OR UPDATE OR DELETE ON "author"
|
|
131
|
+
FOR EACH ROW
|
|
132
|
+
EXECUTE PROCEDURE "system"."trigger_event"($pga$id$pga$);
|
|
133
|
+
CREATE CONSTRAINT TRIGGER "log_event_trx"
|
|
134
|
+
AFTER INSERT OR UPDATE OR DELETE ON "author"
|
|
135
|
+
DEFERRABLE INITIALLY DEFERRED
|
|
136
|
+
FOR EACH ROW
|
|
137
|
+
EXECUTE PROCEDURE "system"."trigger_event_commit"();
|
|
138
|
+
ALTER TABLE "post"
|
|
139
|
+
ADD "author_id" uuid;
|
|
140
|
+
ALTER TABLE "post"
|
|
141
|
+
ADD CONSTRAINT "fk_post_author_id_87ef9a" FOREIGN KEY ("author_id") REFERENCES "author"("id") ON DELETE NO ACTION DEFERRABLE INITIALLY IMMEDIATE;
|
|
142
|
+
CREATE INDEX "post_author_id_index" ON "post" ("author_id");
|
|
143
|
+
ALTER TABLE "post" RENAME TO "article";
|
|
144
|
+
CREATE TABLE "post" (
|
|
145
|
+
"id" uuid PRIMARY KEY NOT NULL
|
|
146
|
+
);
|
|
147
|
+
CREATE TRIGGER "log_event"
|
|
148
|
+
AFTER INSERT OR UPDATE OR DELETE ON "post"
|
|
149
|
+
FOR EACH ROW
|
|
150
|
+
EXECUTE PROCEDURE "system"."trigger_event"($pga$id$pga$);
|
|
151
|
+
CREATE CONSTRAINT TRIGGER "log_event_trx"
|
|
152
|
+
AFTER INSERT OR UPDATE OR DELETE ON "post"
|
|
153
|
+
DEFERRABLE INITIALLY DEFERRED
|
|
154
|
+
FOR EACH ROW
|
|
155
|
+
EXECUTE PROCEDURE "system"."trigger_event_commit"();
|
|
156
|
+
ALTER TABLE "post"
|
|
157
|
+
ADD "author_id" uuid;
|
|
158
|
+
ALTER TABLE "post"
|
|
159
|
+
ADD CONSTRAINT "fk_post_author_id_87ef9a" FOREIGN KEY ("author_id") REFERENCES "author"("id") ON DELETE NO ACTION DEFERRABLE INITIALLY IMMEDIATE;
|
|
160
|
+
CREATE INDEX "post_author_id_index1" ON "post" ("author_id");`)
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
test('taken junction table index name', () => {
|
|
165
|
+
testGenerateSql(emptyModelSchema, [
|
|
166
|
+
createEntityModification.createModification({
|
|
167
|
+
entity: {
|
|
168
|
+
fields: {
|
|
169
|
+
id: {
|
|
170
|
+
columnName: 'id',
|
|
171
|
+
name: 'id',
|
|
172
|
+
nullable: false,
|
|
173
|
+
type: Model.ColumnType.Uuid,
|
|
174
|
+
columnType: 'uuid',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
name: 'Post',
|
|
178
|
+
primary: 'id',
|
|
179
|
+
primaryColumn: 'id',
|
|
180
|
+
tableName: 'post',
|
|
181
|
+
unique: {},
|
|
182
|
+
eventLog: {
|
|
183
|
+
enabled: true,
|
|
184
|
+
},
|
|
185
|
+
indexes: {},
|
|
186
|
+
},
|
|
187
|
+
}),
|
|
188
|
+
createEntityModification.createModification({
|
|
189
|
+
entity: {
|
|
190
|
+
fields: {
|
|
191
|
+
id: {
|
|
192
|
+
columnName: 'id',
|
|
193
|
+
name: 'id',
|
|
194
|
+
nullable: false,
|
|
195
|
+
type: Model.ColumnType.Uuid,
|
|
196
|
+
columnType: 'uuid',
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
name: 'Author',
|
|
200
|
+
primary: 'id',
|
|
201
|
+
primaryColumn: 'id',
|
|
202
|
+
tableName: 'author',
|
|
203
|
+
unique: {},
|
|
204
|
+
eventLog: {
|
|
205
|
+
enabled: true,
|
|
206
|
+
},
|
|
207
|
+
indexes: {},
|
|
208
|
+
},
|
|
209
|
+
}),
|
|
210
|
+
createRelationModification.createModification({
|
|
211
|
+
entityName: 'Post',
|
|
212
|
+
owningSide: {
|
|
213
|
+
name: 'authors',
|
|
214
|
+
type: Model.RelationType.ManyHasMany,
|
|
215
|
+
target: 'Author',
|
|
216
|
+
joiningTable: {
|
|
217
|
+
tableName: 'post_authors',
|
|
218
|
+
joiningColumn: {
|
|
219
|
+
columnName: 'post_id',
|
|
220
|
+
onDelete: Model.OnDelete.cascade,
|
|
221
|
+
},
|
|
222
|
+
inverseJoiningColumn: {
|
|
223
|
+
columnName: 'author_id',
|
|
224
|
+
onDelete: Model.OnDelete.cascade,
|
|
225
|
+
},
|
|
226
|
+
eventLog: {
|
|
227
|
+
enabled: true,
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
}),
|
|
232
|
+
removeFieldModification.createModification({
|
|
233
|
+
entityName: 'Post',
|
|
234
|
+
fieldName: 'authors',
|
|
235
|
+
}),
|
|
236
|
+
createRelationModification.createModification({
|
|
237
|
+
entityName: 'Post',
|
|
238
|
+
owningSide: {
|
|
239
|
+
name: 'authors',
|
|
240
|
+
type: Model.RelationType.ManyHasMany,
|
|
241
|
+
target: 'Author',
|
|
242
|
+
joiningTable: {
|
|
243
|
+
tableName: 'post_authors',
|
|
244
|
+
joiningColumn: {
|
|
245
|
+
columnName: 'post_id',
|
|
246
|
+
onDelete: Model.OnDelete.cascade,
|
|
247
|
+
},
|
|
248
|
+
inverseJoiningColumn: {
|
|
249
|
+
columnName: 'author_id',
|
|
250
|
+
onDelete: Model.OnDelete.cascade,
|
|
251
|
+
},
|
|
252
|
+
eventLog: {
|
|
253
|
+
enabled: true,
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
}),
|
|
258
|
+
], SQL`CREATE TABLE "post" (
|
|
259
|
+
"id" uuid PRIMARY KEY NOT NULL
|
|
260
|
+
);
|
|
261
|
+
CREATE TRIGGER "log_event"
|
|
262
|
+
AFTER INSERT OR UPDATE OR DELETE ON "post"
|
|
263
|
+
FOR EACH ROW
|
|
264
|
+
EXECUTE PROCEDURE "system"."trigger_event"($pga$id$pga$);
|
|
265
|
+
CREATE CONSTRAINT TRIGGER "log_event_trx"
|
|
266
|
+
AFTER INSERT OR UPDATE OR DELETE ON "post"
|
|
267
|
+
DEFERRABLE INITIALLY DEFERRED
|
|
268
|
+
FOR EACH ROW
|
|
269
|
+
EXECUTE PROCEDURE "system"."trigger_event_commit"();
|
|
270
|
+
CREATE TABLE "author" (
|
|
271
|
+
"id" uuid PRIMARY KEY NOT NULL
|
|
272
|
+
);
|
|
273
|
+
CREATE TRIGGER "log_event"
|
|
274
|
+
AFTER INSERT OR UPDATE OR DELETE ON "author"
|
|
275
|
+
FOR EACH ROW
|
|
276
|
+
EXECUTE PROCEDURE "system"."trigger_event"($pga$id$pga$);
|
|
277
|
+
CREATE CONSTRAINT TRIGGER "log_event_trx"
|
|
278
|
+
AFTER INSERT OR UPDATE OR DELETE ON "author"
|
|
279
|
+
DEFERRABLE INITIALLY DEFERRED
|
|
280
|
+
FOR EACH ROW
|
|
281
|
+
EXECUTE PROCEDURE "system"."trigger_event_commit"();
|
|
282
|
+
CREATE TABLE "post_authors" (
|
|
283
|
+
"post_id" uuid NOT NULL REFERENCES "post"("id") ON DELETE CASCADE,
|
|
284
|
+
"author_id" uuid NOT NULL REFERENCES "author"("id") ON DELETE CASCADE
|
|
285
|
+
);
|
|
286
|
+
ALTER TABLE "post_authors"
|
|
287
|
+
ADD CONSTRAINT "post_authors_pkey" PRIMARY KEY ("post_id", "author_id");
|
|
288
|
+
CREATE TRIGGER "log_event"
|
|
289
|
+
AFTER INSERT OR UPDATE OR DELETE ON "post_authors"
|
|
290
|
+
FOR EACH ROW
|
|
291
|
+
EXECUTE PROCEDURE "system"."trigger_event"($pga$post_id$pga$, $pga$author_id$pga$);
|
|
292
|
+
CREATE CONSTRAINT TRIGGER "log_event_trx"
|
|
293
|
+
AFTER INSERT OR UPDATE OR DELETE ON "post_authors"
|
|
294
|
+
DEFERRABLE INITIALLY DEFERRED
|
|
295
|
+
FOR EACH ROW
|
|
296
|
+
EXECUTE PROCEDURE "system"."trigger_event_commit"();
|
|
297
|
+
DROP TABLE "post_authors";
|
|
298
|
+
CREATE TABLE "post_authors" (
|
|
299
|
+
"post_id" uuid NOT NULL REFERENCES "post"("id") ON DELETE CASCADE,
|
|
300
|
+
"author_id" uuid NOT NULL REFERENCES "author"("id") ON DELETE CASCADE
|
|
301
|
+
);
|
|
302
|
+
ALTER TABLE "post_authors"
|
|
303
|
+
ADD CONSTRAINT "post_authors_pkey1" PRIMARY KEY ("post_id", "author_id");
|
|
304
|
+
CREATE TRIGGER "log_event"
|
|
305
|
+
AFTER INSERT OR UPDATE OR DELETE ON "post_authors"
|
|
306
|
+
FOR EACH ROW
|
|
307
|
+
EXECUTE PROCEDURE "system"."trigger_event"($pga$post_id$pga$, $pga$author_id$pga$);
|
|
308
|
+
CREATE CONSTRAINT TRIGGER "log_event_trx"
|
|
309
|
+
AFTER INSERT OR UPDATE OR DELETE ON "post_authors"
|
|
310
|
+
DEFERRABLE INITIALLY DEFERRED
|
|
311
|
+
FOR EACH ROW
|
|
312
|
+
EXECUTE PROCEDURE "system"."trigger_event_commit"();
|
|
313
|
+
`)
|
|
314
|
+
})
|