@contember/schema-migrations 2.0.0-beta.2 → 2.0.0-beta.4

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.
Files changed (41) hide show
  1. package/dist/development/index.cjs +1 -0
  2. package/dist/development/index.cjs.map +1 -1
  3. package/dist/development/index.js +2 -1
  4. package/dist/development/src/modifications/ModificationVersions.cjs +3 -1
  5. package/dist/development/src/modifications/ModificationVersions.cjs.map +1 -1
  6. package/dist/development/src/modifications/ModificationVersions.js +3 -1
  7. package/dist/development/src/modifications/ModificationVersions.js.map +1 -1
  8. package/dist/development/src/modifications/entities/CreateEntityModification.cjs +3 -1
  9. package/dist/development/src/modifications/entities/CreateEntityModification.cjs.map +1 -1
  10. package/dist/development/src/modifications/entities/CreateEntityModification.js +3 -1
  11. package/dist/development/src/modifications/entities/CreateEntityModification.js.map +1 -1
  12. package/dist/development/src/modifications/utils/schemaUpdateUtils.cjs +3 -2
  13. package/dist/development/src/modifications/utils/schemaUpdateUtils.cjs.map +1 -1
  14. package/dist/development/src/modifications/utils/schemaUpdateUtils.js +3 -2
  15. package/dist/development/src/modifications/utils/schemaUpdateUtils.js.map +1 -1
  16. package/dist/production/index.cjs +1 -0
  17. package/dist/production/index.cjs.map +1 -1
  18. package/dist/production/index.js +2 -1
  19. package/dist/production/src/modifications/ModificationVersions.cjs +3 -1
  20. package/dist/production/src/modifications/ModificationVersions.cjs.map +1 -1
  21. package/dist/production/src/modifications/ModificationVersions.js +3 -1
  22. package/dist/production/src/modifications/ModificationVersions.js.map +1 -1
  23. package/dist/production/src/modifications/entities/CreateEntityModification.cjs +3 -1
  24. package/dist/production/src/modifications/entities/CreateEntityModification.cjs.map +1 -1
  25. package/dist/production/src/modifications/entities/CreateEntityModification.js +3 -1
  26. package/dist/production/src/modifications/entities/CreateEntityModification.js.map +1 -1
  27. package/dist/production/src/modifications/utils/schemaUpdateUtils.cjs +3 -2
  28. package/dist/production/src/modifications/utils/schemaUpdateUtils.cjs.map +1 -1
  29. package/dist/production/src/modifications/utils/schemaUpdateUtils.js +3 -2
  30. package/dist/production/src/modifications/utils/schemaUpdateUtils.js.map +1 -1
  31. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  32. package/dist/types/modifications/ModificationVersions.d.ts +2 -1
  33. package/dist/types/modifications/ModificationVersions.d.ts.map +1 -1
  34. package/dist/types/modifications/entities/CreateEntityModification.d.ts.map +1 -1
  35. package/dist/types/modifications/utils/schemaUpdateUtils.d.ts.map +1 -1
  36. package/dist/types/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +7 -7
  38. package/src/modifications/ModificationVersions.ts +2 -1
  39. package/src/modifications/entities/CreateEntityModification.ts +5 -1
  40. package/src/modifications/utils/schemaUpdateUtils.ts +2 -1
  41. package/tests/cases/integration/createEntity.test.ts +51 -0
@@ -146,6 +146,7 @@ Object.defineProperty(exports, "ModificationHandlerFactory", {
146
146
  get: () => ModificationHandlerFactory.ModificationHandlerFactory
147
147
  });
148
148
  exports.VERSION_ACL_PATCH = ModificationVersions.VERSION_ACL_PATCH;
149
+ exports.VERSION_CORRECT_PRIMARY_COLUMN_NAME = ModificationVersions.VERSION_CORRECT_PRIMARY_COLUMN_NAME;
149
150
  exports.VERSION_INITIAL = ModificationVersions.VERSION_INITIAL;
150
151
  exports.VERSION_LATEST = ModificationVersions.VERSION_LATEST;
151
152
  exports.VERSION_REMOVE_REFERENCING_RELATIONS = ModificationVersions.VERSION_REMOVE_REFERENCING_RELATIONS;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -36,7 +36,7 @@ import { UpdateRelationOrderByDiffer, UpdateRelationOrderByModificationHandler,
36
36
  import { PatchValidationSchemaModificationHandler, patchValidationSchemaModification } from "./src/modifications/validation/PatchValidationSchemaModification.js";
37
37
  import { UpdateValidationSchemaDiffer, UpdateValidationSchemaModificationHandler, updateValidationSchemaModification } from "./src/modifications/validation/UpdateValidationSchemaModification.js";
38
38
  import { ModificationHandlerFactory } from "./src/modifications/ModificationHandlerFactory.js";
39
- import { VERSION_ACL_PATCH, VERSION_INITIAL, VERSION_LATEST, VERSION_REMOVE_REFERENCING_RELATIONS, VERSION_REMOVE_RELATION_INVERSE_SIDE, VERSION_UPDATE_CONSTRAINT_FIELDS, VERSION_UPDATE_INDEX_FIELDS, _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE } from "./src/modifications/ModificationVersions.js";
39
+ import { VERSION_ACL_PATCH, VERSION_CORRECT_PRIMARY_COLUMN_NAME, VERSION_INITIAL, VERSION_LATEST, VERSION_REMOVE_REFERENCING_RELATIONS, VERSION_REMOVE_RELATION_INVERSE_SIDE, VERSION_UPDATE_CONSTRAINT_FIELDS, VERSION_UPDATE_INDEX_FIELDS, _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE } from "./src/modifications/ModificationVersions.js";
40
40
  import { createModificationType, emptyModificationDescriptionContext } from "./src/modifications/ModificationHandler.js";
41
41
  import { SchemaUpdateError } from "./src/modifications/exceptions.js";
42
42
  import { createEventTrigger, createEventTrxTrigger, dropEventTrigger, dropEventTrxTrigger } from "./src/modifications/utils/sqlUpdateUtils.js";
@@ -110,6 +110,7 @@ export {
110
110
  UpdateValidationSchemaDiffer,
111
111
  UpdateValidationSchemaModificationHandler,
112
112
  VERSION_ACL_PATCH,
113
+ VERSION_CORRECT_PRIMARY_COLUMN_NAME,
113
114
  VERSION_INITIAL,
114
115
  VERSION_LATEST,
115
116
  VERSION_REMOVE_REFERENCING_RELATIONS,
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const VERSION_INITIAL = 1;
4
- const VERSION_LATEST = 5;
4
+ const VERSION_LATEST = 6;
5
5
  const VERSION_ACL_PATCH = 2;
6
6
  const VERSION_UPDATE_CONSTRAINT_FIELDS = 2;
7
7
  const VERSION_REMOVE_RELATION_INVERSE_SIDE = 3;
8
8
  const VERSION_REMOVE_REFERENCING_RELATIONS = 3;
9
9
  const _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE = 4;
10
10
  const VERSION_UPDATE_INDEX_FIELDS = 5;
11
+ const VERSION_CORRECT_PRIMARY_COLUMN_NAME = 6;
11
12
  exports.VERSION_ACL_PATCH = VERSION_ACL_PATCH;
13
+ exports.VERSION_CORRECT_PRIMARY_COLUMN_NAME = VERSION_CORRECT_PRIMARY_COLUMN_NAME;
12
14
  exports.VERSION_INITIAL = VERSION_INITIAL;
13
15
  exports.VERSION_LATEST = VERSION_LATEST;
14
16
  exports.VERSION_REMOVE_REFERENCING_RELATIONS = VERSION_REMOVE_REFERENCING_RELATIONS;
@@ -1 +1 @@
1
- {"version":3,"file":"ModificationVersions.cjs","sources":["../../../../../packages/schema-migrations/src/modifications/ModificationVersions.ts"],"sourcesContent":["export const VERSION_INITIAL = 1\nexport const VERSION_LATEST = 5\n\nexport const VERSION_ACL_PATCH = 2\nexport const VERSION_UPDATE_CONSTRAINT_FIELDS = 2\nexport const VERSION_REMOVE_RELATION_INVERSE_SIDE = 3\nexport const VERSION_REMOVE_REFERENCING_RELATIONS = 3\nexport const _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE = 4\nexport const VERSION_UPDATE_INDEX_FIELDS = 5\n"],"names":[],"mappings":";;AAAO,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAEvB,MAAM,oBAAoB;AAC1B,MAAM,mCAAmC;AACzC,MAAM,uCAAuC;AAC7C,MAAM,uCAAuC;AAC7C,MAAM,sDAAsD;AAC5D,MAAM,8BAA8B;;;;;;;;;"}
1
+ {"version":3,"file":"ModificationVersions.cjs","sources":["../../../../../packages/schema-migrations/src/modifications/ModificationVersions.ts"],"sourcesContent":["export const VERSION_INITIAL = 1\nexport const VERSION_LATEST = 6\n\nexport const VERSION_ACL_PATCH = 2\nexport const VERSION_UPDATE_CONSTRAINT_FIELDS = 2\nexport const VERSION_REMOVE_RELATION_INVERSE_SIDE = 3\nexport const VERSION_REMOVE_REFERENCING_RELATIONS = 3\nexport const _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE = 4\nexport const VERSION_UPDATE_INDEX_FIELDS = 5\nexport const VERSION_CORRECT_PRIMARY_COLUMN_NAME = 6\n"],"names":[],"mappings":";;AAAO,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAEvB,MAAM,oBAAoB;AAC1B,MAAM,mCAAmC;AACzC,MAAM,uCAAuC;AAC7C,MAAM,uCAAuC;AAC7C,MAAM,sDAAsD;AAC5D,MAAM,8BAA8B;AACpC,MAAM,sCAAsC;;;;;;;;;;"}
@@ -1,13 +1,15 @@
1
1
  const VERSION_INITIAL = 1;
2
- const VERSION_LATEST = 5;
2
+ const VERSION_LATEST = 6;
3
3
  const VERSION_ACL_PATCH = 2;
4
4
  const VERSION_UPDATE_CONSTRAINT_FIELDS = 2;
5
5
  const VERSION_REMOVE_RELATION_INVERSE_SIDE = 3;
6
6
  const VERSION_REMOVE_REFERENCING_RELATIONS = 3;
7
7
  const _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE = 4;
8
8
  const VERSION_UPDATE_INDEX_FIELDS = 5;
9
+ const VERSION_CORRECT_PRIMARY_COLUMN_NAME = 6;
9
10
  export {
10
11
  VERSION_ACL_PATCH,
12
+ VERSION_CORRECT_PRIMARY_COLUMN_NAME,
11
13
  VERSION_INITIAL,
12
14
  VERSION_LATEST,
13
15
  VERSION_REMOVE_REFERENCING_RELATIONS,
@@ -1 +1 @@
1
- {"version":3,"file":"ModificationVersions.js","sources":["../../../../../packages/schema-migrations/src/modifications/ModificationVersions.ts"],"sourcesContent":["export const VERSION_INITIAL = 1\nexport const VERSION_LATEST = 5\n\nexport const VERSION_ACL_PATCH = 2\nexport const VERSION_UPDATE_CONSTRAINT_FIELDS = 2\nexport const VERSION_REMOVE_RELATION_INVERSE_SIDE = 3\nexport const VERSION_REMOVE_REFERENCING_RELATIONS = 3\nexport const _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE = 4\nexport const VERSION_UPDATE_INDEX_FIELDS = 5\n"],"names":[],"mappings":"AAAO,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAEvB,MAAM,oBAAoB;AAC1B,MAAM,mCAAmC;AACzC,MAAM,uCAAuC;AAC7C,MAAM,uCAAuC;AAC7C,MAAM,sDAAsD;AAC5D,MAAM,8BAA8B;"}
1
+ {"version":3,"file":"ModificationVersions.js","sources":["../../../../../packages/schema-migrations/src/modifications/ModificationVersions.ts"],"sourcesContent":["export const VERSION_INITIAL = 1\nexport const VERSION_LATEST = 6\n\nexport const VERSION_ACL_PATCH = 2\nexport const VERSION_UPDATE_CONSTRAINT_FIELDS = 2\nexport const VERSION_REMOVE_RELATION_INVERSE_SIDE = 3\nexport const VERSION_REMOVE_REFERENCING_RELATIONS = 3\nexport const _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE = 4\nexport const VERSION_UPDATE_INDEX_FIELDS = 5\nexport const VERSION_CORRECT_PRIMARY_COLUMN_NAME = 6\n"],"names":[],"mappings":"AAAO,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAEvB,MAAM,oBAAoB;AAC1B,MAAM,mCAAmC;AACzC,MAAM,uCAAuC;AAC7C,MAAM,uCAAuC;AAC7C,MAAM,sDAAsD;AAC5D,MAAM,8BAA8B;AACpC,MAAM,sCAAsC;"}
@@ -4,6 +4,7 @@ const schemaUpdateUtils = require("../utils/schemaUpdateUtils.cjs");
4
4
  const ModificationHandler = require("../ModificationHandler.cjs");
5
5
  const sqlUpdateUtils = require("../utils/sqlUpdateUtils.cjs");
6
6
  const columnUtils = require("../utils/columnUtils.cjs");
7
+ const ModificationVersions = require("../ModificationVersions.cjs");
7
8
  class CreateEntityModificationHandler {
8
9
  constructor(data, schema, options) {
9
10
  this.data = data;
@@ -17,8 +18,9 @@ class CreateEntityModificationHandler {
17
18
  return;
18
19
  }
19
20
  const primaryColumn = entity.fields[entity.primary];
21
+ const primaryColumnName = this.options.formatVersion >= ModificationVersions.VERSION_CORRECT_PRIMARY_COLUMN_NAME ? primaryColumn.columnName : primaryColumn.name;
20
22
  builder.createTable(entity.tableName, {
21
- [primaryColumn.name]: {
23
+ [primaryColumnName]: {
22
24
  primaryKey: true,
23
25
  type: columnUtils.getColumnSqlType(primaryColumn),
24
26
  notNull: true,
@@ -1 +1 @@
1
- {"version":3,"file":"CreateEntityModification.cjs","sources":["../../../../../../packages/schema-migrations/src/modifications/entities/CreateEntityModification.ts"],"sourcesContent":["import { MigrationBuilder } from '@contember/database-migrations'\nimport { Model, Schema } from '@contember/schema'\nimport { SchemaUpdater, updateModel } from '../utils/schemaUpdateUtils'\nimport {\n\tcreateModificationType,\n\tDiffer,\n\tModificationHandler, ModificationHandlerCreateSqlOptions,\n\tModificationHandlerOptions,\n} from '../ModificationHandler'\nimport { createEventTrigger, createEventTrxTrigger } from '../utils/sqlUpdateUtils'\nimport { PossibleEntityShapeInMigrations } from '../../utils/PartialEntity.js'\nimport { getColumnSqlType } from '../utils/columnUtils'\n\nexport class CreateEntityModificationHandler implements ModificationHandler<CreateEntityModificationData> {\n\tconstructor(\n\t\tprivate readonly data: CreateEntityModificationData,\n\t\tprivate readonly schema: Schema,\n\t\tprivate readonly options: ModificationHandlerOptions,\n\t) {}\n\n\tpublic createSql(builder: MigrationBuilder, { systemSchema }: ModificationHandlerCreateSqlOptions): void {\n\t\tconst entity = this.data.entity\n\t\tif (entity.view) {\n\t\t\t// BC\n\t\t\tbuilder.createView(entity.tableName, {}, entity.view.sql)\n\t\t\treturn\n\t\t}\n\t\tconst primaryColumn = entity.fields[entity.primary] as Model.AnyColumn\n\n\t\tbuilder.createTable(entity.tableName, {\n\t\t\t[primaryColumn.name]: {\n\t\t\t\tprimaryKey: true,\n\t\t\t\ttype: getColumnSqlType(primaryColumn),\n\t\t\t\tnotNull: true,\n\t\t\t\tsequenceGenerated: primaryColumn.sequence,\n\t\t\t},\n\t\t})\n\n\t\tif (entity.eventLog?.enabled !== false) {\n\t\t\tcreateEventTrigger(builder, systemSchema, entity.tableName, [entity.primaryColumn])\n\t\t\tcreateEventTrxTrigger(builder, systemSchema, entity.tableName)\n\t\t}\n\t}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn updateModel(({ model }) => ({\n\t\t\t...model,\n\t\t\tentities: {\n\t\t\t\t...model.entities,\n\t\t\t\t[this.data.entity.name]: {\n\t\t\t\t\teventLog: { enabled: true },\n\t\t\t\t\t...this.data.entity,\n\t\t\t\t\tunique: Object.values(this.data.entity.unique),\n\t\t\t\t\tindexes: Object.values(this.data.entity.indexes ?? []),\n\t\t\t\t},\n\t\t\t},\n\t\t}))\n\t}\n\n\n\tdescribe() {\n\t\treturn { message: `Add entity ${this.data.entity.name}` }\n\t}\n\n}\n\nexport const createEntityModification = createModificationType({\n\tid: 'createEntity',\n\thandler: CreateEntityModificationHandler,\n})\n\nexport class CreateEntityDiffer implements Differ {\n\tcreateDiff(originalSchema: Schema, updatedSchema: Schema) {\n\t\treturn Object.values(updatedSchema.model.entities)\n\t\t\t.filter(it => !originalSchema.model.entities[it.name])\n\t\t\t.filter(it => !it.view)\n\t\t\t.map(entity =>\n\t\t\t\tcreateEntityModification.createModification({\n\t\t\t\t\tentity: {\n\t\t\t\t\t\t...entity,\n\t\t\t\t\t\tfields: {\n\t\t\t\t\t\t\t[entity.primary]: entity.fields[entity.primary],\n\t\t\t\t\t\t},\n\t\t\t\t\t\tunique: [],\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t)\n\t}\n}\n\nexport interface CreateEntityModificationData {\n\tentity: PossibleEntityShapeInMigrations\n}\n"],"names":["getColumnSqlType","createEventTrigger","createEventTrxTrigger","updateModel","createModificationType"],"mappings":";;;;;;AAaO,MAAM,gCAA6F;AAAA,EACzG,YACkB,MACA,QACA,SAChB;AAHgB,SAAA,OAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AAAA,EAAA;AAAA,EAGX,UAAU,SAA2B,EAAE,gBAA2D;AAClG,UAAA,SAAS,KAAK,KAAK;AACzB,QAAI,OAAO,MAAM;AAEhB,cAAQ,WAAW,OAAO,WAAW,CAAA,GAAI,OAAO,KAAK,GAAG;AACxD;AAAA,IAAA;AAED,UAAM,gBAAgB,OAAO,OAAO,OAAO,OAAO;AAE1C,YAAA,YAAY,OAAO,WAAW;AAAA,MACrC,CAAC,cAAc,IAAI,GAAG;AAAA,QACrB,YAAY;AAAA,QACZ,MAAMA,6BAAiB,aAAa;AAAA,QACpC,SAAS;AAAA,QACT,mBAAmB,cAAc;AAAA,MAAA;AAAA,IAClC,CACA;AAEI,QAAA,OAAO,UAAU,YAAY,OAAO;AACxCC,qBAAA,mBAAmB,SAAS,cAAc,OAAO,WAAW,CAAC,OAAO,aAAa,CAAC;AAC5DC,qBAAAA,sBAAA,SAAS,cAAc,OAAO,SAAS;AAAA,IAAA;AAAA,EAC9D;AAAA,EAGM,mBAAkC;AACxC,WAAOC,kBAAY,YAAA,CAAC,EAAE,aAAa;AAAA,MAClC,GAAG;AAAA,MACH,UAAU;AAAA,QACT,GAAG,MAAM;AAAA,QACT,CAAC,KAAK,KAAK,OAAO,IAAI,GAAG;AAAA,UACxB,UAAU,EAAE,SAAS,KAAK;AAAA,UAC1B,GAAG,KAAK,KAAK;AAAA,UACb,QAAQ,OAAO,OAAO,KAAK,KAAK,OAAO,MAAM;AAAA,UAC7C,SAAS,OAAO,OAAO,KAAK,KAAK,OAAO,WAAW,CAAE,CAAA;AAAA,QAAA;AAAA,MACtD;AAAA,IACD,EACC;AAAA,EAAA;AAAA,EAIH,WAAW;AACV,WAAO,EAAE,SAAS,cAAc,KAAK,KAAK,OAAO,IAAI,GAAG;AAAA,EAAA;AAG1D;AAEO,MAAM,2BAA2BC,oBAAAA,uBAAuB;AAAA,EAC9D,IAAI;AAAA,EACJ,SAAS;AACV,CAAC;AAEM,MAAM,mBAAqC;AAAA,EACjD,WAAW,gBAAwB,eAAuB;AAClD,WAAA,OAAO,OAAO,cAAc,MAAM,QAAQ,EAC/C,OAAO,QAAM,CAAC,eAAe,MAAM,SAAS,GAAG,IAAI,CAAC,EACpD,OAAO,CAAM,OAAA,CAAC,GAAG,IAAI,EACrB;AAAA,MAAI,CAAA,WACJ,yBAAyB,mBAAmB;AAAA,QAC3C,QAAQ;AAAA,UACP,GAAG;AAAA,UACH,QAAQ;AAAA,YACP,CAAC,OAAO,OAAO,GAAG,OAAO,OAAO,OAAO,OAAO;AAAA,UAC/C;AAAA,UACA,QAAQ,CAAA;AAAA,QAAC;AAAA,MAEV,CAAA;AAAA,IACF;AAAA,EAAA;AAEH;;;;"}
1
+ {"version":3,"file":"CreateEntityModification.cjs","sources":["../../../../../../packages/schema-migrations/src/modifications/entities/CreateEntityModification.ts"],"sourcesContent":["import { MigrationBuilder } from '@contember/database-migrations'\nimport { Model, Schema } from '@contember/schema'\nimport { SchemaUpdater, updateModel } from '../utils/schemaUpdateUtils'\nimport {\n\tcreateModificationType,\n\tDiffer,\n\tModificationHandler, ModificationHandlerCreateSqlOptions,\n\tModificationHandlerOptions,\n} from '../ModificationHandler'\nimport { createEventTrigger, createEventTrxTrigger } from '../utils/sqlUpdateUtils'\nimport { PossibleEntityShapeInMigrations } from '../../utils/PartialEntity.js'\nimport { getColumnSqlType } from '../utils/columnUtils'\nimport { VERSION_CORRECT_PRIMARY_COLUMN_NAME } from '../ModificationVersions'\n\nexport class CreateEntityModificationHandler implements ModificationHandler<CreateEntityModificationData> {\n\tconstructor(\n\t\tprivate readonly data: CreateEntityModificationData,\n\t\tprivate readonly schema: Schema,\n\t\tprivate readonly options: ModificationHandlerOptions,\n\t) {}\n\n\tpublic createSql(builder: MigrationBuilder, { systemSchema }: ModificationHandlerCreateSqlOptions): void {\n\t\tconst entity = this.data.entity\n\t\tif (entity.view) {\n\t\t\t// BC\n\t\t\tbuilder.createView(entity.tableName, {}, entity.view.sql)\n\t\t\treturn\n\t\t}\n\t\tconst primaryColumn = entity.fields[entity.primary] as Model.AnyColumn\n\n\t\tconst primaryColumnName = this.options.formatVersion >= VERSION_CORRECT_PRIMARY_COLUMN_NAME\n\t\t\t? primaryColumn.columnName\n\t\t\t: primaryColumn.name\n\t\tbuilder.createTable(entity.tableName, {\n\t\t\t[primaryColumnName]: {\n\t\t\t\tprimaryKey: true,\n\t\t\t\ttype: getColumnSqlType(primaryColumn),\n\t\t\t\tnotNull: true,\n\t\t\t\tsequenceGenerated: primaryColumn.sequence,\n\t\t\t},\n\t\t})\n\n\t\tif (entity.eventLog?.enabled !== false) {\n\t\t\tcreateEventTrigger(builder, systemSchema, entity.tableName, [entity.primaryColumn])\n\t\t\tcreateEventTrxTrigger(builder, systemSchema, entity.tableName)\n\t\t}\n\t}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn updateModel(({ model }) => ({\n\t\t\t...model,\n\t\t\tentities: {\n\t\t\t\t...model.entities,\n\t\t\t\t[this.data.entity.name]: {\n\t\t\t\t\teventLog: { enabled: true },\n\t\t\t\t\t...this.data.entity,\n\t\t\t\t\tunique: Object.values(this.data.entity.unique),\n\t\t\t\t\tindexes: Object.values(this.data.entity.indexes ?? []),\n\t\t\t\t},\n\t\t\t},\n\t\t}))\n\t}\n\n\n\tdescribe() {\n\t\treturn { message: `Add entity ${this.data.entity.name}` }\n\t}\n\n}\n\nexport const createEntityModification = createModificationType({\n\tid: 'createEntity',\n\thandler: CreateEntityModificationHandler,\n})\n\nexport class CreateEntityDiffer implements Differ {\n\tcreateDiff(originalSchema: Schema, updatedSchema: Schema) {\n\t\treturn Object.values(updatedSchema.model.entities)\n\t\t\t.filter(it => !originalSchema.model.entities[it.name])\n\t\t\t.filter(it => !it.view)\n\t\t\t.map(entity =>\n\t\t\t\tcreateEntityModification.createModification({\n\t\t\t\t\tentity: {\n\t\t\t\t\t\t...entity,\n\t\t\t\t\t\tfields: {\n\t\t\t\t\t\t\t[entity.primary]: entity.fields[entity.primary],\n\t\t\t\t\t\t},\n\t\t\t\t\t\tunique: [],\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t)\n\t}\n}\n\nexport interface CreateEntityModificationData {\n\tentity: PossibleEntityShapeInMigrations\n}\n"],"names":["VERSION_CORRECT_PRIMARY_COLUMN_NAME","getColumnSqlType","createEventTrigger","createEventTrxTrigger","updateModel","createModificationType"],"mappings":";;;;;;;AAcO,MAAM,gCAA6F;AAAA,EACzG,YACkB,MACA,QACA,SAChB;AAHgB,SAAA,OAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AAAA,EAAA;AAAA,EAGX,UAAU,SAA2B,EAAE,gBAA2D;AAClG,UAAA,SAAS,KAAK,KAAK;AACzB,QAAI,OAAO,MAAM;AAEhB,cAAQ,WAAW,OAAO,WAAW,CAAA,GAAI,OAAO,KAAK,GAAG;AACxD;AAAA,IAAA;AAED,UAAM,gBAAgB,OAAO,OAAO,OAAO,OAAO;AAElD,UAAM,oBAAoB,KAAK,QAAQ,iBAAiBA,qBAAAA,sCACrD,cAAc,aACd,cAAc;AACT,YAAA,YAAY,OAAO,WAAW;AAAA,MACrC,CAAC,iBAAiB,GAAG;AAAA,QACp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OAAO,OAAO,OAAO;AAAA,UAC/C;AAAA,UACA,QAAQ,CAAA;AAAA,QAAC;AAAA,MAEV,CAAA;AAAA,IACF;AAAA,EAAA;AAEH;;;;"}
@@ -2,6 +2,7 @@ import { updateModel } from "../utils/schemaUpdateUtils.js";
2
2
  import { createModificationType } from "../ModificationHandler.js";
3
3
  import { createEventTrigger, createEventTrxTrigger } from "../utils/sqlUpdateUtils.js";
4
4
  import { getColumnSqlType } from "../utils/columnUtils.js";
5
+ import { VERSION_CORRECT_PRIMARY_COLUMN_NAME } from "../ModificationVersions.js";
5
6
  class CreateEntityModificationHandler {
6
7
  constructor(data, schema, options) {
7
8
  this.data = data;
@@ -15,8 +16,9 @@ class CreateEntityModificationHandler {
15
16
  return;
16
17
  }
17
18
  const primaryColumn = entity.fields[entity.primary];
19
+ const primaryColumnName = this.options.formatVersion >= VERSION_CORRECT_PRIMARY_COLUMN_NAME ? primaryColumn.columnName : primaryColumn.name;
18
20
  builder.createTable(entity.tableName, {
19
- [primaryColumn.name]: {
21
+ [primaryColumnName]: {
20
22
  primaryKey: true,
21
23
  type: getColumnSqlType(primaryColumn),
22
24
  notNull: true,
@@ -1 +1 @@
1
- {"version":3,"file":"CreateEntityModification.js","sources":["../../../../../../packages/schema-migrations/src/modifications/entities/CreateEntityModification.ts"],"sourcesContent":["import { MigrationBuilder } from '@contember/database-migrations'\nimport { Model, Schema } from '@contember/schema'\nimport { SchemaUpdater, updateModel } from '../utils/schemaUpdateUtils'\nimport {\n\tcreateModificationType,\n\tDiffer,\n\tModificationHandler, ModificationHandlerCreateSqlOptions,\n\tModificationHandlerOptions,\n} from '../ModificationHandler'\nimport { createEventTrigger, createEventTrxTrigger } from '../utils/sqlUpdateUtils'\nimport { PossibleEntityShapeInMigrations } from '../../utils/PartialEntity.js'\nimport { getColumnSqlType } from '../utils/columnUtils'\n\nexport class CreateEntityModificationHandler implements ModificationHandler<CreateEntityModificationData> {\n\tconstructor(\n\t\tprivate readonly data: CreateEntityModificationData,\n\t\tprivate readonly schema: Schema,\n\t\tprivate readonly options: ModificationHandlerOptions,\n\t) {}\n\n\tpublic createSql(builder: MigrationBuilder, { systemSchema }: ModificationHandlerCreateSqlOptions): void {\n\t\tconst entity = this.data.entity\n\t\tif (entity.view) {\n\t\t\t// BC\n\t\t\tbuilder.createView(entity.tableName, {}, entity.view.sql)\n\t\t\treturn\n\t\t}\n\t\tconst primaryColumn = entity.fields[entity.primary] as Model.AnyColumn\n\n\t\tbuilder.createTable(entity.tableName, {\n\t\t\t[primaryColumn.name]: {\n\t\t\t\tprimaryKey: true,\n\t\t\t\ttype: getColumnSqlType(primaryColumn),\n\t\t\t\tnotNull: true,\n\t\t\t\tsequenceGenerated: primaryColumn.sequence,\n\t\t\t},\n\t\t})\n\n\t\tif (entity.eventLog?.enabled !== false) {\n\t\t\tcreateEventTrigger(builder, systemSchema, entity.tableName, [entity.primaryColumn])\n\t\t\tcreateEventTrxTrigger(builder, systemSchema, entity.tableName)\n\t\t}\n\t}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn updateModel(({ model }) => ({\n\t\t\t...model,\n\t\t\tentities: {\n\t\t\t\t...model.entities,\n\t\t\t\t[this.data.entity.name]: {\n\t\t\t\t\teventLog: { enabled: true },\n\t\t\t\t\t...this.data.entity,\n\t\t\t\t\tunique: Object.values(this.data.entity.unique),\n\t\t\t\t\tindexes: Object.values(this.data.entity.indexes ?? []),\n\t\t\t\t},\n\t\t\t},\n\t\t}))\n\t}\n\n\n\tdescribe() {\n\t\treturn { message: `Add entity ${this.data.entity.name}` }\n\t}\n\n}\n\nexport const createEntityModification = createModificationType({\n\tid: 'createEntity',\n\thandler: CreateEntityModificationHandler,\n})\n\nexport class CreateEntityDiffer implements Differ {\n\tcreateDiff(originalSchema: Schema, updatedSchema: Schema) {\n\t\treturn Object.values(updatedSchema.model.entities)\n\t\t\t.filter(it => !originalSchema.model.entities[it.name])\n\t\t\t.filter(it => !it.view)\n\t\t\t.map(entity =>\n\t\t\t\tcreateEntityModification.createModification({\n\t\t\t\t\tentity: {\n\t\t\t\t\t\t...entity,\n\t\t\t\t\t\tfields: {\n\t\t\t\t\t\t\t[entity.primary]: entity.fields[entity.primary],\n\t\t\t\t\t\t},\n\t\t\t\t\t\tunique: [],\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t)\n\t}\n}\n\nexport interface CreateEntityModificationData {\n\tentity: PossibleEntityShapeInMigrations\n}\n"],"names":[],"mappings":";;;;AAaO,MAAM,gCAA6F;AAAA,EACzG,YACkB,MACA,QACA,SAChB;AAHgB,SAAA,OAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AAAA,EAAA;AAAA,EAGX,UAAU,SAA2B,EAAE,gBAA2D;AAClG,UAAA,SAAS,KAAK,KAAK;AACzB,QAAI,OAAO,MAAM;AAEhB,cAAQ,WAAW,OAAO,WAAW,CAAA,GAAI,OAAO,KAAK,GAAG;AACxD;AAAA,IAAA;AAED,UAAM,gBAAgB,OAAO,OAAO,OAAO,OAAO;AAE1C,YAAA,YAAY,OAAO,WAAW;AAAA,MACrC,CAAC,cAAc,IAAI,GAAG;AAAA,QACrB,YAAY;AAAA,QACZ,MAAM,iBAAiB,aAAa;AAAA,QACpC,SAAS;AAAA,QACT,mBAAmB,cAAc;AAAA,MAAA;AAAA,IAClC,CACA;AAEI,QAAA,OAAO,UAAU,YAAY,OAAO;AACxC,yBAAmB,SAAS,cAAc,OAAO,WAAW,CAAC,OAAO,aAAa,CAAC;AAC5D,4BAAA,SAAS,cAAc,OAAO,SAAS;AAAA,IAAA;AAAA,EAC9D;AAAA,EAGM,mBAAkC;AACxC,WAAO,YAAY,CAAC,EAAE,aAAa;AAAA,MAClC,GAAG;AAAA,MACH,UAAU;AAAA,QACT,GAAG,MAAM;AAAA,QACT,CAAC,KAAK,KAAK,OAAO,IAAI,GAAG;AAAA,UACxB,UAAU,EAAE,SAAS,KAAK;AAAA,UAC1B,GAAG,KAAK,KAAK;AAAA,UACb,QAAQ,OAAO,OAAO,KAAK,KAAK,OAAO,MAAM;AAAA,UAC7C,SAAS,OAAO,OAAO,KAAK,KAAK,OAAO,WAAW,CAAE,CAAA;AAAA,QAAA;AAAA,MACtD;AAAA,IACD,EACC;AAAA,EAAA;AAAA,EAIH,WAAW;AACV,WAAO,EAAE,SAAS,cAAc,KAAK,KAAK,OAAO,IAAI,GAAG;AAAA,EAAA;AAG1D;AAEO,MAAM,2BAA2B,uBAAuB;AAAA,EAC9D,IAAI;AAAA,EACJ,SAAS;AACV,CAAC;AAEM,MAAM,mBAAqC;AAAA,EACjD,WAAW,gBAAwB,eAAuB;AAClD,WAAA,OAAO,OAAO,cAAc,MAAM,QAAQ,EAC/C,OAAO,QAAM,CAAC,eAAe,MAAM,SAAS,GAAG,IAAI,CAAC,EACpD,OAAO,CAAM,OAAA,CAAC,GAAG,IAAI,EACrB;AAAA,MAAI,CAAA,WACJ,yBAAyB,mBAAmB;AAAA,QAC3C,QAAQ;AAAA,UACP,GAAG;AAAA,UACH,QAAQ;AAAA,YACP,CAAC,OAAO,OAAO,GAAG,OAAO,OAAO,OAAO,OAAO;AAAA,UAC/C;AAAA,UACA,QAAQ,CAAA;AAAA,QAAC;AAAA,MAEV,CAAA;AAAA,IACF;AAAA,EAAA;AAEH;"}
1
+ {"version":3,"file":"CreateEntityModification.js","sources":["../../../../../../packages/schema-migrations/src/modifications/entities/CreateEntityModification.ts"],"sourcesContent":["import { MigrationBuilder } from '@contember/database-migrations'\nimport { Model, Schema } from '@contember/schema'\nimport { SchemaUpdater, updateModel } from '../utils/schemaUpdateUtils'\nimport {\n\tcreateModificationType,\n\tDiffer,\n\tModificationHandler, ModificationHandlerCreateSqlOptions,\n\tModificationHandlerOptions,\n} from '../ModificationHandler'\nimport { createEventTrigger, createEventTrxTrigger } from '../utils/sqlUpdateUtils'\nimport { PossibleEntityShapeInMigrations } from '../../utils/PartialEntity.js'\nimport { getColumnSqlType } from '../utils/columnUtils'\nimport { VERSION_CORRECT_PRIMARY_COLUMN_NAME } from '../ModificationVersions'\n\nexport class CreateEntityModificationHandler implements ModificationHandler<CreateEntityModificationData> {\n\tconstructor(\n\t\tprivate readonly data: CreateEntityModificationData,\n\t\tprivate readonly schema: Schema,\n\t\tprivate readonly options: ModificationHandlerOptions,\n\t) {}\n\n\tpublic createSql(builder: MigrationBuilder, { systemSchema }: ModificationHandlerCreateSqlOptions): void {\n\t\tconst entity = this.data.entity\n\t\tif (entity.view) {\n\t\t\t// BC\n\t\t\tbuilder.createView(entity.tableName, {}, entity.view.sql)\n\t\t\treturn\n\t\t}\n\t\tconst primaryColumn = entity.fields[entity.primary] as Model.AnyColumn\n\n\t\tconst primaryColumnName = this.options.formatVersion >= VERSION_CORRECT_PRIMARY_COLUMN_NAME\n\t\t\t? primaryColumn.columnName\n\t\t\t: primaryColumn.name\n\t\tbuilder.createTable(entity.tableName, {\n\t\t\t[primaryColumnName]: {\n\t\t\t\tprimaryKey: true,\n\t\t\t\ttype: getColumnSqlType(primaryColumn),\n\t\t\t\tnotNull: true,\n\t\t\t\tsequenceGenerated: primaryColumn.sequence,\n\t\t\t},\n\t\t})\n\n\t\tif (entity.eventLog?.enabled !== false) {\n\t\t\tcreateEventTrigger(builder, systemSchema, entity.tableName, [entity.primaryColumn])\n\t\t\tcreateEventTrxTrigger(builder, systemSchema, entity.tableName)\n\t\t}\n\t}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn updateModel(({ model }) => ({\n\t\t\t...model,\n\t\t\tentities: {\n\t\t\t\t...model.entities,\n\t\t\t\t[this.data.entity.name]: {\n\t\t\t\t\teventLog: { enabled: true },\n\t\t\t\t\t...this.data.entity,\n\t\t\t\t\tunique: Object.values(this.data.entity.unique),\n\t\t\t\t\tindexes: Object.values(this.data.entity.indexes ?? []),\n\t\t\t\t},\n\t\t\t},\n\t\t}))\n\t}\n\n\n\tdescribe() {\n\t\treturn { message: `Add entity ${this.data.entity.name}` }\n\t}\n\n}\n\nexport const createEntityModification = createModificationType({\n\tid: 'createEntity',\n\thandler: CreateEntityModificationHandler,\n})\n\nexport class CreateEntityDiffer implements Differ {\n\tcreateDiff(originalSchema: Schema, updatedSchema: Schema) {\n\t\treturn Object.values(updatedSchema.model.entities)\n\t\t\t.filter(it => !originalSchema.model.entities[it.name])\n\t\t\t.filter(it => !it.view)\n\t\t\t.map(entity =>\n\t\t\t\tcreateEntityModification.createModification({\n\t\t\t\t\tentity: {\n\t\t\t\t\t\t...entity,\n\t\t\t\t\t\tfields: {\n\t\t\t\t\t\t\t[entity.primary]: entity.fields[entity.primary],\n\t\t\t\t\t\t},\n\t\t\t\t\t\tunique: [],\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t)\n\t}\n}\n\nexport interface CreateEntityModificationData {\n\tentity: PossibleEntityShapeInMigrations\n}\n"],"names":[],"mappings":";;;;;AAcO,MAAM,gCAA6F;AAAA,EACzG,YACkB,MACA,QACA,SAChB;AAHgB,SAAA,OAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AAAA,EAAA;AAAA,EAGX,UAAU,SAA2B,EAAE,gBAA2D;AAClG,UAAA,SAAS,KAAK,KAAK;AACzB,QAAI,OAAO,MAAM;AAEhB,cAAQ,WAAW,OAAO,WAAW,CAAA,GAAI,OAAO,KAAK,GAAG;AACxD;AAAA,IAAA;AAED,UAAM,gBAAgB,OAAO,OAAO,OAAO,OAAO;AAElD,UAAM,oBAAoB,KAAK,QAAQ,iBAAiB,sCACrD,cAAc,aACd,cAAc;AACT,YAAA,YAAY,OAAO,WAAW;AAAA,MACrC,CAAC,iBAAiB,GAAG;AAAA,QACpB,YAAY;AAAA,QACZ,MAAM,iBAAiB,aAAa;AAAA,QACpC,SAAS;AAAA,QACT,mBAAmB,cAAc;AAAA,MAAA;AAAA,IAClC,CACA;AAEI,QAAA,OAAO,UAAU,YAAY,OAAO;AACxC,yBAAmB,SAAS,cAAc,OAAO,WAAW,CAAC,OAAO,aAAa,CAAC;AAC5D,4BAAA,SAAS,cAAc,OAAO,SAAS;AAAA,IAAA;AAAA,EAC9D;AAAA,EAGM,mBAAkC;AACxC,WAAO,YAAY,CAAC,EAAE,aAAa;AAAA,MAClC,GAAG;AAAA,MACH,UAAU;AAAA,QACT,GAAG,MAAM;AAAA,QACT,CAAC,KAAK,KAAK,OAAO,IAAI,GAAG;AAAA,UACxB,UAAU,EAAE,SAAS,KAAK;AAAA,UAC1B,GAAG,KAAK,KAAK;AAAA,UACb,QAAQ,OAAO,OAAO,KAAK,KAAK,OAAO,MAAM;AAAA,UAC7C,SAAS,OAAO,OAAO,KAAK,KAAK,OAAO,WAAW,CAAE,CAAA;AAAA,QAAA;AAAA,MACtD;AAAA,IACD,EACC;AAAA,EAAA;AAAA,EAIH,WAAW;AACV,WAAO,EAAE,SAAS,cAAc,KAAK,KAAK,OAAO,IAAI,GAAG;AAAA,EAAA;AAG1D;AAEO,MAAM,2BAA2B,uBAAuB;AAAA,EAC9D,IAAI;AAAA,EACJ,SAAS;AACV,CAAC;AAEM,MAAM,mBAAqC;AAAA,EACjD,WAAW,gBAAwB,eAAuB;AAClD,WAAA,OAAO,OAAO,cAAc,MAAM,QAAQ,EAC/C,OAAO,QAAM,CAAC,eAAe,MAAM,SAAS,GAAG,IAAI,CAAC,EACpD,OAAO,CAAM,OAAA,CAAC,GAAG,IAAI,EACrB;AAAA,MAAI,CAAA,WACJ,yBAAyB,mBAAmB;AAAA,QAC3C,QAAQ;AAAA,UACP,GAAG;AAAA,UACH,QAAQ;AAAA,YACP,CAAC,OAAO,OAAO,GAAG,OAAO,OAAO,OAAO,OAAO;AAAA,UAC/C;AAAA,UACA,QAAQ,CAAA;AAAA,QAAC;AAAA,MAEV,CAAA;AAAA,IACF;AAAA,EAAA;AAEH;"}
@@ -47,9 +47,10 @@ const updateAclFieldPermissions = (updater) => ({ entityPermissions, entityName
47
47
  update: (value) => updater(value, entityName, schema.Acl.Operation.update),
48
48
  read: (value) => updater(value, entityName, schema.Acl.Operation.read),
49
49
  delete: (value) => value,
50
- customPrimary: (value) => value
50
+ customPrimary: (value) => value,
51
+ noRoot: (value) => value
51
52
  };
52
- const types = ["create", "update", "read", "delete", "customPrimary"];
53
+ const types = ["create", "update", "read", "delete", "customPrimary", "noRoot"];
53
54
  for (const key of types) {
54
55
  if (key in entityPermissions.operations) {
55
56
  operations[key] = handlers[key](entityPermissions.operations[key]);
@@ -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\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 =\n\t(...schemaUpdater: (SchemaUpdater | undefined)[]): SchemaUpdater =>\n\t\targs =>\n\t\t\tschemaUpdater.filter(isDefined).reduce((schema, updater) => updater({ ...args, schema }), args.schema)\n\nexport const updateAcl =\n\t(updater: AclUpdater): SchemaUpdater =>\n\t\targs => ({\n\t\t\t...args.schema,\n\t\t\tacl: updater({ schema: args.schema, acl: args.schema.acl }),\n\t\t})\n\nexport const updateAclEveryRole =\n\t(...updater: AclRoleUpdater[]): AclUpdater =>\n\t\targs => ({\n\t\t\t...args.acl,\n\t\t\troles: Object.fromEntries(\n\t\t\t\tupdater.reduce(\n\t\t\t\t\t(acc, updater) => acc.map(([name, role]) => [name, updater({ ...args, role })]),\n\t\t\t\t\tObject.entries(args.acl.roles),\n\t\t\t\t),\n\t\t\t),\n\t\t})\n\nexport const updateAclEntities =\n\t(updater: AclPermissionsUpdater): AclRoleUpdater =>\n\t\targs => ({\n\t\t\t...args.role,\n\t\t\tentities: updater({ ...args, entities: args.role.entities }),\n\t\t})\n\nexport const updateAclEveryEntity =\n\t(...updater: AclEntityPermissionsUpdater[]): AclRoleUpdater =>\n\t\targs => ({\n\t\t\t...args.role,\n\t\t\tentities: Object.fromEntries(\n\t\t\t\tupdater.reduce(\n\t\t\t\t\t(acc, updater) =>\n\t\t\t\t\t\tacc.map(([entity, entityPermissions]) => [\n\t\t\t\t\t\t\tentity,\n\t\t\t\t\t\t\tupdater({\n\t\t\t\t\t\t\t\t...args,\n\t\t\t\t\t\t\t\tentities: args.role.entities,\n\t\t\t\t\t\t\t\tentityName: entity,\n\t\t\t\t\t\t\t\tentityPermissions,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]),\n\t\t\t\t\tObject.entries(args.role.entities),\n\t\t\t\t),\n\t\t\t),\n\t\t})\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 =>\n\t\t({ entityPermissions, entityName }) => {\n\t\t\tconst operations: Writable<Acl.EntityOperations> = {}\n\t\t\tconst handlers: EntityOperationHandler = {\n\t\t\t\tcreate: value => updater(value, entityName, Acl.Operation.create),\n\t\t\t\tupdate: value => updater(value, entityName, Acl.Operation.update),\n\t\t\t\tread: value => updater(value, entityName, Acl.Operation.read),\n\t\t\t\tdelete: value => value,\n\t\t\t\tcustomPrimary: value => value,\n\t\t\t}\n\t\t\tconst types: (keyof Acl.EntityOperations)[] = ['create', 'update', 'read', 'delete', 'customPrimary']\n\t\t\tfor (const key of types) {\n\t\t\t\tif (key in entityPermissions.operations) {\n\t\t\t\t\toperations[key] = handlers[key](entityPermissions.operations[key] as any) as any\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...entityPermissions,\n\t\t\t\toperations,\n\t\t\t}\n\t\t}\n\nexport const updateAclEveryPredicate =\n\t(updater: EntityAclEveryPredicatesUpdater): AclEntityPermissionsUpdater =>\n\t\targs => {\n\t\t\treturn {\n\t\t\t\t...args.entityPermissions,\n\t\t\t\tpredicates: Object.fromEntries(\n\t\t\t\t\tObject.entries(args.entityPermissions.predicates).map(([name, predicate]) => [\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tupdater({\n\t\t\t\t\t\t\t...args,\n\t\t\t\t\t\t\tpredicate,\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t}\n\t\t}\n\nexport const updateModel =\n\t(...modelUpdate: (ModelUpdater | undefined)[]): SchemaUpdater =>\n\t\targs => ({\n\t\t\t...args.schema,\n\t\t\tmodel: modelUpdate\n\t\t\t\t.filter((it): it is ModelUpdater => it !== undefined)\n\t\t\t\t.reduce((model, updater) => updater({ ...args, model }), args.schema.model),\n\t\t})\n\nexport const updateEntity =\n\t(name: string, entityUpdate: EntityUpdater): ModelUpdater =>\n\t\targs => {\n\t\t\tif (!args.model.entities[name]) {\n\t\t\t\tthrow new SchemaUpdateError(`Entity ${name} not found`)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...args.model,\n\t\t\t\tentities: {\n\t\t\t\t\t...args.model.entities,\n\t\t\t\t\t[name]: entityUpdate({ ...args, entity: args.model.entities[name] }),\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\nexport const updateEveryEntity =\n\t(entityUpdate: EntityUpdater): ModelUpdater =>\n\t\targs => ({\n\t\t\t...args.model,\n\t\t\tentities: Object.fromEntries(\n\t\t\t\tObject.entries(args.model.entities).map(([name, entity]) => [name, entityUpdate({ ...args, entity })]),\n\t\t\t),\n\t\t})\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\t\targs => {\n\t\t\tconst { [name]: field, ...otherFields } = args.entity.fields\n\t\t\tif (!args.entity.fields[name]) {\n\t\t\t\tthrow new SchemaUpdateError(`Field ${args.entity.name}::${name} not found`)\n\t\t\t}\n\t\t\tconst updatedField = fieldUpdater({ ...args, field: args.entity.fields[name] as In })\n\n\t\t\treturn {\n\t\t\t\t...args.entity,\n\t\t\t\tfields: {\n\t\t\t\t\t...otherFields,\n\t\t\t\t\t...(updatedField ? { [name]: updatedField } : {}),\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\nexport const updateEveryField =\n\t(fieldUpdater: FieldUpdater<Model.AnyField, Model.AnyField>): EntityUpdater =>\n\t\targs => ({\n\t\t\t...args.entity,\n\t\t\tfields: Object.fromEntries(\n\t\t\t\tObject.entries(args.entity.fields)\n\t\t\t\t\t.map(([name, field]) => {\n\t\t\t\t\t\tconst updatedField = fieldUpdater({ ...args, field })\n\t\t\t\t\t\tif (!updatedField) {\n\t\t\t\t\t\t\treturn undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn [name, updatedField]\n\t\t\t\t\t})\n\t\t\t\t\t.filter(isDefined),\n\t\t\t),\n\t\t})\n\nexport const addField =\n\t(field: Model.AnyField): EntityUpdater =>\n\t\targs => {\n\t\t\treturn {\n\t\t\t\t...args.entity,\n\t\t\t\tfields: {\n\t\t\t\t\t...args.entity.fields,\n\t\t\t\t\t[field.name]: field,\n\t\t\t\t},\n\t\t\t}\n\t\t}\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 =>\n\t\t\t\t\t\t\t\t\t\tctx.entity.name === entity.name && ctx.column.name === field.name ? undefined : ctx.value,\n\t\t\t\t\t\t\t\t\thandleRelation: ctx =>\n\t\t\t\t\t\t\t\t\t\tctx.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\tisOwningRelation(field) &&\n\t\t\t\tfield.inversedBy &&\n\t\t\t\tversion >= 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":";;;;;;;AAgDa,MAAA,eACZ,IAAI,kBACH,CAAA,SACC,cAAc,OAAOA,UAAAA,SAAS,EAAE,OAAO,CAACC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WC,qBAAA,uCACT,YAAY,MAAM,QAAQ,MAAM,YAAY,OAAO,IACnD;AAAA,MACH;AAAA,QACC,aAAa,OAAO,MAAM,CAAC,EAAE,QAAAC,cAAa;AACnC,gBAAA,EAAE,CAAC,MAAM,IAAI,GAAG,SAAS,GAAG,OAAO,IAAIA,QAAO;AAC9C,gBAAA,UAAUA,QAAO,QAAQ,OAAO,CAAA,UAAS,CAAC,MAAM,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3E,gBAAA,SAASA,QAAO,OAAO,OAAO,CAAA,UAAS,CAAC,MAAM,OAAO,SAAS,MAAM,IAAI,CAAC;AACxE,iBAAA;AAAA,YACN,GAAGA;AAAAA,YACH;AAAA,YACA;AAAA,YACA;AAAA,UACD;AAAA,QAAA,CACA;AAAA,QACDH,YAAAA,WAAW,KAAK,KAAKI,8BAAkB,KAAK,IACzC;AAAA,UACD,MAAM;AAAA,UACN,YAAqC,MAAM,SAAS,CAAC,EAAE,OAAO,EAAE,YAAY,GAAGN,OAAQ,EAAA,MAAMA,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'\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\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 =\n\t(...schemaUpdater: (SchemaUpdater | undefined)[]): SchemaUpdater =>\n\t\targs =>\n\t\t\tschemaUpdater.filter(isDefined).reduce((schema, updater) => updater({ ...args, schema }), args.schema)\n\nexport const updateAcl =\n\t(updater: AclUpdater): SchemaUpdater =>\n\t\targs => ({\n\t\t\t...args.schema,\n\t\t\tacl: updater({ schema: args.schema, acl: args.schema.acl }),\n\t\t})\n\nexport const updateAclEveryRole =\n\t(...updater: AclRoleUpdater[]): AclUpdater =>\n\t\targs => ({\n\t\t\t...args.acl,\n\t\t\troles: Object.fromEntries(\n\t\t\t\tupdater.reduce(\n\t\t\t\t\t(acc, updater) => acc.map(([name, role]) => [name, updater({ ...args, role })]),\n\t\t\t\t\tObject.entries(args.acl.roles),\n\t\t\t\t),\n\t\t\t),\n\t\t})\n\nexport const updateAclEntities =\n\t(updater: AclPermissionsUpdater): AclRoleUpdater =>\n\t\targs => ({\n\t\t\t...args.role,\n\t\t\tentities: updater({ ...args, entities: args.role.entities }),\n\t\t})\n\nexport const updateAclEveryEntity =\n\t(...updater: AclEntityPermissionsUpdater[]): AclRoleUpdater =>\n\t\targs => ({\n\t\t\t...args.role,\n\t\t\tentities: Object.fromEntries(\n\t\t\t\tupdater.reduce(\n\t\t\t\t\t(acc, updater) =>\n\t\t\t\t\t\tacc.map(([entity, entityPermissions]) => [\n\t\t\t\t\t\t\tentity,\n\t\t\t\t\t\t\tupdater({\n\t\t\t\t\t\t\t\t...args,\n\t\t\t\t\t\t\t\tentities: args.role.entities,\n\t\t\t\t\t\t\t\tentityName: entity,\n\t\t\t\t\t\t\t\tentityPermissions,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]),\n\t\t\t\t\tObject.entries(args.role.entities),\n\t\t\t\t),\n\t\t\t),\n\t\t})\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 =>\n\t\t({ entityPermissions, entityName }) => {\n\t\t\tconst operations: Writable<Acl.EntityOperations> = {}\n\t\t\tconst handlers: EntityOperationHandler = {\n\t\t\t\tcreate: value => updater(value, entityName, Acl.Operation.create),\n\t\t\t\tupdate: value => updater(value, entityName, Acl.Operation.update),\n\t\t\t\tread: value => updater(value, entityName, Acl.Operation.read),\n\t\t\t\tdelete: value => value,\n\t\t\t\tcustomPrimary: value => value,\n\t\t\t\tnoRoot: value => value,\n\t\t\t}\n\t\t\tconst types: (keyof Acl.EntityOperations)[] = ['create', 'update', 'read', 'delete', 'customPrimary', 'noRoot']\n\t\t\tfor (const key of types) {\n\t\t\t\tif (key in entityPermissions.operations) {\n\t\t\t\t\toperations[key] = handlers[key](entityPermissions.operations[key] as any) as any\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...entityPermissions,\n\t\t\t\toperations,\n\t\t\t}\n\t\t}\n\nexport const updateAclEveryPredicate =\n\t(updater: EntityAclEveryPredicatesUpdater): AclEntityPermissionsUpdater =>\n\t\targs => {\n\t\t\treturn {\n\t\t\t\t...args.entityPermissions,\n\t\t\t\tpredicates: Object.fromEntries(\n\t\t\t\t\tObject.entries(args.entityPermissions.predicates).map(([name, predicate]) => [\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tupdater({\n\t\t\t\t\t\t\t...args,\n\t\t\t\t\t\t\tpredicate,\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t}\n\t\t}\n\nexport const updateModel =\n\t(...modelUpdate: (ModelUpdater | undefined)[]): SchemaUpdater =>\n\t\targs => ({\n\t\t\t...args.schema,\n\t\t\tmodel: modelUpdate\n\t\t\t\t.filter((it): it is ModelUpdater => it !== undefined)\n\t\t\t\t.reduce((model, updater) => updater({ ...args, model }), args.schema.model),\n\t\t})\n\nexport const updateEntity =\n\t(name: string, entityUpdate: EntityUpdater): ModelUpdater =>\n\t\targs => {\n\t\t\tif (!args.model.entities[name]) {\n\t\t\t\tthrow new SchemaUpdateError(`Entity ${name} not found`)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...args.model,\n\t\t\t\tentities: {\n\t\t\t\t\t...args.model.entities,\n\t\t\t\t\t[name]: entityUpdate({ ...args, entity: args.model.entities[name] }),\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\nexport const updateEveryEntity =\n\t(entityUpdate: EntityUpdater): ModelUpdater =>\n\t\targs => ({\n\t\t\t...args.model,\n\t\t\tentities: Object.fromEntries(\n\t\t\t\tObject.entries(args.model.entities).map(([name, entity]) => [name, entityUpdate({ ...args, entity })]),\n\t\t\t),\n\t\t})\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\t\targs => {\n\t\t\tconst { [name]: field, ...otherFields } = args.entity.fields\n\t\t\tif (!args.entity.fields[name]) {\n\t\t\t\tthrow new SchemaUpdateError(`Field ${args.entity.name}::${name} not found`)\n\t\t\t}\n\t\t\tconst updatedField = fieldUpdater({ ...args, field: args.entity.fields[name] as In })\n\n\t\t\treturn {\n\t\t\t\t...args.entity,\n\t\t\t\tfields: {\n\t\t\t\t\t...otherFields,\n\t\t\t\t\t...(updatedField ? { [name]: updatedField } : {}),\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\nexport const updateEveryField =\n\t(fieldUpdater: FieldUpdater<Model.AnyField, Model.AnyField>): EntityUpdater =>\n\t\targs => ({\n\t\t\t...args.entity,\n\t\t\tfields: Object.fromEntries(\n\t\t\t\tObject.entries(args.entity.fields)\n\t\t\t\t\t.map(([name, field]) => {\n\t\t\t\t\t\tconst updatedField = fieldUpdater({ ...args, field })\n\t\t\t\t\t\tif (!updatedField) {\n\t\t\t\t\t\t\treturn undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn [name, updatedField]\n\t\t\t\t\t})\n\t\t\t\t\t.filter(isDefined),\n\t\t\t),\n\t\t})\n\nexport const addField =\n\t(field: Model.AnyField): EntityUpdater =>\n\t\targs => {\n\t\t\treturn {\n\t\t\t\t...args.entity,\n\t\t\t\tfields: {\n\t\t\t\t\t...args.entity.fields,\n\t\t\t\t\t[field.name]: field,\n\t\t\t\t},\n\t\t\t}\n\t\t}\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 =>\n\t\t\t\t\t\t\t\t\t\tctx.entity.name === entity.name && ctx.column.name === field.name ? undefined : ctx.value,\n\t\t\t\t\t\t\t\t\thandleRelation: ctx =>\n\t\t\t\t\t\t\t\t\t\tctx.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\tisOwningRelation(field) &&\n\t\t\t\tfield.inversedBy &&\n\t\t\t\tversion >= 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":";;;;;;;AAgDa,MAAA,eACZ,IAAI,kBACH,CAAA,SACC,cAAc,OAAOA,UAAAA,SAAS,EAAE,OAAO,CAACC,SAAQ,YAAY,QAAQ,EAAE,GAAG,MAAM,QAAAA,QAAQ,CAAA,GAAG,KAAK,MAAM;AAE3F,MAAA,YACZ,CAAC,YACA,CAAS,UAAA;AAAA,EACR,GAAG,KAAK;AAAA,EACR,KAAK,QAAQ,EAAE,QAAQ,KAAK,QAAQ,KAAK,KAAK,OAAO,IAAK,CAAA;AAC3D;AAEW,MAAA,qBACZ,IAAI,YACH,CAAS,UAAA;AAAA,EACR,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,KAAM,CAAA,CAAC,CAAC;AAAA,MAC9E,OAAO,QAAQ,KAAK,IAAI,KAAK;AAAA,IAAA;AAAA,EAC9B;AAEF;AAEW,MAAA,oBACZ,CAAC,YACA,CAAS,UAAA;AAAA,EACR,GAAG,KAAK;AAAA,EACR,UAAU,QAAQ,EAAE,GAAG,MAAM,UAAU,KAAK,KAAK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,EAAA,MAAMA,MAAK;AAAA,QAAA,IAEjG;AAAA,MAAA;AAAA,IACJ,EACC,EAAE,QAAAN,QAAA,CAAQ;AAAA,EACb;AACD;;;;;;;;;;;;;;;"}
@@ -45,9 +45,10 @@ const updateAclFieldPermissions = (updater) => ({ entityPermissions, entityName
45
45
  update: (value) => updater(value, entityName, Acl.Operation.update),
46
46
  read: (value) => updater(value, entityName, Acl.Operation.read),
47
47
  delete: (value) => value,
48
- customPrimary: (value) => value
48
+ customPrimary: (value) => value,
49
+ noRoot: (value) => value
49
50
  };
50
- const types = ["create", "update", "read", "delete", "customPrimary"];
51
+ const types = ["create", "update", "read", "delete", "customPrimary", "noRoot"];
51
52
  for (const key of types) {
52
53
  if (key in entityPermissions.operations) {
53
54
  operations[key] = handlers[key](entityPermissions.operations[key]);
@@ -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\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 =\n\t(...schemaUpdater: (SchemaUpdater | undefined)[]): SchemaUpdater =>\n\t\targs =>\n\t\t\tschemaUpdater.filter(isDefined).reduce((schema, updater) => updater({ ...args, schema }), args.schema)\n\nexport const updateAcl =\n\t(updater: AclUpdater): SchemaUpdater =>\n\t\targs => ({\n\t\t\t...args.schema,\n\t\t\tacl: updater({ schema: args.schema, acl: args.schema.acl }),\n\t\t})\n\nexport const updateAclEveryRole =\n\t(...updater: AclRoleUpdater[]): AclUpdater =>\n\t\targs => ({\n\t\t\t...args.acl,\n\t\t\troles: Object.fromEntries(\n\t\t\t\tupdater.reduce(\n\t\t\t\t\t(acc, updater) => acc.map(([name, role]) => [name, updater({ ...args, role })]),\n\t\t\t\t\tObject.entries(args.acl.roles),\n\t\t\t\t),\n\t\t\t),\n\t\t})\n\nexport const updateAclEntities =\n\t(updater: AclPermissionsUpdater): AclRoleUpdater =>\n\t\targs => ({\n\t\t\t...args.role,\n\t\t\tentities: updater({ ...args, entities: args.role.entities }),\n\t\t})\n\nexport const updateAclEveryEntity =\n\t(...updater: AclEntityPermissionsUpdater[]): AclRoleUpdater =>\n\t\targs => ({\n\t\t\t...args.role,\n\t\t\tentities: Object.fromEntries(\n\t\t\t\tupdater.reduce(\n\t\t\t\t\t(acc, updater) =>\n\t\t\t\t\t\tacc.map(([entity, entityPermissions]) => [\n\t\t\t\t\t\t\tentity,\n\t\t\t\t\t\t\tupdater({\n\t\t\t\t\t\t\t\t...args,\n\t\t\t\t\t\t\t\tentities: args.role.entities,\n\t\t\t\t\t\t\t\tentityName: entity,\n\t\t\t\t\t\t\t\tentityPermissions,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]),\n\t\t\t\t\tObject.entries(args.role.entities),\n\t\t\t\t),\n\t\t\t),\n\t\t})\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 =>\n\t\t({ entityPermissions, entityName }) => {\n\t\t\tconst operations: Writable<Acl.EntityOperations> = {}\n\t\t\tconst handlers: EntityOperationHandler = {\n\t\t\t\tcreate: value => updater(value, entityName, Acl.Operation.create),\n\t\t\t\tupdate: value => updater(value, entityName, Acl.Operation.update),\n\t\t\t\tread: value => updater(value, entityName, Acl.Operation.read),\n\t\t\t\tdelete: value => value,\n\t\t\t\tcustomPrimary: value => value,\n\t\t\t}\n\t\t\tconst types: (keyof Acl.EntityOperations)[] = ['create', 'update', 'read', 'delete', 'customPrimary']\n\t\t\tfor (const key of types) {\n\t\t\t\tif (key in entityPermissions.operations) {\n\t\t\t\t\toperations[key] = handlers[key](entityPermissions.operations[key] as any) as any\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...entityPermissions,\n\t\t\t\toperations,\n\t\t\t}\n\t\t}\n\nexport const updateAclEveryPredicate =\n\t(updater: EntityAclEveryPredicatesUpdater): AclEntityPermissionsUpdater =>\n\t\targs => {\n\t\t\treturn {\n\t\t\t\t...args.entityPermissions,\n\t\t\t\tpredicates: Object.fromEntries(\n\t\t\t\t\tObject.entries(args.entityPermissions.predicates).map(([name, predicate]) => [\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tupdater({\n\t\t\t\t\t\t\t...args,\n\t\t\t\t\t\t\tpredicate,\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t}\n\t\t}\n\nexport const updateModel =\n\t(...modelUpdate: (ModelUpdater | undefined)[]): SchemaUpdater =>\n\t\targs => ({\n\t\t\t...args.schema,\n\t\t\tmodel: modelUpdate\n\t\t\t\t.filter((it): it is ModelUpdater => it !== undefined)\n\t\t\t\t.reduce((model, updater) => updater({ ...args, model }), args.schema.model),\n\t\t})\n\nexport const updateEntity =\n\t(name: string, entityUpdate: EntityUpdater): ModelUpdater =>\n\t\targs => {\n\t\t\tif (!args.model.entities[name]) {\n\t\t\t\tthrow new SchemaUpdateError(`Entity ${name} not found`)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...args.model,\n\t\t\t\tentities: {\n\t\t\t\t\t...args.model.entities,\n\t\t\t\t\t[name]: entityUpdate({ ...args, entity: args.model.entities[name] }),\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\nexport const updateEveryEntity =\n\t(entityUpdate: EntityUpdater): ModelUpdater =>\n\t\targs => ({\n\t\t\t...args.model,\n\t\t\tentities: Object.fromEntries(\n\t\t\t\tObject.entries(args.model.entities).map(([name, entity]) => [name, entityUpdate({ ...args, entity })]),\n\t\t\t),\n\t\t})\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\t\targs => {\n\t\t\tconst { [name]: field, ...otherFields } = args.entity.fields\n\t\t\tif (!args.entity.fields[name]) {\n\t\t\t\tthrow new SchemaUpdateError(`Field ${args.entity.name}::${name} not found`)\n\t\t\t}\n\t\t\tconst updatedField = fieldUpdater({ ...args, field: args.entity.fields[name] as In })\n\n\t\t\treturn {\n\t\t\t\t...args.entity,\n\t\t\t\tfields: {\n\t\t\t\t\t...otherFields,\n\t\t\t\t\t...(updatedField ? { [name]: updatedField } : {}),\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\nexport const updateEveryField =\n\t(fieldUpdater: FieldUpdater<Model.AnyField, Model.AnyField>): EntityUpdater =>\n\t\targs => ({\n\t\t\t...args.entity,\n\t\t\tfields: Object.fromEntries(\n\t\t\t\tObject.entries(args.entity.fields)\n\t\t\t\t\t.map(([name, field]) => {\n\t\t\t\t\t\tconst updatedField = fieldUpdater({ ...args, field })\n\t\t\t\t\t\tif (!updatedField) {\n\t\t\t\t\t\t\treturn undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn [name, updatedField]\n\t\t\t\t\t})\n\t\t\t\t\t.filter(isDefined),\n\t\t\t),\n\t\t})\n\nexport const addField =\n\t(field: Model.AnyField): EntityUpdater =>\n\t\targs => {\n\t\t\treturn {\n\t\t\t\t...args.entity,\n\t\t\t\tfields: {\n\t\t\t\t\t...args.entity.fields,\n\t\t\t\t\t[field.name]: field,\n\t\t\t\t},\n\t\t\t}\n\t\t}\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 =>\n\t\t\t\t\t\t\t\t\t\tctx.entity.name === entity.name && ctx.column.name === field.name ? undefined : ctx.value,\n\t\t\t\t\t\t\t\t\thandleRelation: ctx =>\n\t\t\t\t\t\t\t\t\t\tctx.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\tisOwningRelation(field) &&\n\t\t\t\tfield.inversedBy &&\n\t\t\t\tversion >= 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: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GA,IAAA;AAAA,MACH,WAAW,KAAK,KACf,iBAAiB,KAAK,KACtB,MAAM,cACN,WAAW,uCACT,YAAY,MAAM,QAAQ,MAAM,YAAY,OAAO,IACnD;AAAA,MACH;AAAA,QACC,aAAa,OAAO,MAAM,CAAC,EAAE,QAAAE,cAAa;AACnC,gBAAA,EAAE,CAAC,MAAM,IAAI,GAAG,SAAS,GAAG,OAAO,IAAIA,QAAO;AAC9C,gBAAA,UAAUA,QAAO,QAAQ,OAAO,CAAA,UAAS,CAAC,MAAM,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3E,gBAAA,SAASA,QAAO,OAAO,OAAO,CAAA,UAAS,CAAC,MAAM,OAAO,SAAS,MAAM,IAAI,CAAC;AACxE,iBAAA;AAAA,YACN,GAAGA;AAAAA,YACH;AAAA,YACA;AAAA,YACA;AAAA,UACD;AAAA,QAAA,CACA;AAAA,QACD,WAAW,KAAK,KAAK,kBAAkB,KAAK,IACzC;AAAA,UACD,MAAM;AAAA,UACN,YAAqC,MAAM,SAAS,CAAC,EAAE,OAAO,EAAE,YAAY,GAAGD,OAAQ,EAAA,MAAMA,MAAK;AAAA,QAAA,IAEjG;AAAA,MAAA;AAAA,IACJ,EACC,EAAE,OAAA,CAAQ;AAAA,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'\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\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 =\n\t(...schemaUpdater: (SchemaUpdater | undefined)[]): SchemaUpdater =>\n\t\targs =>\n\t\t\tschemaUpdater.filter(isDefined).reduce((schema, updater) => updater({ ...args, schema }), args.schema)\n\nexport const updateAcl =\n\t(updater: AclUpdater): SchemaUpdater =>\n\t\targs => ({\n\t\t\t...args.schema,\n\t\t\tacl: updater({ schema: args.schema, acl: args.schema.acl }),\n\t\t})\n\nexport const updateAclEveryRole =\n\t(...updater: AclRoleUpdater[]): AclUpdater =>\n\t\targs => ({\n\t\t\t...args.acl,\n\t\t\troles: Object.fromEntries(\n\t\t\t\tupdater.reduce(\n\t\t\t\t\t(acc, updater) => acc.map(([name, role]) => [name, updater({ ...args, role })]),\n\t\t\t\t\tObject.entries(args.acl.roles),\n\t\t\t\t),\n\t\t\t),\n\t\t})\n\nexport const updateAclEntities =\n\t(updater: AclPermissionsUpdater): AclRoleUpdater =>\n\t\targs => ({\n\t\t\t...args.role,\n\t\t\tentities: updater({ ...args, entities: args.role.entities }),\n\t\t})\n\nexport const updateAclEveryEntity =\n\t(...updater: AclEntityPermissionsUpdater[]): AclRoleUpdater =>\n\t\targs => ({\n\t\t\t...args.role,\n\t\t\tentities: Object.fromEntries(\n\t\t\t\tupdater.reduce(\n\t\t\t\t\t(acc, updater) =>\n\t\t\t\t\t\tacc.map(([entity, entityPermissions]) => [\n\t\t\t\t\t\t\tentity,\n\t\t\t\t\t\t\tupdater({\n\t\t\t\t\t\t\t\t...args,\n\t\t\t\t\t\t\t\tentities: args.role.entities,\n\t\t\t\t\t\t\t\tentityName: entity,\n\t\t\t\t\t\t\t\tentityPermissions,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]),\n\t\t\t\t\tObject.entries(args.role.entities),\n\t\t\t\t),\n\t\t\t),\n\t\t})\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 =>\n\t\t({ entityPermissions, entityName }) => {\n\t\t\tconst operations: Writable<Acl.EntityOperations> = {}\n\t\t\tconst handlers: EntityOperationHandler = {\n\t\t\t\tcreate: value => updater(value, entityName, Acl.Operation.create),\n\t\t\t\tupdate: value => updater(value, entityName, Acl.Operation.update),\n\t\t\t\tread: value => updater(value, entityName, Acl.Operation.read),\n\t\t\t\tdelete: value => value,\n\t\t\t\tcustomPrimary: value => value,\n\t\t\t\tnoRoot: value => value,\n\t\t\t}\n\t\t\tconst types: (keyof Acl.EntityOperations)[] = ['create', 'update', 'read', 'delete', 'customPrimary', 'noRoot']\n\t\t\tfor (const key of types) {\n\t\t\t\tif (key in entityPermissions.operations) {\n\t\t\t\t\toperations[key] = handlers[key](entityPermissions.operations[key] as any) as any\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...entityPermissions,\n\t\t\t\toperations,\n\t\t\t}\n\t\t}\n\nexport const updateAclEveryPredicate =\n\t(updater: EntityAclEveryPredicatesUpdater): AclEntityPermissionsUpdater =>\n\t\targs => {\n\t\t\treturn {\n\t\t\t\t...args.entityPermissions,\n\t\t\t\tpredicates: Object.fromEntries(\n\t\t\t\t\tObject.entries(args.entityPermissions.predicates).map(([name, predicate]) => [\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tupdater({\n\t\t\t\t\t\t\t...args,\n\t\t\t\t\t\t\tpredicate,\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t}\n\t\t}\n\nexport const updateModel =\n\t(...modelUpdate: (ModelUpdater | undefined)[]): SchemaUpdater =>\n\t\targs => ({\n\t\t\t...args.schema,\n\t\t\tmodel: modelUpdate\n\t\t\t\t.filter((it): it is ModelUpdater => it !== undefined)\n\t\t\t\t.reduce((model, updater) => updater({ ...args, model }), args.schema.model),\n\t\t})\n\nexport const updateEntity =\n\t(name: string, entityUpdate: EntityUpdater): ModelUpdater =>\n\t\targs => {\n\t\t\tif (!args.model.entities[name]) {\n\t\t\t\tthrow new SchemaUpdateError(`Entity ${name} not found`)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...args.model,\n\t\t\t\tentities: {\n\t\t\t\t\t...args.model.entities,\n\t\t\t\t\t[name]: entityUpdate({ ...args, entity: args.model.entities[name] }),\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\nexport const updateEveryEntity =\n\t(entityUpdate: EntityUpdater): ModelUpdater =>\n\t\targs => ({\n\t\t\t...args.model,\n\t\t\tentities: Object.fromEntries(\n\t\t\t\tObject.entries(args.model.entities).map(([name, entity]) => [name, entityUpdate({ ...args, entity })]),\n\t\t\t),\n\t\t})\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\t\targs => {\n\t\t\tconst { [name]: field, ...otherFields } = args.entity.fields\n\t\t\tif (!args.entity.fields[name]) {\n\t\t\t\tthrow new SchemaUpdateError(`Field ${args.entity.name}::${name} not found`)\n\t\t\t}\n\t\t\tconst updatedField = fieldUpdater({ ...args, field: args.entity.fields[name] as In })\n\n\t\t\treturn {\n\t\t\t\t...args.entity,\n\t\t\t\tfields: {\n\t\t\t\t\t...otherFields,\n\t\t\t\t\t...(updatedField ? { [name]: updatedField } : {}),\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\nexport const updateEveryField =\n\t(fieldUpdater: FieldUpdater<Model.AnyField, Model.AnyField>): EntityUpdater =>\n\t\targs => ({\n\t\t\t...args.entity,\n\t\t\tfields: Object.fromEntries(\n\t\t\t\tObject.entries(args.entity.fields)\n\t\t\t\t\t.map(([name, field]) => {\n\t\t\t\t\t\tconst updatedField = fieldUpdater({ ...args, field })\n\t\t\t\t\t\tif (!updatedField) {\n\t\t\t\t\t\t\treturn undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn [name, updatedField]\n\t\t\t\t\t})\n\t\t\t\t\t.filter(isDefined),\n\t\t\t),\n\t\t})\n\nexport const addField =\n\t(field: Model.AnyField): EntityUpdater =>\n\t\targs => {\n\t\t\treturn {\n\t\t\t\t...args.entity,\n\t\t\t\tfields: {\n\t\t\t\t\t...args.entity.fields,\n\t\t\t\t\t[field.name]: field,\n\t\t\t\t},\n\t\t\t}\n\t\t}\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 =>\n\t\t\t\t\t\t\t\t\t\tctx.entity.name === entity.name && ctx.column.name === field.name ? undefined : ctx.value,\n\t\t\t\t\t\t\t\t\thandleRelation: ctx =>\n\t\t\t\t\t\t\t\t\t\tctx.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\tisOwningRelation(field) &&\n\t\t\t\tfield.inversedBy &&\n\t\t\t\tversion >= 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":";;;;;AAgDa,MAAA,eACZ,IAAI,kBACH,CAAA,SACC,cAAc,OAAO,SAAS,EAAE,OAAO,CAAC,QAAQ,YAAY,QAAQ,EAAE,GAAG,MAAM,OAAQ,CAAA,GAAG,KAAK,MAAM;AAE3F,MAAA,YACZ,CAAC,YACA,CAAS,UAAA;AAAA,EACR,GAAG,KAAK;AAAA,EACR,KAAK,QAAQ,EAAE,QAAQ,KAAK,QAAQ,KAAK,KAAK,OAAO,IAAK,CAAA;AAC3D;AAEW,MAAA,qBACZ,IAAI,YACH,CAAS,UAAA;AAAA,EACR,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,KAAM,CAAA,CAAC,CAAC;AAAA,MAC9E,OAAO,QAAQ,KAAK,IAAI,KAAK;AAAA,IAAA;AAAA,EAC9B;AAEF;AAEW,MAAA,oBACZ,CAAC,YACA,CAAS,UAAA;AAAA,EACR,GAAG,KAAK;AAAA,EACR,UAAU,QAAQ,EAAE,GAAG,MAAM,UAAU,KAAK,KAAK,SAAU,CAAA;AAC5D;AAEW,MAAA,uBACZ,IAAI,YACH,CAAS,UAAA;AAAA,EACR,GAAG,KAAK;AAAA,EACR,UAAU,OAAO;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O,KAAK;AAC/D,qBAAO,UAAU,QAAQ,OAAO,MAAM,SAASA,WAAU,GAAG,WAAW;AAAA,gBACtE,cAAc,CAAA,QACb,IAAI,OAAO,SAAS,OAAO,QAAQ,IAAI,OAAO,SAAS,MAAM,OAAO,SAAY,IAAI;AAAA,gBACrF,gBAAgB,CAAA,QACf,IAAI,OAAO,SAAS,OAAO,QAAQ,IAAI,SAAS,SAAS,MAAM,OAAO,SAAY,IAAI;AAAA,cAAA,CACvF;AAAA,YACD,CAAA;AAAA,UAAA;AAAA,QACF;AAAA,MAGA,IAAA;AAAA,MACH,WAAW,KAAK,KACf,iBAAiB,KAAK,KACtB,MAAM,cACN,WAAW,uCACT,YAAY,MAAM,QAAQ,MAAM,YAAY,OAAO,IACnD;AAAA,MACH;AAAA,QACC,aAAa,OAAO,MAAM,CAAC,EAAE,QAAAE,cAAa;AACnC,gBAAA,EAAE,CAAC,MAAM,IAAI,GAAG,SAAS,GAAG,OAAO,IAAIA,QAAO;AAC9C,gBAAA,UAAUA,QAAO,QAAQ,OAAO,CAAA,UAAS,CAAC,MAAM,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3E,gBAAA,SAASA,QAAO,OAAO,OAAO,CAAA,UAAS,CAAC,MAAM,OAAO,SAAS,MAAM,IAAI,CAAC;AACxE,iBAAA;AAAA,YACN,GAAGA;AAAAA,YACH;AAAA,YACA;AAAA,YACA;AAAA,UACD;AAAA,QAAA,CACA;AAAA,QACD,WAAW,KAAK,KAAK,kBAAkB,KAAK,IACzC;AAAA,UACD,MAAM;AAAA,UACN,YAAqC,MAAM,SAAS,CAAC,EAAE,OAAO,EAAE,YAAY,GAAGD,OAAQ,EAAA,MAAMA,MAAK;AAAA,QAAA,IAEjG;AAAA,MAAA;AAAA,IACJ,EACC,EAAE,OAAA,CAAQ;AAAA,EACb;AACD;"}
@@ -146,6 +146,7 @@ Object.defineProperty(exports, "ModificationHandlerFactory", {
146
146
  get: () => ModificationHandlerFactory.ModificationHandlerFactory
147
147
  });
148
148
  exports.VERSION_ACL_PATCH = ModificationVersions.VERSION_ACL_PATCH;
149
+ exports.VERSION_CORRECT_PRIMARY_COLUMN_NAME = ModificationVersions.VERSION_CORRECT_PRIMARY_COLUMN_NAME;
149
150
  exports.VERSION_INITIAL = ModificationVersions.VERSION_INITIAL;
150
151
  exports.VERSION_LATEST = ModificationVersions.VERSION_LATEST;
151
152
  exports.VERSION_REMOVE_REFERENCING_RELATIONS = ModificationVersions.VERSION_REMOVE_REFERENCING_RELATIONS;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -36,7 +36,7 @@ import { UpdateRelationOrderByDiffer, UpdateRelationOrderByModificationHandler,
36
36
  import { PatchValidationSchemaModificationHandler, patchValidationSchemaModification } from "./src/modifications/validation/PatchValidationSchemaModification.js";
37
37
  import { UpdateValidationSchemaDiffer, UpdateValidationSchemaModificationHandler, updateValidationSchemaModification } from "./src/modifications/validation/UpdateValidationSchemaModification.js";
38
38
  import { ModificationHandlerFactory } from "./src/modifications/ModificationHandlerFactory.js";
39
- import { VERSION_ACL_PATCH, VERSION_INITIAL, VERSION_LATEST, VERSION_REMOVE_REFERENCING_RELATIONS, VERSION_REMOVE_RELATION_INVERSE_SIDE, VERSION_UPDATE_CONSTRAINT_FIELDS, VERSION_UPDATE_INDEX_FIELDS, _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE } from "./src/modifications/ModificationVersions.js";
39
+ import { VERSION_ACL_PATCH, VERSION_CORRECT_PRIMARY_COLUMN_NAME, VERSION_INITIAL, VERSION_LATEST, VERSION_REMOVE_REFERENCING_RELATIONS, VERSION_REMOVE_RELATION_INVERSE_SIDE, VERSION_UPDATE_CONSTRAINT_FIELDS, VERSION_UPDATE_INDEX_FIELDS, _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE } from "./src/modifications/ModificationVersions.js";
40
40
  import { createModificationType, emptyModificationDescriptionContext } from "./src/modifications/ModificationHandler.js";
41
41
  import { SchemaUpdateError } from "./src/modifications/exceptions.js";
42
42
  import { createEventTrigger, createEventTrxTrigger, dropEventTrigger, dropEventTrxTrigger } from "./src/modifications/utils/sqlUpdateUtils.js";
@@ -110,6 +110,7 @@ export {
110
110
  UpdateValidationSchemaDiffer,
111
111
  UpdateValidationSchemaModificationHandler,
112
112
  VERSION_ACL_PATCH,
113
+ VERSION_CORRECT_PRIMARY_COLUMN_NAME,
113
114
  VERSION_INITIAL,
114
115
  VERSION_LATEST,
115
116
  VERSION_REMOVE_REFERENCING_RELATIONS,
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const VERSION_INITIAL = 1;
4
- const VERSION_LATEST = 5;
4
+ const VERSION_LATEST = 6;
5
5
  const VERSION_ACL_PATCH = 2;
6
6
  const VERSION_UPDATE_CONSTRAINT_FIELDS = 2;
7
7
  const VERSION_REMOVE_RELATION_INVERSE_SIDE = 3;
8
8
  const VERSION_REMOVE_REFERENCING_RELATIONS = 3;
9
9
  const _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE = 4;
10
10
  const VERSION_UPDATE_INDEX_FIELDS = 5;
11
+ const VERSION_CORRECT_PRIMARY_COLUMN_NAME = 6;
11
12
  exports.VERSION_ACL_PATCH = VERSION_ACL_PATCH;
13
+ exports.VERSION_CORRECT_PRIMARY_COLUMN_NAME = VERSION_CORRECT_PRIMARY_COLUMN_NAME;
12
14
  exports.VERSION_INITIAL = VERSION_INITIAL;
13
15
  exports.VERSION_LATEST = VERSION_LATEST;
14
16
  exports.VERSION_REMOVE_REFERENCING_RELATIONS = VERSION_REMOVE_REFERENCING_RELATIONS;
@@ -1 +1 @@
1
- {"version":3,"file":"ModificationVersions.cjs","sources":["../../../../../packages/schema-migrations/src/modifications/ModificationVersions.ts"],"sourcesContent":["export const VERSION_INITIAL = 1\nexport const VERSION_LATEST = 5\n\nexport const VERSION_ACL_PATCH = 2\nexport const VERSION_UPDATE_CONSTRAINT_FIELDS = 2\nexport const VERSION_REMOVE_RELATION_INVERSE_SIDE = 3\nexport const VERSION_REMOVE_REFERENCING_RELATIONS = 3\nexport const _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE = 4\nexport const VERSION_UPDATE_INDEX_FIELDS = 5\n"],"names":[],"mappings":";;AAAO,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAEvB,MAAM,oBAAoB;AAC1B,MAAM,mCAAmC;AACzC,MAAM,uCAAuC;AAC7C,MAAM,uCAAuC;AAC7C,MAAM,sDAAsD;AAC5D,MAAM,8BAA8B;;;;;;;;;"}
1
+ {"version":3,"file":"ModificationVersions.cjs","sources":["../../../../../packages/schema-migrations/src/modifications/ModificationVersions.ts"],"sourcesContent":["export const VERSION_INITIAL = 1\nexport const VERSION_LATEST = 6\n\nexport const VERSION_ACL_PATCH = 2\nexport const VERSION_UPDATE_CONSTRAINT_FIELDS = 2\nexport const VERSION_REMOVE_RELATION_INVERSE_SIDE = 3\nexport const VERSION_REMOVE_REFERENCING_RELATIONS = 3\nexport const _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE = 4\nexport const VERSION_UPDATE_INDEX_FIELDS = 5\nexport const VERSION_CORRECT_PRIMARY_COLUMN_NAME = 6\n"],"names":[],"mappings":";;AAAO,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAEvB,MAAM,oBAAoB;AAC1B,MAAM,mCAAmC;AACzC,MAAM,uCAAuC;AAC7C,MAAM,uCAAuC;AAC7C,MAAM,sDAAsD;AAC5D,MAAM,8BAA8B;AACpC,MAAM,sCAAsC;;;;;;;;;;"}
@@ -1,13 +1,15 @@
1
1
  const VERSION_INITIAL = 1;
2
- const VERSION_LATEST = 5;
2
+ const VERSION_LATEST = 6;
3
3
  const VERSION_ACL_PATCH = 2;
4
4
  const VERSION_UPDATE_CONSTRAINT_FIELDS = 2;
5
5
  const VERSION_REMOVE_RELATION_INVERSE_SIDE = 3;
6
6
  const VERSION_REMOVE_REFERENCING_RELATIONS = 3;
7
7
  const _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE = 4;
8
8
  const VERSION_UPDATE_INDEX_FIELDS = 5;
9
+ const VERSION_CORRECT_PRIMARY_COLUMN_NAME = 6;
9
10
  export {
10
11
  VERSION_ACL_PATCH,
12
+ VERSION_CORRECT_PRIMARY_COLUMN_NAME,
11
13
  VERSION_INITIAL,
12
14
  VERSION_LATEST,
13
15
  VERSION_REMOVE_REFERENCING_RELATIONS,
@@ -1 +1 @@
1
- {"version":3,"file":"ModificationVersions.js","sources":["../../../../../packages/schema-migrations/src/modifications/ModificationVersions.ts"],"sourcesContent":["export const VERSION_INITIAL = 1\nexport const VERSION_LATEST = 5\n\nexport const VERSION_ACL_PATCH = 2\nexport const VERSION_UPDATE_CONSTRAINT_FIELDS = 2\nexport const VERSION_REMOVE_RELATION_INVERSE_SIDE = 3\nexport const VERSION_REMOVE_REFERENCING_RELATIONS = 3\nexport const _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE = 4\nexport const VERSION_UPDATE_INDEX_FIELDS = 5\n"],"names":[],"mappings":"AAAO,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAEvB,MAAM,oBAAoB;AAC1B,MAAM,mCAAmC;AACzC,MAAM,uCAAuC;AAC7C,MAAM,uCAAuC;AAC7C,MAAM,sDAAsD;AAC5D,MAAM,8BAA8B;"}
1
+ {"version":3,"file":"ModificationVersions.js","sources":["../../../../../packages/schema-migrations/src/modifications/ModificationVersions.ts"],"sourcesContent":["export const VERSION_INITIAL = 1\nexport const VERSION_LATEST = 6\n\nexport const VERSION_ACL_PATCH = 2\nexport const VERSION_UPDATE_CONSTRAINT_FIELDS = 2\nexport const VERSION_REMOVE_RELATION_INVERSE_SIDE = 3\nexport const VERSION_REMOVE_REFERENCING_RELATIONS = 3\nexport const _REMOVED_VERSION_UPDATE_CONSTRAINT_NAME_ONE_HAS_ONE = 4\nexport const VERSION_UPDATE_INDEX_FIELDS = 5\nexport const VERSION_CORRECT_PRIMARY_COLUMN_NAME = 6\n"],"names":[],"mappings":"AAAO,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;AAEvB,MAAM,oBAAoB;AAC1B,MAAM,mCAAmC;AACzC,MAAM,uCAAuC;AAC7C,MAAM,uCAAuC;AAC7C,MAAM,sDAAsD;AAC5D,MAAM,8BAA8B;AACpC,MAAM,sCAAsC;"}
@@ -4,6 +4,7 @@ const schemaUpdateUtils = require("../utils/schemaUpdateUtils.cjs");
4
4
  const ModificationHandler = require("../ModificationHandler.cjs");
5
5
  const sqlUpdateUtils = require("../utils/sqlUpdateUtils.cjs");
6
6
  const columnUtils = require("../utils/columnUtils.cjs");
7
+ const ModificationVersions = require("../ModificationVersions.cjs");
7
8
  class CreateEntityModificationHandler {
8
9
  constructor(data, schema, options) {
9
10
  this.data = data;
@@ -17,8 +18,9 @@ class CreateEntityModificationHandler {
17
18
  return;
18
19
  }
19
20
  const primaryColumn = entity.fields[entity.primary];
21
+ const primaryColumnName = this.options.formatVersion >= ModificationVersions.VERSION_CORRECT_PRIMARY_COLUMN_NAME ? primaryColumn.columnName : primaryColumn.name;
20
22
  builder.createTable(entity.tableName, {
21
- [primaryColumn.name]: {
23
+ [primaryColumnName]: {
22
24
  primaryKey: true,
23
25
  type: columnUtils.getColumnSqlType(primaryColumn),
24
26
  notNull: true,
@@ -1 +1 @@
1
- {"version":3,"file":"CreateEntityModification.cjs","sources":["../../../../../../packages/schema-migrations/src/modifications/entities/CreateEntityModification.ts"],"sourcesContent":["import { MigrationBuilder } from '@contember/database-migrations'\nimport { Model, Schema } from '@contember/schema'\nimport { SchemaUpdater, updateModel } from '../utils/schemaUpdateUtils'\nimport {\n\tcreateModificationType,\n\tDiffer,\n\tModificationHandler, ModificationHandlerCreateSqlOptions,\n\tModificationHandlerOptions,\n} from '../ModificationHandler'\nimport { createEventTrigger, createEventTrxTrigger } from '../utils/sqlUpdateUtils'\nimport { PossibleEntityShapeInMigrations } from '../../utils/PartialEntity.js'\nimport { getColumnSqlType } from '../utils/columnUtils'\n\nexport class CreateEntityModificationHandler implements ModificationHandler<CreateEntityModificationData> {\n\tconstructor(\n\t\tprivate readonly data: CreateEntityModificationData,\n\t\tprivate readonly schema: Schema,\n\t\tprivate readonly options: ModificationHandlerOptions,\n\t) {}\n\n\tpublic createSql(builder: MigrationBuilder, { systemSchema }: ModificationHandlerCreateSqlOptions): void {\n\t\tconst entity = this.data.entity\n\t\tif (entity.view) {\n\t\t\t// BC\n\t\t\tbuilder.createView(entity.tableName, {}, entity.view.sql)\n\t\t\treturn\n\t\t}\n\t\tconst primaryColumn = entity.fields[entity.primary] as Model.AnyColumn\n\n\t\tbuilder.createTable(entity.tableName, {\n\t\t\t[primaryColumn.name]: {\n\t\t\t\tprimaryKey: true,\n\t\t\t\ttype: getColumnSqlType(primaryColumn),\n\t\t\t\tnotNull: true,\n\t\t\t\tsequenceGenerated: primaryColumn.sequence,\n\t\t\t},\n\t\t})\n\n\t\tif (entity.eventLog?.enabled !== false) {\n\t\t\tcreateEventTrigger(builder, systemSchema, entity.tableName, [entity.primaryColumn])\n\t\t\tcreateEventTrxTrigger(builder, systemSchema, entity.tableName)\n\t\t}\n\t}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn updateModel(({ model }) => ({\n\t\t\t...model,\n\t\t\tentities: {\n\t\t\t\t...model.entities,\n\t\t\t\t[this.data.entity.name]: {\n\t\t\t\t\teventLog: { enabled: true },\n\t\t\t\t\t...this.data.entity,\n\t\t\t\t\tunique: Object.values(this.data.entity.unique),\n\t\t\t\t\tindexes: Object.values(this.data.entity.indexes ?? []),\n\t\t\t\t},\n\t\t\t},\n\t\t}))\n\t}\n\n\n\tdescribe() {\n\t\treturn { message: `Add entity ${this.data.entity.name}` }\n\t}\n\n}\n\nexport const createEntityModification = createModificationType({\n\tid: 'createEntity',\n\thandler: CreateEntityModificationHandler,\n})\n\nexport class CreateEntityDiffer implements Differ {\n\tcreateDiff(originalSchema: Schema, updatedSchema: Schema) {\n\t\treturn Object.values(updatedSchema.model.entities)\n\t\t\t.filter(it => !originalSchema.model.entities[it.name])\n\t\t\t.filter(it => !it.view)\n\t\t\t.map(entity =>\n\t\t\t\tcreateEntityModification.createModification({\n\t\t\t\t\tentity: {\n\t\t\t\t\t\t...entity,\n\t\t\t\t\t\tfields: {\n\t\t\t\t\t\t\t[entity.primary]: entity.fields[entity.primary],\n\t\t\t\t\t\t},\n\t\t\t\t\t\tunique: [],\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t)\n\t}\n}\n\nexport interface CreateEntityModificationData {\n\tentity: PossibleEntityShapeInMigrations\n}\n"],"names":["getColumnSqlType","createEventTrigger","createEventTrxTrigger","updateModel","createModificationType"],"mappings":";;;;;;AAaO,MAAM,gCAA6F;AAAA,EACzG,YACkB,MACA,QACA,SAChB;AAHgB,SAAA,OAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AAAA,EAAA;AAAA,EAGX,UAAU,SAA2B,EAAE,gBAA2D;AAClG,UAAA,SAAS,KAAK,KAAK;AACzB,QAAI,OAAO,M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S,GAAG,IAAI,CAAC,EACpD,OAAO,CAAM,OAAA,CAAC,GAAG,IAAI,EACrB;AAAA,MAAI,CAAA,WACJ,yBAAyB,mBAAmB;AAAA,QAC3C,QAAQ;AAAA,UACP,GAAG;AAAA,UACH,QAAQ;AAAA,YACP,CAAC,OAAO,OAAO,GAAG,OAAO,OAAO,OAAO,OAAO;AAAA,UAC/C;AAAA,UACA,QAAQ,CAAA;AAAA,QAAC;AAAA,MAEV,CAAA;AAAA,IACF;AAAA,EAAA;AAEH;;;;"}
1
+ {"version":3,"file":"CreateEntityModification.cjs","sources":["../../../../../../packages/schema-migrations/src/modifications/entities/CreateEntityModification.ts"],"sourcesContent":["import { MigrationBuilder } from '@contember/database-migrations'\nimport { Model, Schema } from '@contember/schema'\nimport { SchemaUpdater, updateModel } from '../utils/schemaUpdateUtils'\nimport {\n\tcreateModificationType,\n\tDiffer,\n\tModificationHandler, ModificationHandlerCreateSqlOptions,\n\tModificationHandlerOptions,\n} from '../ModificationHandler'\nimport { createEventTrigger, createEventTrxTrigger } from '../utils/sqlUpdateUtils'\nimport { PossibleEntityShapeInMigrations } from '../../utils/PartialEntity.js'\nimport { getColumnSqlType } from '../utils/columnUtils'\nimport { VERSION_CORRECT_PRIMARY_COLUMN_NAME } from '../ModificationVersions'\n\nexport class CreateEntityModificationHandler implements ModificationHandler<CreateEntityModificationData> {\n\tconstructor(\n\t\tprivate readonly data: CreateEntityModificationData,\n\t\tprivate readonly schema: Schema,\n\t\tprivate readonly options: ModificationHandlerOptions,\n\t) {}\n\n\tpublic createSql(builder: MigrationBuilder, { systemSchema }: ModificationHandlerCreateSqlOptions): void {\n\t\tconst entity = this.data.entity\n\t\tif (entity.view) {\n\t\t\t// BC\n\t\t\tbuilder.createView(entity.tableName, {}, entity.view.sql)\n\t\t\treturn\n\t\t}\n\t\tconst primaryColumn = entity.fields[entity.primary] as Model.AnyColumn\n\n\t\tconst primaryColumnName = this.options.formatVersion >= VERSION_CORRECT_PRIMARY_COLUMN_NAME\n\t\t\t? primaryColumn.columnName\n\t\t\t: primaryColumn.name\n\t\tbuilder.createTable(entity.tableName, {\n\t\t\t[primaryColumnName]: {\n\t\t\t\tprimaryKey: true,\n\t\t\t\ttype: getColumnSqlType(primaryColumn),\n\t\t\t\tnotNull: true,\n\t\t\t\tsequenceGenerated: primaryColumn.sequence,\n\t\t\t},\n\t\t})\n\n\t\tif (entity.eventLog?.enabled !== false) {\n\t\t\tcreateEventTrigger(builder, systemSchema, entity.tableName, [entity.primaryColumn])\n\t\t\tcreateEventTrxTrigger(builder, systemSchema, entity.tableName)\n\t\t}\n\t}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn updateModel(({ model }) => ({\n\t\t\t...model,\n\t\t\tentities: {\n\t\t\t\t...model.entities,\n\t\t\t\t[this.data.entity.name]: {\n\t\t\t\t\teventLog: { enabled: true },\n\t\t\t\t\t...this.data.entity,\n\t\t\t\t\tunique: Object.values(this.data.entity.unique),\n\t\t\t\t\tindexes: Object.values(this.data.entity.indexes ?? []),\n\t\t\t\t},\n\t\t\t},\n\t\t}))\n\t}\n\n\n\tdescribe() {\n\t\treturn { message: `Add entity ${this.data.entity.name}` }\n\t}\n\n}\n\nexport const createEntityModification = createModificationType({\n\tid: 'createEntity',\n\thandler: CreateEntityModificationHandler,\n})\n\nexport class CreateEntityDiffer implements Differ {\n\tcreateDiff(originalSchema: Schema, updatedSchema: Schema) {\n\t\treturn Object.values(updatedSchema.model.entities)\n\t\t\t.filter(it => !originalSchema.model.entities[it.name])\n\t\t\t.filter(it => !it.view)\n\t\t\t.map(entity =>\n\t\t\t\tcreateEntityModification.createModification({\n\t\t\t\t\tentity: {\n\t\t\t\t\t\t...entity,\n\t\t\t\t\t\tfields: {\n\t\t\t\t\t\t\t[entity.primary]: entity.fields[entity.primary],\n\t\t\t\t\t\t},\n\t\t\t\t\t\tunique: [],\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t)\n\t}\n}\n\nexport interface CreateEntityModificationData {\n\tentity: PossibleEntityShapeInMigrations\n}\n"],"names":["VERSION_CORRECT_PRIMARY_COLUMN_NAME","getColumnSqlType","createEventTrigger","createEventTrxTrigger","updateModel","createModificationType"],"mappings":";;;;;;;AAcO,MAAM,gCAA6F;AAAA,EACzG,YACkB,MACA,QACA,SAChB;AAHgB,SAAA,OAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AAAA,EAAA;AAAA,EAGX,UAAU,SAA2B,EAAE,gBAA2D;AAClG,UAAA,SAAS,KAAK,KAAK;AACzB,QAAI,OAAO,MAAM;AAEhB,cAAQ,WAAW,OAAO,WAAW,CAAA,GAAI,OAAO,KAAK,GAAG;AACxD;AAAA,IAAA;AAED,UAAM,gBAAgB,OAAO,OAAO,OAAO,OAAO;AAElD,UAAM,oBAAoB,KAAK,QAAQ,iBAAiBA,qBAAAA,sCACrD,cAAc,aACd,cAAc;AACT,YAAA,YAAY,OAAO,WAAW;AAAA,MACrC,CAAC,iBAAiB,GAAG;AAAA,QACpB,YAAY;AAAA,QACZ,MAAMC,6BAAiB,aAAa;AAAA,QACpC,SAAS;AAAA,QACT,mBAAmB,cAAc;AAAA,MAAA;AAAA,IAClC,CACA;AAEI,QAAA,OAAO,UAAU,YAAY,OAAO;AACxCC,qBAAA,mBAAmB,SAAS,cAAc,OAAO,WAAW,CAAC,OAAO,aAAa,CAAC;AAC5DC,qBAAAA,sBAAA,SAAS,cAAc,OAAO,SAAS;AAAA,IAAA;AAAA,EAC9D;AAAA,EAGM,mBAAkC;AACxC,WAAOC,kBAAY,YAAA,CAAC,EAAE,aAAa;AAAA,MAClC,GAAG;AAAA,MACH,UAAU;AAAA,QACT,GAAG,MAAM;AAAA,QACT,CAAC,KAAK,KAAK,OAAO,IAAI,GAAG;AAAA,UACxB,UAAU,EAAE,SAAS,KAAK;AAAA,UAC1B,GAAG,KAAK,KAAK;AAAA,UACb,QAAQ,OAAO,OAAO,KAAK,KAAK,OAAO,MAAM;AAAA,UAC7C,SAAS,OAAO,OAAO,KAAK,KAAK,OAAO,WAAW,CAAE,CAAA;AAAA,QAAA;AAAA,MACtD;AAAA,IACD,EACC;AAAA,EAAA;AAAA,EAIH,WAAW;AACV,WAAO,EAAE,SAAS,cAAc,KAAK,KAAK,OAAO,IAAI,GAAG;AAAA,EAAA;AAG1D;AAEO,MAAM,2BAA2BC,oBAAAA,uBAAuB;AAAA,EAC9D,IAAI;AAAA,EACJ,SAAS;AACV,CAAC;AAEM,MAAM,mBAAqC;AAAA,EACjD,WAAW,gBAAwB,eAAuB;AAClD,WAAA,OAAO,OAAO,cAAc,MAAM,QAAQ,EAC/C,OAAO,QAAM,CAAC,eAAe,MAAM,SAAS,GAAG,IAAI,CAAC,EACpD,OAAO,CAAM,OAAA,CAAC,GAAG,IAAI,EACrB;AAAA,MAAI,CAAA,WACJ,yBAAyB,mBAAmB;AAAA,QAC3C,QAAQ;AAAA,UACP,GAAG;AAAA,UACH,QAAQ;AAAA,YACP,CAAC,OAAO,OAAO,GAAG,OAAO,OAAO,OAAO,OAAO;AAAA,UAC/C;AAAA,UACA,QAAQ,CAAA;AAAA,QAAC;AAAA,MAEV,CAAA;AAAA,IACF;AAAA,EAAA;AAEH;;;;"}
@@ -2,6 +2,7 @@ import { updateModel } from "../utils/schemaUpdateUtils.js";
2
2
  import { createModificationType } from "../ModificationHandler.js";
3
3
  import { createEventTrigger, createEventTrxTrigger } from "../utils/sqlUpdateUtils.js";
4
4
  import { getColumnSqlType } from "../utils/columnUtils.js";
5
+ import { VERSION_CORRECT_PRIMARY_COLUMN_NAME } from "../ModificationVersions.js";
5
6
  class CreateEntityModificationHandler {
6
7
  constructor(data, schema, options) {
7
8
  this.data = data;
@@ -15,8 +16,9 @@ class CreateEntityModificationHandler {
15
16
  return;
16
17
  }
17
18
  const primaryColumn = entity.fields[entity.primary];
19
+ const primaryColumnName = this.options.formatVersion >= VERSION_CORRECT_PRIMARY_COLUMN_NAME ? primaryColumn.columnName : primaryColumn.name;
18
20
  builder.createTable(entity.tableName, {
19
- [primaryColumn.name]: {
21
+ [primaryColumnName]: {
20
22
  primaryKey: true,
21
23
  type: getColumnSqlType(primaryColumn),
22
24
  notNull: true,
@@ -1 +1 @@
1
- {"version":3,"file":"CreateEntityModification.js","sources":["../../../../../../packages/schema-migrations/src/modifications/entities/CreateEntityModification.ts"],"sourcesContent":["import { MigrationBuilder } from '@contember/database-migrations'\nimport { Model, Schema } from '@contember/schema'\nimport { SchemaUpdater, updateModel } from '../utils/schemaUpdateUtils'\nimport {\n\tcreateModificationType,\n\tDiffer,\n\tModificationHandler, ModificationHandlerCreateSqlOptions,\n\tModificationHandlerOptions,\n} from '../ModificationHandler'\nimport { createEventTrigger, createEventTrxTrigger } from '../utils/sqlUpdateUtils'\nimport { PossibleEntityShapeInMigrations } from '../../utils/PartialEntity.js'\nimport { getColumnSqlType } from '../utils/columnUtils'\n\nexport class CreateEntityModificationHandler implements ModificationHandler<CreateEntityModificationData> {\n\tconstructor(\n\t\tprivate readonly data: CreateEntityModificationData,\n\t\tprivate readonly schema: Schema,\n\t\tprivate readonly options: ModificationHandlerOptions,\n\t) {}\n\n\tpublic createSql(builder: MigrationBuilder, { systemSchema }: ModificationHandlerCreateSqlOptions): void {\n\t\tconst entity = this.data.entity\n\t\tif (entity.view) {\n\t\t\t// BC\n\t\t\tbuilder.createView(entity.tableName, {}, entity.view.sql)\n\t\t\treturn\n\t\t}\n\t\tconst primaryColumn = entity.fields[entity.primary] as Model.AnyColumn\n\n\t\tbuilder.createTable(entity.tableName, {\n\t\t\t[primaryColumn.name]: {\n\t\t\t\tprimaryKey: true,\n\t\t\t\ttype: getColumnSqlType(primaryColumn),\n\t\t\t\tnotNull: true,\n\t\t\t\tsequenceGenerated: primaryColumn.sequence,\n\t\t\t},\n\t\t})\n\n\t\tif (entity.eventLog?.enabled !== false) {\n\t\t\tcreateEventTrigger(builder, systemSchema, entity.tableName, [entity.primaryColumn])\n\t\t\tcreateEventTrxTrigger(builder, systemSchema, entity.tableName)\n\t\t}\n\t}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn updateModel(({ model }) => ({\n\t\t\t...model,\n\t\t\tentities: {\n\t\t\t\t...model.entities,\n\t\t\t\t[this.data.entity.name]: {\n\t\t\t\t\teventLog: { enabled: true },\n\t\t\t\t\t...this.data.entity,\n\t\t\t\t\tunique: Object.values(this.data.entity.unique),\n\t\t\t\t\tindexes: Object.values(this.data.entity.indexes ?? []),\n\t\t\t\t},\n\t\t\t},\n\t\t}))\n\t}\n\n\n\tdescribe() {\n\t\treturn { message: `Add entity ${this.data.entity.name}` }\n\t}\n\n}\n\nexport const createEntityModification = createModificationType({\n\tid: 'createEntity',\n\thandler: CreateEntityModificationHandler,\n})\n\nexport class CreateEntityDiffer implements Differ {\n\tcreateDiff(originalSchema: Schema, updatedSchema: Schema) {\n\t\treturn Object.values(updatedSchema.model.entities)\n\t\t\t.filter(it => !originalSchema.model.entities[it.name])\n\t\t\t.filter(it => !it.view)\n\t\t\t.map(entity =>\n\t\t\t\tcreateEntityModification.createModification({\n\t\t\t\t\tentity: {\n\t\t\t\t\t\t...entity,\n\t\t\t\t\t\tfields: {\n\t\t\t\t\t\t\t[entity.primary]: entity.fields[entity.primary],\n\t\t\t\t\t\t},\n\t\t\t\t\t\tunique: [],\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t)\n\t}\n}\n\nexport interface CreateEntityModificationData {\n\tentity: PossibleEntityShapeInMigrations\n}\n"],"names":[],"mappings":";;;;AAaO,MAAM,gCAA6F;AAAA,EACzG,YACkB,MACA,QACA,SAChB;AAHgB,SAAA,OAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AAAA,EAAA;AAAA,EAGX,UAAU,SAA2B,EAAE,gBAA2D;AAClG,UAAA,SAAS,KAAK,KAAK;AACzB,QAAI,OAAO,MAAM;AAEhB,cAAQ,WAAW,OAAO,WAAW,CAAA,GAAI,OAAO,KAAK,GAAG;AACxD;AAAA,IAAA;AAED,UAAM,gBAAgB,O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AG;AAAA,UACH,QAAQ;AAAA,YACP,CAAC,OAAO,OAAO,GAAG,OAAO,OAAO,OAAO,OAAO;AAAA,UAC/C;AAAA,UACA,QAAQ,CAAA;AAAA,QAAC;AAAA,MAEV,CAAA;AAAA,IACF;AAAA,EAAA;AAEH;"}
1
+ {"version":3,"file":"CreateEntityModification.js","sources":["../../../../../../packages/schema-migrations/src/modifications/entities/CreateEntityModification.ts"],"sourcesContent":["import { MigrationBuilder } from '@contember/database-migrations'\nimport { Model, Schema } from '@contember/schema'\nimport { SchemaUpdater, updateModel } from '../utils/schemaUpdateUtils'\nimport {\n\tcreateModificationType,\n\tDiffer,\n\tModificationHandler, ModificationHandlerCreateSqlOptions,\n\tModificationHandlerOptions,\n} from '../ModificationHandler'\nimport { createEventTrigger, createEventTrxTrigger } from '../utils/sqlUpdateUtils'\nimport { PossibleEntityShapeInMigrations } from '../../utils/PartialEntity.js'\nimport { getColumnSqlType } from '../utils/columnUtils'\nimport { VERSION_CORRECT_PRIMARY_COLUMN_NAME } from '../ModificationVersions'\n\nexport class CreateEntityModificationHandler implements ModificationHandler<CreateEntityModificationData> {\n\tconstructor(\n\t\tprivate readonly data: CreateEntityModificationData,\n\t\tprivate readonly schema: Schema,\n\t\tprivate readonly options: ModificationHandlerOptions,\n\t) {}\n\n\tpublic createSql(builder: MigrationBuilder, { systemSchema }: ModificationHandlerCreateSqlOptions): void {\n\t\tconst entity = this.data.entity\n\t\tif (entity.view) {\n\t\t\t// BC\n\t\t\tbuilder.createView(entity.tableName, {}, entity.view.sql)\n\t\t\treturn\n\t\t}\n\t\tconst primaryColumn = entity.fields[entity.primary] as Model.AnyColumn\n\n\t\tconst primaryColumnName = this.options.formatVersion >= VERSION_CORRECT_PRIMARY_COLUMN_NAME\n\t\t\t? primaryColumn.columnName\n\t\t\t: primaryColumn.name\n\t\tbuilder.createTable(entity.tableName, {\n\t\t\t[primaryColumnName]: {\n\t\t\t\tprimaryKey: true,\n\t\t\t\ttype: getColumnSqlType(primaryColumn),\n\t\t\t\tnotNull: true,\n\t\t\t\tsequenceGenerated: primaryColumn.sequence,\n\t\t\t},\n\t\t})\n\n\t\tif (entity.eventLog?.enabled !== false) {\n\t\t\tcreateEventTrigger(builder, systemSchema, entity.tableName, [entity.primaryColumn])\n\t\t\tcreateEventTrxTrigger(builder, systemSchema, entity.tableName)\n\t\t}\n\t}\n\n\tpublic getSchemaUpdater(): SchemaUpdater {\n\t\treturn updateModel(({ model }) => ({\n\t\t\t...model,\n\t\t\tentities: {\n\t\t\t\t...model.entities,\n\t\t\t\t[this.data.entity.name]: {\n\t\t\t\t\teventLog: { enabled: true },\n\t\t\t\t\t...this.data.entity,\n\t\t\t\t\tunique: Object.values(this.data.entity.unique),\n\t\t\t\t\tindexes: Object.values(this.data.entity.indexes ?? []),\n\t\t\t\t},\n\t\t\t},\n\t\t}))\n\t}\n\n\n\tdescribe() {\n\t\treturn { message: `Add entity ${this.data.entity.name}` }\n\t}\n\n}\n\nexport const createEntityModification = createModificationType({\n\tid: 'createEntity',\n\thandler: CreateEntityModificationHandler,\n})\n\nexport class CreateEntityDiffer implements Differ {\n\tcreateDiff(originalSchema: Schema, updatedSchema: Schema) {\n\t\treturn Object.values(updatedSchema.model.entities)\n\t\t\t.filter(it => !originalSchema.model.entities[it.name])\n\t\t\t.filter(it => !it.view)\n\t\t\t.map(entity =>\n\t\t\t\tcreateEntityModification.createModification({\n\t\t\t\t\tentity: {\n\t\t\t\t\t\t...entity,\n\t\t\t\t\t\tfields: {\n\t\t\t\t\t\t\t[entity.primary]: entity.fields[entity.primary],\n\t\t\t\t\t\t},\n\t\t\t\t\t\tunique: [],\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t)\n\t}\n}\n\nexport interface CreateEntityModificationData {\n\tentity: PossibleEntityShapeInMigrations\n}\n"],"names":[],"mappings":";;;;;AAcO,MAAM,gCAA6F;AAAA,EACzG,YACkB,MACA,QACA,SAChB;AAHgB,SAAA,OAAA;AACA,SAAA,SAAA;AAC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AAEM,MAAM,mBAAqC;AAAA,EACjD,WAAW,gBAAwB,eAAuB;AAClD,WAAA,OAAO,OAAO,cAAc,MAAM,QAAQ,EAC/C,OAAO,QAAM,CAAC,eAAe,MAAM,SAAS,GAAG,IAAI,CAAC,EACpD,OAAO,CAAM,OAAA,CAAC,GAAG,IAAI,EACrB;AAAA,MAAI,CAAA,WACJ,yBAAyB,mBAAmB;AAAA,QAC3C,QAAQ;AAAA,UACP,GAAG;AAAA,UACH,QAAQ;AAAA,YACP,CAAC,OAAO,OAAO,GAAG,OAAO,OAAO,OAAO,OAAO;AAAA,UAC/C;AAAA,UACA,QAAQ,CAAA;AAAA,QAAC;AAAA,MAEV,CAAA;AAAA,IACF;AAAA,EAAA;AAEH;"}
@@ -47,9 +47,10 @@ const updateAclFieldPermissions = (updater) => ({ entityPermissions, entityName
47
47
  update: (value) => updater(value, entityName, schema.Acl.Operation.update),
48
48
  read: (value) => updater(value, entityName, schema.Acl.Operation.read),
49
49
  delete: (value) => value,
50
- customPrimary: (value) => value
50
+ customPrimary: (value) => value,
51
+ noRoot: (value) => value
51
52
  };
52
- const types = ["create", "update", "read", "delete", "customPrimary"];
53
+ const types = ["create", "update", "read", "delete", "customPrimary", "noRoot"];
53
54
  for (const key of types) {
54
55
  if (key in entityPermissions.operations) {
55
56
  operations[key] = handlers[key](entityPermissions.operations[key]);