@flusys/nestjs-entity-builder 9.2.0 → 9.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -22
- package/config/entity-builder.constants.d.ts +1 -0
- package/config/message-keys.d.ts +11 -2
- package/controllers/definition-bundle.controller.d.ts +2 -2
- package/controllers/entity-definition.controller.d.ts +0 -1
- package/controllers/field-definition.controller.d.ts +0 -1
- package/controllers/flow-definition.controller.d.ts +2 -1
- package/controllers/flow-runtime.controller.d.ts +4 -3
- package/fesm/21.js +13 -5
- package/fesm/{458.js → 28.js} +104 -62
- package/fesm/677.js +1234 -469
- package/fesm/794.js +1 -1
- package/fesm/857.js +1 -2
- package/fesm/870.js +415 -332
- package/fesm/897.js +23 -29
- package/fesm/946.js +67 -42
- package/fesm/config/index.js +10 -14
- package/fesm/docs/index.js +1 -1
- package/fesm/guards/index.js +15 -9
- package/fesm/index.js +25 -25
- package/fesm/modules/index.js +4 -3
- package/fesm/services/index.js +29 -58
- package/flow-engine/flow-code-runner.d.ts +16 -0
- package/flow-engine/flow-graph.validator.d.ts +1 -0
- package/flow-engine/flow-input.validator.d.ts +14 -0
- package/flow-engine/flow-run.types.d.ts +15 -0
- package/flow-engine/flow.types.d.ts +1 -1
- package/guards/designer-writable.interceptor.d.ts +1 -0
- package/interfaces/definition-bundle.interface.d.ts +2 -0
- package/interfaces/entity-builder-module.interface.d.ts +9 -0
- package/modules/entity-builder.module.d.ts +1 -0
- package/modules/index.d.ts +1 -0
- package/modules/tenant-context-id.strategy.d.ts +16 -0
- package/package.json +3 -4
- package/services/definition-bundle.diff.d.ts +0 -2
- package/services/definition-bundle.file.d.ts +2 -1
- package/services/definition-bundle.service.d.ts +0 -1
- package/services/entity-builder-config.service.d.ts +3 -0
- package/services/entity-builder-datasource.provider.d.ts +1 -0
- package/services/field-value-validator.d.ts +7 -0
- package/services/flow-definition.service.d.ts +10 -2
- package/services/flow-executor.service.d.ts +3 -0
- package/services/flow-runtime.service.d.ts +6 -1
- package/services/generic-entity-service.factory.d.ts +5 -1
- package/services/generic-entity.service.d.ts +24 -2
- package/services/identifier-rules.d.ts +0 -1
- package/services/save-loaded.d.ts +2 -0
- package/services/schema-columns.d.ts +7 -2
- package/services/schema-evolution.service.d.ts +8 -2
- package/services/schema-registry.service.d.ts +12 -0
- package/services/schema-sync.service.d.ts +3 -1
- package/flow-engine/flow-code-sandbox.d.ts +0 -5
package/fesm/870.js
CHANGED
|
@@ -472,13 +472,15 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
472
472
|
3801(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
473
473
|
/* import */ var _flusys_nestjs_shared_utils__rspack_import_0 = __webpack_require__(9216);
|
|
474
474
|
/* import */ var node_crypto__rspack_import_1 = __webpack_require__(2561);
|
|
475
|
-
/* import */ var
|
|
476
|
-
/* import */ var
|
|
477
|
-
/* import */ var
|
|
475
|
+
/* import */ var _config_message_keys_js__rspack_import_7 = __webpack_require__(5732);
|
|
476
|
+
/* import */ var _enums_entity_status_enum_js__rspack_import_8 = __webpack_require__(1313);
|
|
477
|
+
/* import */ var _enums_field_type_enum_js__rspack_import_9 = __webpack_require__(9614);
|
|
478
478
|
/* import */ var _flow_engine_flow_types_js__rspack_import_2 = __webpack_require__(6256);
|
|
479
479
|
/* import */ var _rule_engine_rule_permission_js__rspack_import_3 = __webpack_require__(5191);
|
|
480
480
|
/* import */ var _rule_engine_rule_interface_js__rspack_import_4 = __webpack_require__(2354);
|
|
481
481
|
/* import */ var _flow_definition_service_js__rspack_import_5 = __webpack_require__(5229);
|
|
482
|
+
/* import */ var _reference_rewrite_js__rspack_import_6 = __webpack_require__(3086);
|
|
483
|
+
|
|
482
484
|
|
|
483
485
|
|
|
484
486
|
|
|
@@ -518,22 +520,10 @@ const bundleChecksum = (bundle)=>(0,node_crypto__rspack_import_1.createHash)('sh
|
|
|
518
520
|
}
|
|
519
521
|
const VARIABLE_PATTERN = /\$\{var:([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
520
522
|
/** Shorter values would be replaced inside unrelated text. */ const MIN_VARIABLE_VALUE_LENGTH = 4;
|
|
521
|
-
function mapStrings(value, fn) {
|
|
522
|
-
if (typeof value === 'string') return fn(value);
|
|
523
|
-
if (Array.isArray(value)) return value.map((item)=>mapStrings(item, fn));
|
|
524
|
-
if (value && typeof value === 'object') {
|
|
525
|
-
return Object.fromEntries(Object.entries(value).map(([key, item])=>[
|
|
526
|
-
key,
|
|
527
|
-
mapStrings(item, fn)
|
|
528
|
-
]));
|
|
529
|
-
}
|
|
530
|
-
return value;
|
|
531
|
-
}
|
|
532
523
|
/** Only a step's settings hold environment values: its id, type, name and position are never rewritten. */ const mapConfigStrings = (nodes, fn)=>nodes.map((node)=>node?.config ? {
|
|
533
524
|
...node,
|
|
534
|
-
config: mapStrings(node.config, fn)
|
|
525
|
+
config: (0,_reference_rewrite_js__rspack_import_6/* .mapStrings */.to)(node.config, fn)
|
|
535
526
|
} : node);
|
|
536
|
-
const escapeRegExp = (text)=>text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
537
527
|
/**
|
|
538
528
|
* Export: every occurrence of this environment's variable values in a step's settings becomes `${var:NAME}`
|
|
539
529
|
* (longest value first; one pass, so a placeholder already written is never rewritten by a shorter value).
|
|
@@ -545,7 +535,7 @@ const escapeRegExp = (text)=>text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
|
545
535
|
if (!nameOf.size) return nodes;
|
|
546
536
|
const pattern = new RegExp([
|
|
547
537
|
...nameOf.keys()
|
|
548
|
-
].map(
|
|
538
|
+
].map(_reference_rewrite_js__rspack_import_6/* .escapeRe */.NF).join('|'), 'g');
|
|
549
539
|
return mapConfigStrings(nodes, (text)=>text.replace(pattern, (value)=>`\${var:${nameOf.get(value)}}`));
|
|
550
540
|
}
|
|
551
541
|
/** Import: `${var:NAME}` in a step's settings becomes this environment's value; names it does not define are returned, not replaced. */ function applyVariables(nodes, variables) {
|
|
@@ -710,17 +700,17 @@ function changedValues(from, to, keys) {
|
|
|
710
700
|
const problems = [];
|
|
711
701
|
const codes = new Set();
|
|
712
702
|
for (const entity of entities){
|
|
713
|
-
if (codes.has(entity.code)) problems.push((0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(
|
|
703
|
+
if (codes.has(entity.code)) problems.push((0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(_config_message_keys_js__rspack_import_7/* .BUNDLE_MESSAGES.DUPLICATE_ENTITY */.iX.DUPLICATE_ENTITY, {
|
|
714
704
|
entity: entity.code
|
|
715
705
|
}));
|
|
716
|
-
if (entity.status ===
|
|
706
|
+
if (entity.status === _enums_entity_status_enum_js__rspack_import_8/* .EntityStatus.DRAFT */.c.DRAFT) problems.push((0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(_config_message_keys_js__rspack_import_7/* .BUNDLE_MESSAGES.ENTITY_DRAFT_IN_BUNDLE */.iX.ENTITY_DRAFT_IN_BUNDLE, {
|
|
717
707
|
entity: entity.code
|
|
718
708
|
}));
|
|
719
709
|
codes.add(entity.code);
|
|
720
710
|
const fieldCodes = new Set();
|
|
721
711
|
const fieldIds = new Set();
|
|
722
712
|
for (const field of entity.fields){
|
|
723
|
-
if (fieldCodes.has(field.code) || fieldIds.has(field.id)) problems.push((0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(
|
|
713
|
+
if (fieldCodes.has(field.code) || fieldIds.has(field.id)) problems.push((0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(_config_message_keys_js__rspack_import_7/* .BUNDLE_MESSAGES.DUPLICATE_FIELD */.iX.DUPLICATE_FIELD, {
|
|
724
714
|
entity: entity.code,
|
|
725
715
|
field: field.code
|
|
726
716
|
}));
|
|
@@ -733,9 +723,9 @@ function changedValues(from, to, keys) {
|
|
|
733
723
|
...current.map((e)=>e.code)
|
|
734
724
|
]);
|
|
735
725
|
for (const entity of entities){
|
|
736
|
-
for (const field of entity.fields.filter((f)=>f.fieldType ===
|
|
726
|
+
for (const field of entity.fields.filter((f)=>f.fieldType === _enums_field_type_enum_js__rspack_import_9/* .FieldType.RELATION */.P.RELATION && !f.deprecated)){
|
|
737
727
|
if (!field.relationTarget || !known.has(field.relationTarget)) {
|
|
738
|
-
problems.push((0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(
|
|
728
|
+
problems.push((0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(_config_message_keys_js__rspack_import_7/* .BUNDLE_MESSAGES.RELATION_TARGET_UNKNOWN */.iX.RELATION_TARGET_UNKNOWN, {
|
|
739
729
|
entity: entity.code,
|
|
740
730
|
field: field.code,
|
|
741
731
|
target: field.relationTarget ?? ''
|
|
@@ -793,7 +783,7 @@ function changedValues(from, to, keys) {
|
|
|
793
783
|
const first = pending[0];
|
|
794
784
|
const temporary = temporaryCode(first.targetFieldId, taken);
|
|
795
785
|
ordered.push(step(first, first.from, temporary, first.restored || first.waited, [
|
|
796
|
-
(0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(
|
|
786
|
+
(0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(_config_message_keys_js__rspack_import_7/* .BUNDLE_MESSAGES.RENAME_VIA_TEMPORARY */.iX.RENAME_VIA_TEMPORARY, {
|
|
797
787
|
field: first.from,
|
|
798
788
|
temporary,
|
|
799
789
|
to: first.to
|
|
@@ -837,7 +827,7 @@ function changedValues(from, to, keys) {
|
|
|
837
827
|
for (const entity of sorted){
|
|
838
828
|
const target = pairs.get(entity);
|
|
839
829
|
if (target && target.code !== entity.code) {
|
|
840
|
-
result.blockers.push((0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(
|
|
830
|
+
result.blockers.push((0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(_config_message_keys_js__rspack_import_7/* .BUNDLE_MESSAGES.ENTITY_CODE_CHANGED */.iX.ENTITY_CODE_CHANGED, {
|
|
841
831
|
entity: entity.code,
|
|
842
832
|
current: target.code
|
|
843
833
|
}));
|
|
@@ -849,15 +839,15 @@ function changedValues(from, to, keys) {
|
|
|
849
839
|
kind: 'create_entity',
|
|
850
840
|
entityCode: entity.code,
|
|
851
841
|
details: {
|
|
852
|
-
fields: live.filter((f)=>f.fieldType !==
|
|
842
|
+
fields: live.filter((f)=>f.fieldType !== _enums_field_type_enum_js__rspack_import_9/* .FieldType.RELATION */.P.RELATION).map((f)=>f.code)
|
|
853
843
|
},
|
|
854
844
|
dependsOnEarlierStep: false,
|
|
855
845
|
entity: {
|
|
856
846
|
...entity,
|
|
857
|
-
fields: live.filter((f)=>f.fieldType !==
|
|
847
|
+
fields: live.filter((f)=>f.fieldType !== _enums_field_type_enum_js__rspack_import_9/* .FieldType.RELATION */.P.RELATION)
|
|
858
848
|
}
|
|
859
849
|
});
|
|
860
|
-
for (const field of live.filter((f)=>f.fieldType ===
|
|
850
|
+
for (const field of live.filter((f)=>f.fieldType === _enums_field_type_enum_js__rspack_import_9/* .FieldType.RELATION */.P.RELATION)){
|
|
861
851
|
relationAdds.push({
|
|
862
852
|
kind: 'add_field',
|
|
863
853
|
entityCode: entity.code,
|
|
@@ -870,7 +860,7 @@ function changedValues(from, to, keys) {
|
|
|
870
860
|
field
|
|
871
861
|
});
|
|
872
862
|
}
|
|
873
|
-
if (entity.status ===
|
|
863
|
+
if (entity.status === _enums_entity_status_enum_js__rspack_import_8/* .EntityStatus.DEPRECATED */.c.DEPRECATED) {
|
|
874
864
|
entityUpdatesLast.push({
|
|
875
865
|
kind: 'update_entity',
|
|
876
866
|
entityCode: entity.code,
|
|
@@ -881,20 +871,20 @@ function changedValues(from, to, keys) {
|
|
|
881
871
|
},
|
|
882
872
|
dependsOnEarlierStep: true,
|
|
883
873
|
changes: {
|
|
884
|
-
status:
|
|
874
|
+
status: _enums_entity_status_enum_js__rspack_import_8/* .EntityStatus.DEPRECATED */.c.DEPRECATED
|
|
885
875
|
}
|
|
886
876
|
});
|
|
887
877
|
}
|
|
888
878
|
continue;
|
|
889
879
|
}
|
|
890
|
-
if (target.status ===
|
|
891
|
-
result.blockers.push((0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(
|
|
880
|
+
if (target.status === _enums_entity_status_enum_js__rspack_import_8/* .EntityStatus.DRAFT */.c.DRAFT) {
|
|
881
|
+
result.blockers.push((0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(_config_message_keys_js__rspack_import_7/* .BUNDLE_MESSAGES.ENTITY_DRAFT_HERE */.iX.ENTITY_DRAFT_HERE, {
|
|
892
882
|
entity: entity.code
|
|
893
883
|
}));
|
|
894
884
|
continue;
|
|
895
885
|
}
|
|
896
886
|
const entityChanges = changedValues(target, entity, ENTITY_COMPARED_KEYS);
|
|
897
|
-
const deprecating = entityChanges['status'] ===
|
|
887
|
+
const deprecating = entityChanges['status'] === _enums_entity_status_enum_js__rspack_import_8/* .EntityStatus.DEPRECATED */.c.DEPRECATED;
|
|
898
888
|
if (Object.keys(entityChanges).length) {
|
|
899
889
|
(deprecating ? entityUpdatesLast : entityUpdatesFirst).push({
|
|
900
890
|
kind: 'update_entity',
|
|
@@ -1041,11 +1031,9 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
1041
1031
|
qG: () => (orderFlows),
|
|
1042
1032
|
zb: () => (diffEntities)
|
|
1043
1033
|
}, {
|
|
1044
|
-
$I: ENTITY_COMPARED_KEYS,
|
|
1045
1034
|
VU: byCode,
|
|
1046
1035
|
bs: bundleSubject,
|
|
1047
|
-
i9: bundleChecksum
|
|
1048
|
-
mT: FIELD_COMPARED_KEYS
|
|
1036
|
+
i9: bundleChecksum
|
|
1049
1037
|
});
|
|
1050
1038
|
|
|
1051
1039
|
|
|
@@ -1053,22 +1041,34 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
1053
1041
|
6412(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
1054
1042
|
/* import */ var _nestjs_common__rspack_import_0 = __webpack_require__(6157);
|
|
1055
1043
|
/* import */ var class_transformer__rspack_import_1 = __webpack_require__(5812);
|
|
1056
|
-
/* import */ var
|
|
1057
|
-
/* import */ var
|
|
1058
|
-
/* import */ var
|
|
1044
|
+
/* import */ var _flusys_nestjs_shared_utils__rspack_import_2 = __webpack_require__(9216);
|
|
1045
|
+
/* import */ var class_validator__rspack_import_3 = __webpack_require__(5421);
|
|
1046
|
+
/* import */ var _config_entity_builder_constants_js__rspack_import_7 = __webpack_require__(6576);
|
|
1047
|
+
/* import */ var _config_message_keys_js__rspack_import_6 = __webpack_require__(5732);
|
|
1048
|
+
/* import */ var _dtos_definition_bundle_dto_js__rspack_import_4 = __webpack_require__(6691);
|
|
1049
|
+
/* import */ var _interfaces_definition_bundle_interface_js__rspack_import_8 = __webpack_require__(8835);
|
|
1050
|
+
/* import */ var _definition_bundle_diff_js__rspack_import_5 = __webpack_require__(3801);
|
|
1051
|
+
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
|
|
1059
1055
|
|
|
1060
1056
|
|
|
1061
1057
|
|
|
1062
1058
|
|
|
1063
1059
|
|
|
1064
1060
|
const MAX_REPORTED_PROBLEMS = 50;
|
|
1065
|
-
/** Every failed constraint, named by its path in the bundle (`entities.0.fields.2.code`). */ function problems(errors, parent = '') {
|
|
1061
|
+
/** Every failed constraint, named by its path in the bundle (`entities.0.fields.2.code`); `constraints` are class-validator's names (`isString`, `maxLength`). */ function problems(errors, parent = '') {
|
|
1066
1062
|
return errors.flatMap((error)=>{
|
|
1067
1063
|
const field = parent ? `${parent}.${error.property}` : error.property;
|
|
1068
1064
|
const own = error.constraints ? [
|
|
1069
1065
|
{
|
|
1070
1066
|
field,
|
|
1071
|
-
message: Object.values(error.constraints).join('; ')
|
|
1067
|
+
message: Object.values(error.constraints).join('; '),
|
|
1068
|
+
...(0,_flusys_nestjs_shared_utils__rspack_import_2.messageRef)(_config_message_keys_js__rspack_import_6/* .BUNDLE_MESSAGES.FILE_VALUE_INVALID */.iX.FILE_VALUE_INVALID, {
|
|
1069
|
+
field,
|
|
1070
|
+
constraints: Object.keys(error.constraints).join(', ')
|
|
1071
|
+
})
|
|
1072
1072
|
}
|
|
1073
1073
|
] : [];
|
|
1074
1074
|
return [
|
|
@@ -1077,9 +1077,16 @@ const MAX_REPORTED_PROBLEMS = 50;
|
|
|
1077
1077
|
];
|
|
1078
1078
|
});
|
|
1079
1079
|
}
|
|
1080
|
+
const fileProblem = (file, message, messageKey)=>({
|
|
1081
|
+
field: file,
|
|
1082
|
+
message,
|
|
1083
|
+
...(0,_flusys_nestjs_shared_utils__rspack_import_2.messageRef)(messageKey, {
|
|
1084
|
+
file
|
|
1085
|
+
})
|
|
1086
|
+
});
|
|
1080
1087
|
const invalid = (errors = [])=>new _nestjs_common__rspack_import_0.BadRequestException({
|
|
1081
1088
|
message: 'The file is not a valid entity builder bundle.',
|
|
1082
|
-
messageKey:
|
|
1089
|
+
messageKey: _config_message_keys_js__rspack_import_6/* .BUNDLE_MESSAGES.FILE_INVALID */.iX.FILE_INVALID,
|
|
1083
1090
|
...errors.length ? {
|
|
1084
1091
|
errors: errors.slice(0, MAX_REPORTED_PROBLEMS)
|
|
1085
1092
|
} : {}
|
|
@@ -1087,31 +1094,64 @@ const invalid = (errors = [])=>new _nestjs_common__rspack_import_0.BadRequestExc
|
|
|
1087
1094
|
/**
|
|
1088
1095
|
* The uploaded bundle, parsed and checked as strictly as a request body (unknown keys refused). The
|
|
1089
1096
|
* bundle travels as a file rather than as JSON so the app's JSON body limit never applies to it: the
|
|
1090
|
-
* upload limit is the package's own (`ENTITY_BUNDLE_MAX_BYTES`, enforced by
|
|
1091
|
-
*/ function readBundleFile(file) {
|
|
1097
|
+
* upload limit is the package's own (`ENTITY_BUNDLE_MAX_BYTES`, enforced by FilesInterceptor).
|
|
1098
|
+
*/ function readBundleFile(file, source = '') {
|
|
1092
1099
|
if (!file?.buffer?.length) {
|
|
1093
1100
|
throw new _nestjs_common__rspack_import_0.BadRequestException({
|
|
1094
1101
|
message: 'Attach the bundle file as the "bundle" form field.',
|
|
1095
|
-
messageKey:
|
|
1102
|
+
messageKey: _config_message_keys_js__rspack_import_6/* .BUNDLE_MESSAGES.FILE_REQUIRED */.iX.FILE_REQUIRED
|
|
1096
1103
|
});
|
|
1097
1104
|
}
|
|
1105
|
+
const unreadable = (message, messageKey)=>invalid(source ? [
|
|
1106
|
+
fileProblem(source, message, messageKey)
|
|
1107
|
+
] : []);
|
|
1098
1108
|
let raw;
|
|
1099
1109
|
try {
|
|
1100
1110
|
raw = JSON.parse(file.buffer.toString('utf8').replace(/^\uFEFF/, ''));
|
|
1101
1111
|
} catch {
|
|
1102
|
-
throw
|
|
1112
|
+
throw unreadable('not valid JSON', _config_message_keys_js__rspack_import_6/* .BUNDLE_MESSAGES.FILE_NOT_JSON */.iX.FILE_NOT_JSON);
|
|
1103
1113
|
}
|
|
1104
|
-
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) throw
|
|
1105
|
-
const bundle = (0,class_transformer__rspack_import_1.plainToInstance)(
|
|
1106
|
-
const errors = (0,
|
|
1114
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) throw unreadable('not a JSON object', _config_message_keys_js__rspack_import_6/* .BUNDLE_MESSAGES.FILE_NOT_OBJECT */.iX.FILE_NOT_OBJECT);
|
|
1115
|
+
const bundle = (0,class_transformer__rspack_import_1.plainToInstance)(_dtos_definition_bundle_dto_js__rspack_import_4/* .DefinitionBundleDto */.JE, raw);
|
|
1116
|
+
const errors = (0,class_validator__rspack_import_3.validateSync)(bundle, {
|
|
1107
1117
|
whitelist: true,
|
|
1108
1118
|
forbidNonWhitelisted: true
|
|
1109
1119
|
});
|
|
1110
|
-
if (errors.length) throw invalid(problems(errors));
|
|
1120
|
+
if (errors.length) throw invalid(problems(errors, source));
|
|
1111
1121
|
return bundle;
|
|
1112
1122
|
}
|
|
1123
|
+
/**
|
|
1124
|
+
* One bundle from one or more uploaded files. Every file is a complete bundle on its own - a whole export,
|
|
1125
|
+
* or one file per entity and per flow as `entity-bundle export --split` writes them - so a folder kept in git
|
|
1126
|
+
* can be cherry-picked file by file. Entities and flows are merged in code / slug order, the order an export
|
|
1127
|
+
* writes them, so a split folder and the single file of the same definitions have the same checksum.
|
|
1128
|
+
* A definition in two files is not merged here: the plan blocks it as a duplicate.
|
|
1129
|
+
*/ function readBundleFiles(files) {
|
|
1130
|
+
if (!files?.length) return readBundleFile(undefined);
|
|
1131
|
+
if (files.length === 1) return readBundleFile(files[0]);
|
|
1132
|
+
if (files.reduce((total, file)=>total + file.size, 0) > _config_entity_builder_constants_js__rspack_import_7/* .ENTITY_BUNDLE_MAX_BYTES */.EA) {
|
|
1133
|
+
throw new _nestjs_common__rspack_import_0.PayloadTooLargeException({
|
|
1134
|
+
message: 'The bundle files are larger than the upload limit together.',
|
|
1135
|
+
messageKey: _config_message_keys_js__rspack_import_6/* .BUNDLE_MESSAGES.FILES_TOO_LARGE */.iX.FILES_TOO_LARGE
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
const bundles = files.map((file, index)=>{
|
|
1139
|
+
const name = file.originalname || `#${index + 1}`;
|
|
1140
|
+
if (!file.buffer?.length) throw invalid([
|
|
1141
|
+
fileProblem(name, 'empty file', _config_message_keys_js__rspack_import_6/* .BUNDLE_MESSAGES.FILE_EMPTY */.iX.FILE_EMPTY)
|
|
1142
|
+
]);
|
|
1143
|
+
return readBundleFile(file, name);
|
|
1144
|
+
});
|
|
1145
|
+
return {
|
|
1146
|
+
format: _interfaces_definition_bundle_interface_js__rspack_import_8/* .DEFINITION_BUNDLE_FORMAT */.D,
|
|
1147
|
+
version: (/* inlined export .DEFINITION_BUNDLE_VERSION */1),
|
|
1148
|
+
entities: bundles.flatMap((b)=>b.entities).toSorted((a, b)=>(0,_definition_bundle_diff_js__rspack_import_5/* .byCode */.VU)(a.code, b.code)),
|
|
1149
|
+
flows: bundles.flatMap((b)=>b.flows).toSorted((a, b)=>(0,_definition_bundle_diff_js__rspack_import_5/* .byCode */.VU)(a.slug, b.slug))
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1113
1152
|
|
|
1114
1153
|
__webpack_require__.d(__webpack_exports__, {
|
|
1154
|
+
K: () => (readBundleFiles),
|
|
1115
1155
|
z: () => (readBundleFile)
|
|
1116
1156
|
});
|
|
1117
1157
|
|
|
@@ -1256,9 +1296,6 @@ class DefinitionBundleService {
|
|
|
1256
1296
|
this.dialect = dialect;
|
|
1257
1297
|
this.actionRegistry = actionRegistry;
|
|
1258
1298
|
}
|
|
1259
|
-
variables() {
|
|
1260
|
-
return this.config.getBundleVariables();
|
|
1261
|
-
}
|
|
1262
1299
|
// ── export ──────────────────────────────────────────────────────────────────────────
|
|
1263
1300
|
async export(dto) {
|
|
1264
1301
|
const current = await this.loadEntities();
|
|
@@ -1283,7 +1320,7 @@ class DefinitionBundleService {
|
|
|
1283
1320
|
flow: flow.slug
|
|
1284
1321
|
}))
|
|
1285
1322
|
];
|
|
1286
|
-
const variables = this.
|
|
1323
|
+
const variables = this.config.getBundleVariables();
|
|
1287
1324
|
const flows = rows.filter(_flow_definition_service_js__rspack_import_15/* .isPublished */.HF).map((flow)=>{
|
|
1288
1325
|
const snapshot = (0,_flow_definition_service_js__rspack_import_15/* .snapshotOf */.eY)(flow);
|
|
1289
1326
|
return {
|
|
@@ -1530,17 +1567,7 @@ class DefinitionBundleService {
|
|
|
1530
1567
|
flow
|
|
1531
1568
|
]));
|
|
1532
1569
|
const slugs = bundleFlows.map((f)=>f.slug);
|
|
1533
|
-
const
|
|
1534
|
-
select: {
|
|
1535
|
-
id: true,
|
|
1536
|
-
slug: true
|
|
1537
|
-
},
|
|
1538
|
-
where: {
|
|
1539
|
-
slug: (0,typeorm__rspack_import_4.In)(slugs)
|
|
1540
|
-
},
|
|
1541
|
-
withDeleted: true
|
|
1542
|
-
})).filter((f)=>!bySlug.has(f.slug)).map((f)=>f.slug)) : new Set();
|
|
1543
|
-
const variables = this.variables();
|
|
1570
|
+
const variables = this.config.getBundleVariables();
|
|
1544
1571
|
const result = {
|
|
1545
1572
|
planned: [],
|
|
1546
1573
|
unchanged: 0,
|
|
@@ -1566,9 +1593,6 @@ class DefinitionBundleService {
|
|
|
1566
1593
|
flow: flow.slug
|
|
1567
1594
|
}));
|
|
1568
1595
|
const target = bySlug.get(flow.slug);
|
|
1569
|
-
if (!target && deleted.has(flow.slug)) blockers.push((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .BUNDLE_MESSAGES.FLOW_SLUG_DELETED */.iX.FLOW_SLUG_DELETED, {
|
|
1570
|
-
flow: flow.slug
|
|
1571
|
-
}));
|
|
1572
1596
|
const keys = storedApiKeys(target);
|
|
1573
1597
|
const warnings = flow.nodes.filter((node)=>needsApiKey(node) && !keys.has(node.id)).map((node)=>(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .BUNDLE_MESSAGES.FLOW_API_KEY_GENERATED */.iX.FLOW_API_KEY_GENERATED, {
|
|
1574
1598
|
flow: flow.slug,
|
|
@@ -2168,7 +2192,6 @@ const INPUT_TYPE = {
|
|
|
2168
2192
|
[_enums_field_type_enum_js__rspack_import_2/* .FieldType.JSON */.P.JSON]: 'object',
|
|
2169
2193
|
[_enums_field_type_enum_js__rspack_import_2/* .FieldType.FILE */.P.FILE]: 'uuid'
|
|
2170
2194
|
};
|
|
2171
|
-
const LIST_LIMIT = 50;
|
|
2172
2195
|
/** The API controller endpoint each endpoint's Request step stands in for. */ const ENDPOINT_CONTRACTS = {
|
|
2173
2196
|
insert: 'insert',
|
|
2174
2197
|
insertMany: 'insert_many',
|
|
@@ -2458,7 +2481,7 @@ const idInput = (t)=>({
|
|
|
2458
2481
|
case 'getAll':
|
|
2459
2482
|
return list({
|
|
2460
2483
|
fromRequest: true,
|
|
2461
|
-
limit:
|
|
2484
|
+
limit: _flow_engine_flow_types_js__rspack_import_1/* .FLOW_LIMITS.DEFAULT_QUERY_LIMIT */.Or.DEFAULT_QUERY_LIMIT
|
|
2462
2485
|
}, `${label} records retrieved successfully`, 'get.all');
|
|
2463
2486
|
case 'getByFilter':
|
|
2464
2487
|
return {
|
|
@@ -2851,6 +2874,11 @@ const SCALAR_TO_TEXT = new Set([
|
|
|
2851
2874
|
_enums_field_type_enum_js__rspack_import_1/* .FieldType.DATETIME */.P.DATETIME
|
|
2852
2875
|
]);
|
|
2853
2876
|
const EMAIL_PG = `'^[^[:space:]@]+@[^[:space:]@]+\\.[^[:space:]@]+$'`;
|
|
2877
|
+
const EMAIL_MYSQL = `'^[^ @]+@[^ @]+\\\\.[^ @]+$'`;
|
|
2878
|
+
/** Rows whose value is not an email; `castToText` for a column that is not text yet. */ const notEmailCheck = (castToText)=>({
|
|
2879
|
+
description: (0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(_config_message_keys_js__rspack_import_2/* .SCHEMA_PRECHECK_MESSAGES.NOT_EMAIL */.NE.NOT_EMAIL),
|
|
2880
|
+
badRowsWhere: (c, d)=>d === 'postgres' ? `${castToText ? `${c}::text` : c} !~ ${EMAIL_PG}` : `${castToText ? `CAST(${c} AS CHAR)` : c} NOT REGEXP ${EMAIL_MYSQL}`
|
|
2881
|
+
});
|
|
2854
2882
|
const regexFail = (column, driver, pattern)=>driver === 'postgres' ? `${column} !~ '${pattern}'` : `${column} NOT REGEXP '${pattern}'`;
|
|
2855
2883
|
const SELECT_KINDS = new Set([
|
|
2856
2884
|
_enums_field_type_enum_js__rspack_import_1/* .FieldType.SINGLE_SELECT */.P.SINGLE_SELECT,
|
|
@@ -2875,17 +2903,12 @@ function planTypeConversion(from, to, driver) {
|
|
|
2875
2903
|
if (driver === 'mysql' && (SELECT_KINDS.has(from) && SELECT_KINDS.has(to) || textLike && to === _enums_field_type_enum_js__rspack_import_1/* .FieldType.BOOLEAN */.P.BOOLEAN)) return unsupported(from, to);
|
|
2876
2904
|
// Same physical column (varchar(255)): only the meaning changes.
|
|
2877
2905
|
if (TEXT_LIKE.has(from) && TEXT_LIKE.has(to)) {
|
|
2878
|
-
const checks = [];
|
|
2879
|
-
if (to === _enums_field_type_enum_js__rspack_import_1/* .FieldType.EMAIL */.P.EMAIL) {
|
|
2880
|
-
checks.push({
|
|
2881
|
-
description: (0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(_config_message_keys_js__rspack_import_2/* .SCHEMA_PRECHECK_MESSAGES.NOT_EMAIL */.NE.NOT_EMAIL),
|
|
2882
|
-
badRowsWhere: (c, d)=>d === 'postgres' ? `${c} !~ ${EMAIL_PG}` : `${c} NOT REGEXP '^[^ @]+@[^ @]+\\\\.[^ @]+$'`
|
|
2883
|
-
});
|
|
2884
|
-
}
|
|
2885
2906
|
return {
|
|
2886
2907
|
supported: true,
|
|
2887
2908
|
noDbChange: true,
|
|
2888
|
-
prechecks:
|
|
2909
|
+
prechecks: to === _enums_field_type_enum_js__rspack_import_1/* .FieldType.EMAIL */.P.EMAIL ? [
|
|
2910
|
+
notEmailCheck(false)
|
|
2911
|
+
] : []
|
|
2889
2912
|
};
|
|
2890
2913
|
}
|
|
2891
2914
|
if (from === _enums_field_type_enum_js__rspack_import_1/* .FieldType.RELATION */.P.RELATION && to === _enums_field_type_enum_js__rspack_import_1/* .FieldType.FILE */.P.FILE || from === _enums_field_type_enum_js__rspack_import_1/* .FieldType.FILE */.P.FILE && to === _enums_field_type_enum_js__rspack_import_1/* .FieldType.RELATION */.P.RELATION) {
|
|
@@ -2911,12 +2934,7 @@ function planTypeConversion(from, to, driver) {
|
|
|
2911
2934
|
badRowsWhere: (c, d)=>d === 'postgres' ? `char_length(${c}) > 255` : `CHAR_LENGTH(${c}) > 255`
|
|
2912
2935
|
}
|
|
2913
2936
|
];
|
|
2914
|
-
if (to === _enums_field_type_enum_js__rspack_import_1/* .FieldType.EMAIL */.P.EMAIL)
|
|
2915
|
-
checks.push({
|
|
2916
|
-
description: (0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(_config_message_keys_js__rspack_import_2/* .SCHEMA_PRECHECK_MESSAGES.NOT_EMAIL */.NE.NOT_EMAIL),
|
|
2917
|
-
badRowsWhere: (c, d)=>d === 'postgres' ? `${c} !~ ${EMAIL_PG}` : `${c} NOT REGEXP '^[^ @]+@[^ @]+\\\\.[^ @]+$'`
|
|
2918
|
-
});
|
|
2919
|
-
}
|
|
2937
|
+
if (to === _enums_field_type_enum_js__rspack_import_1/* .FieldType.EMAIL */.P.EMAIL) checks.push(notEmailCheck(false));
|
|
2920
2938
|
return {
|
|
2921
2939
|
supported: true,
|
|
2922
2940
|
using: (c)=>`${c}::varchar(255)`,
|
|
@@ -2925,17 +2943,12 @@ function planTypeConversion(from, to, driver) {
|
|
|
2925
2943
|
}
|
|
2926
2944
|
// scalar -> text-like: always representable
|
|
2927
2945
|
if (SCALAR_TO_TEXT.has(from) && TEXT_LIKE.has(to)) {
|
|
2928
|
-
const checks = [];
|
|
2929
|
-
if (to === _enums_field_type_enum_js__rspack_import_1/* .FieldType.EMAIL */.P.EMAIL) {
|
|
2930
|
-
checks.push({
|
|
2931
|
-
description: (0,_flusys_nestjs_shared_utils__rspack_import_0.messageRef)(_config_message_keys_js__rspack_import_2/* .SCHEMA_PRECHECK_MESSAGES.NOT_EMAIL */.NE.NOT_EMAIL),
|
|
2932
|
-
badRowsWhere: (c, d)=>d === 'postgres' ? `${c}::text !~ ${EMAIL_PG}` : `CAST(${c} AS CHAR) NOT REGEXP '^[^ @]+@[^ @]+\\\\.[^ @]+$'`
|
|
2933
|
-
});
|
|
2934
|
-
}
|
|
2935
2946
|
return {
|
|
2936
2947
|
supported: true,
|
|
2937
2948
|
using: (c)=>`${c}::text`,
|
|
2938
|
-
prechecks:
|
|
2949
|
+
prechecks: to === _enums_field_type_enum_js__rspack_import_1/* .FieldType.EMAIL */.P.EMAIL ? [
|
|
2950
|
+
notEmailCheck(true)
|
|
2951
|
+
] : []
|
|
2939
2952
|
};
|
|
2940
2953
|
}
|
|
2941
2954
|
// text-like / long text -> scalar: every existing value must parse
|
|
@@ -3212,10 +3225,44 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
3212
3225
|
}
|
|
3213
3226
|
|
|
3214
3227
|
__webpack_require__.d(__webpack_exports__, {
|
|
3215
|
-
|
|
3216
|
-
|
|
3228
|
+
f: () => (assertIndexableField),
|
|
3229
|
+
k: () => (assertValidIdentifier)
|
|
3230
|
+
});
|
|
3231
|
+
|
|
3232
|
+
|
|
3233
|
+
},
|
|
3234
|
+
3086(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
3235
|
+
/** Pure JSON string helpers for finding and rewriting `<prefix>.<field>` references inside definitions. */ function mapStrings(value, fn) {
|
|
3236
|
+
if (typeof value === 'string') return fn(value);
|
|
3237
|
+
if (Array.isArray(value)) return value.map((v)=>mapStrings(v, fn));
|
|
3238
|
+
if (value && typeof value === 'object') {
|
|
3239
|
+
return Object.fromEntries(Object.entries(value).map(([k, v])=>[
|
|
3240
|
+
k,
|
|
3241
|
+
mapStrings(v, fn)
|
|
3242
|
+
]));
|
|
3243
|
+
}
|
|
3244
|
+
return value;
|
|
3245
|
+
}
|
|
3246
|
+
function anyString(value, test) {
|
|
3247
|
+
if (typeof value === 'string') return test(value);
|
|
3248
|
+
if (Array.isArray(value)) return value.some((v)=>anyString(v, test));
|
|
3249
|
+
if (value && typeof value === 'object') return Object.values(value).some((v)=>anyString(v, test));
|
|
3250
|
+
return false;
|
|
3251
|
+
}
|
|
3252
|
+
const escapeRe = (s)=>s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
3253
|
+
/**
|
|
3254
|
+
* `<prefix>.<field>`, `<prefix>.<field>.x` or `{{ <prefix>.<field> }}` inside a template - but not
|
|
3255
|
+
* `<prefix>.<field>_2`. The prefix is a regex source (e.g. `context\.find\.items\.\d+`), captured so a rewrite keeps it.
|
|
3256
|
+
*/ const referencePatternSource = (prefixSource, field, flags = '')=>new RegExp(`(^|\\{\\{\\s*)(${prefixSource})\\.${escapeRe(field)}(?!\\w)`, flags);
|
|
3257
|
+
const replaceReferenceSource = (s, prefixSource, from, to)=>s.replace(referencePatternSource(prefixSource, from, 'g'), (_match, lead, prefix)=>`${lead}${prefix}.${to}`);
|
|
3258
|
+
|
|
3259
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
3260
|
+
gp: () => (anyString),
|
|
3261
|
+
to: () => (mapStrings)
|
|
3217
3262
|
}, {
|
|
3218
|
-
|
|
3263
|
+
LV: referencePatternSource,
|
|
3264
|
+
NF: escapeRe,
|
|
3265
|
+
Ni: replaceReferenceSource
|
|
3219
3266
|
});
|
|
3220
3267
|
|
|
3221
3268
|
|
|
@@ -3782,14 +3829,14 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
3782
3829
|
/* import */ var class_transformer__rspack_import_3 = __webpack_require__(5812);
|
|
3783
3830
|
/* import */ var class_validator__rspack_import_4 = __webpack_require__(5421);
|
|
3784
3831
|
/* import */ var typeorm__rspack_import_5 = __webpack_require__(7158);
|
|
3785
|
-
/* import */ var
|
|
3832
|
+
/* import */ var _config_message_keys_js__rspack_import_20 = __webpack_require__(5732);
|
|
3786
3833
|
/* import */ var _dtos_schema_change_dto_js__rspack_import_6 = __webpack_require__(4945);
|
|
3787
3834
|
/* import */ var _entities_entity_definition_entity_js__rspack_import_7 = __webpack_require__(3189);
|
|
3788
3835
|
/* import */ var _entities_field_definition_entity_js__rspack_import_8 = __webpack_require__(2206);
|
|
3789
3836
|
/* import */ var _entities_schema_change_log_entity_js__rspack_import_9 = __webpack_require__(875);
|
|
3790
|
-
/* import */ var
|
|
3791
|
-
/* import */ var
|
|
3792
|
-
/* import */ var
|
|
3837
|
+
/* import */ var _enums_ddl_operation_enum_js__rspack_import_22 = __webpack_require__(9949);
|
|
3838
|
+
/* import */ var _enums_entity_status_enum_js__rspack_import_24 = __webpack_require__(1313);
|
|
3839
|
+
/* import */ var _enums_field_type_enum_js__rspack_import_21 = __webpack_require__(9614);
|
|
3793
3840
|
/* import */ var _entity_builder_datasource_provider_js__rspack_import_10 = __webpack_require__(424);
|
|
3794
3841
|
/* import */ var _entity_permission_service_js__rspack_import_11 = __webpack_require__(1462);
|
|
3795
3842
|
/* import */ var _field_value_validator_js__rspack_import_12 = __webpack_require__(3525);
|
|
@@ -3797,9 +3844,10 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
3797
3844
|
/* import */ var _identifier_rules_js__rspack_import_14 = __webpack_require__(413);
|
|
3798
3845
|
/* import */ var _reference_scanner_service_js__rspack_import_15 = __webpack_require__(921);
|
|
3799
3846
|
/* import */ var _schema_change_executor_service_js__rspack_import_16 = __webpack_require__(6605);
|
|
3800
|
-
/* import */ var
|
|
3847
|
+
/* import */ var _schema_change_types_js__rspack_import_23 = __webpack_require__(7827);
|
|
3801
3848
|
/* import */ var _schema_columns_js__rspack_import_17 = __webpack_require__(5313);
|
|
3802
|
-
/* import */ var
|
|
3849
|
+
/* import */ var _entity_builder_config_service_js__rspack_import_18 = __webpack_require__(4281);
|
|
3850
|
+
/* import */ var _schema_dialect_adapter_service_js__rspack_import_19 = __webpack_require__(7259);
|
|
3803
3851
|
function _ts_decorate(decorators, target, key, desc) {
|
|
3804
3852
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3805
3853
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
@@ -3845,48 +3893,59 @@ function _ts_param(paramIndex, decorator) {
|
|
|
3845
3893
|
|
|
3846
3894
|
|
|
3847
3895
|
|
|
3896
|
+
|
|
3848
3897
|
|
|
3849
3898
|
|
|
3850
3899
|
const entityNotFound = (id)=>new _nestjs_common__rspack_import_2.NotFoundException({
|
|
3851
3900
|
message: `Entity definition '${id}' not found.`,
|
|
3852
|
-
messageKey:
|
|
3901
|
+
messageKey: _config_message_keys_js__rspack_import_20/* .ENTITY_DEFINITION_MESSAGES.NOT_FOUND */.pL.NOT_FOUND,
|
|
3853
3902
|
messageVariables: {
|
|
3854
3903
|
id
|
|
3855
3904
|
}
|
|
3856
3905
|
});
|
|
3857
3906
|
const fieldNotFound = (id)=>new _nestjs_common__rspack_import_2.NotFoundException({
|
|
3858
3907
|
message: `Field definition '${id}' not found.`,
|
|
3859
|
-
messageKey:
|
|
3908
|
+
messageKey: _config_message_keys_js__rspack_import_20/* .FIELD_DEFINITION_MESSAGES.NOT_FOUND */.oc.NOT_FOUND,
|
|
3860
3909
|
messageVariables: {
|
|
3861
3910
|
id
|
|
3862
3911
|
}
|
|
3863
3912
|
});
|
|
3913
|
+
const HISTORY_LIMIT = 50;
|
|
3864
3914
|
const DESTRUCTIVE_ACTIONS = [
|
|
3865
3915
|
_dtos_schema_change_dto_js__rspack_import_6/* .SchemaChangeAction.DROP_ENTITY */.M3.DROP_ENTITY,
|
|
3866
3916
|
_dtos_schema_change_dto_js__rspack_import_6/* .SchemaChangeAction.PURGE_FIELD */.M3.PURGE_FIELD
|
|
3867
3917
|
];
|
|
3868
3918
|
const isDestructiveSchemaAction = (action)=>DESTRUCTIVE_ACTIONS.includes(action);
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3919
|
+
/**
|
|
3920
|
+
* Every structural change to an existing entity: add / change / rename / restore / deprecate /
|
|
3921
|
+
* purge a field, change entity settings, drop an entity, and repair drift. Each is a
|
|
3922
|
+
* `SchemaChangeRun` executed by SchemaChangeExecutor, so each can be previewed (`plan`) with
|
|
3923
|
+
* the real SQL and data checks before it is applied. The definitions loaded up front only
|
|
3924
|
+
* validate the request; every run reloads them through its own query runner, so an apply works
|
|
3925
|
+
* on what is current under the entity lock. Plans carry counts but never record values.
|
|
3926
|
+
*/ /** Metadata the runtime reads from the cached field list (SchemaRegistryService): changing it must move schemaVersion. */ const FIELD_CACHE_KEYS = new Set([
|
|
3927
|
+
'selectOptions',
|
|
3928
|
+
'validationRules',
|
|
3929
|
+
'defaultValue',
|
|
3930
|
+
'label',
|
|
3931
|
+
'relationTargetEntityId',
|
|
3932
|
+
'isSearchable',
|
|
3933
|
+
'order'
|
|
3934
|
+
]);
|
|
3878
3935
|
class SchemaEvolutionService {
|
|
3879
3936
|
dataSourceProvider;
|
|
3880
3937
|
adapter;
|
|
3881
3938
|
executor;
|
|
3882
3939
|
references;
|
|
3883
3940
|
permissions;
|
|
3884
|
-
|
|
3941
|
+
config;
|
|
3942
|
+
constructor(dataSourceProvider, adapter, executor, references, permissions, config){
|
|
3885
3943
|
this.dataSourceProvider = dataSourceProvider;
|
|
3886
3944
|
this.adapter = adapter;
|
|
3887
3945
|
this.executor = executor;
|
|
3888
3946
|
this.references = references;
|
|
3889
3947
|
this.permissions = permissions;
|
|
3948
|
+
this.config = config;
|
|
3890
3949
|
}
|
|
3891
3950
|
// ── public API ──────────────────────────────────────────────────────────────────────
|
|
3892
3951
|
async plan(request, user) {
|
|
@@ -3928,7 +3987,7 @@ class SchemaEvolutionService {
|
|
|
3928
3987
|
await qr.release();
|
|
3929
3988
|
}
|
|
3930
3989
|
}
|
|
3931
|
-
/** Newest first. Includes failed attempts, with the SQL that was about to run. */ async history(entityDefinitionId
|
|
3990
|
+
/** Newest first. Includes failed attempts, with the SQL that was about to run. */ async history(entityDefinitionId) {
|
|
3932
3991
|
const repo = await this.dataSourceProvider.getRepository(_entities_schema_change_log_entity_js__rspack_import_9/* .SchemaChangeLog */.W);
|
|
3933
3992
|
return repo.find({
|
|
3934
3993
|
select: {
|
|
@@ -3949,7 +4008,7 @@ class SchemaEvolutionService {
|
|
|
3949
4008
|
order: {
|
|
3950
4009
|
createdAt: 'DESC'
|
|
3951
4010
|
},
|
|
3952
|
-
take:
|
|
4011
|
+
take: HISTORY_LIMIT
|
|
3953
4012
|
});
|
|
3954
4013
|
}
|
|
3955
4014
|
// ── loading ─────────────────────────────────────────────────────────────────────────
|
|
@@ -3957,7 +4016,7 @@ class SchemaEvolutionService {
|
|
|
3957
4016
|
if (!entityDefinitionId) {
|
|
3958
4017
|
throw new _nestjs_common__rspack_import_2.BadRequestException({
|
|
3959
4018
|
message: 'entityDefinitionId is required for this action.',
|
|
3960
|
-
messageKey:
|
|
4019
|
+
messageKey: _config_message_keys_js__rspack_import_20/* .ENTITY_DEFINITION_MESSAGES.ID_REQUIRED */.pL.ID_REQUIRED
|
|
3961
4020
|
});
|
|
3962
4021
|
}
|
|
3963
4022
|
return this.definitions((entity)=>this.dataSourceProvider.getRepository(entity), entityDefinitionId);
|
|
@@ -3966,7 +4025,7 @@ class SchemaEvolutionService {
|
|
|
3966
4025
|
if (!fieldDefinitionId) {
|
|
3967
4026
|
throw new _nestjs_common__rspack_import_2.BadRequestException({
|
|
3968
4027
|
message: 'fieldDefinitionId is required for this action.',
|
|
3969
|
-
messageKey:
|
|
4028
|
+
messageKey: _config_message_keys_js__rspack_import_20/* .FIELD_DEFINITION_MESSAGES.ID_REQUIRED */.oc.ID_REQUIRED
|
|
3970
4029
|
});
|
|
3971
4030
|
}
|
|
3972
4031
|
const field = await (await this.dataSourceProvider.getRepository(_entities_field_definition_entity_js__rspack_import_8/* .FieldDefinition */.c)).findOne({
|
|
@@ -4008,7 +4067,7 @@ class SchemaEvolutionService {
|
|
|
4008
4067
|
if (unknown.length) {
|
|
4009
4068
|
throw new _nestjs_common__rspack_import_2.BadRequestException({
|
|
4010
4069
|
message: `Cannot change ${what} property: ${unknown.join(', ')}. Allowed: ${allowed.join(', ')}.`,
|
|
4011
|
-
messageKey:
|
|
4070
|
+
messageKey: _config_message_keys_js__rspack_import_20/* .SCHEMA_MESSAGES.UNKNOWN_CHANGE_PROPERTY */.Hu.UNKNOWN_CHANGE_PROPERTY,
|
|
4012
4071
|
messageVariables: {
|
|
4013
4072
|
what,
|
|
4014
4073
|
properties: unknown.join(', '),
|
|
@@ -4025,13 +4084,13 @@ class SchemaEvolutionService {
|
|
|
4025
4084
|
const properties = errors.map((e)=>e.property);
|
|
4026
4085
|
throw new _nestjs_common__rspack_import_2.BadRequestException({
|
|
4027
4086
|
message: `Invalid value for ${properties.map((p)=>`'${p}'`).join(', ')}.`,
|
|
4028
|
-
messageKey:
|
|
4087
|
+
messageKey: _config_message_keys_js__rspack_import_20/* .SCHEMA_MESSAGES.INVALID_CHANGE_VALUE */.Hu.INVALID_CHANGE_VALUE,
|
|
4029
4088
|
messageVariables: {
|
|
4030
4089
|
property: properties.join(', ')
|
|
4031
4090
|
},
|
|
4032
4091
|
errors: properties.map((property)=>({
|
|
4033
4092
|
field: property,
|
|
4034
|
-
messageKey:
|
|
4093
|
+
messageKey: _config_message_keys_js__rspack_import_20/* .SCHEMA_MESSAGES.INVALID_CHANGE_VALUE */.Hu.INVALID_CHANGE_VALUE,
|
|
4035
4094
|
messageVariables: {
|
|
4036
4095
|
property
|
|
4037
4096
|
}
|
|
@@ -4059,7 +4118,7 @@ class SchemaEvolutionService {
|
|
|
4059
4118
|
if (updatedAt && updatedAt.getTime() !== new Date(expected).getTime()) {
|
|
4060
4119
|
throw new _nestjs_common__rspack_import_2.ConflictException({
|
|
4061
4120
|
message: 'Someone else changed this definition since you opened it. Reload it and make your change again.',
|
|
4062
|
-
messageKey:
|
|
4121
|
+
messageKey: _config_message_keys_js__rspack_import_20/* .SCHEMA_MESSAGES.STALE_DEFINITION */.Hu.STALE_DEFINITION,
|
|
4063
4122
|
messageVariables: {
|
|
4064
4123
|
updatedAt: updatedAt.toISOString()
|
|
4065
4124
|
}
|
|
@@ -4068,7 +4127,7 @@ class SchemaEvolutionService {
|
|
|
4068
4127
|
}
|
|
4069
4128
|
/** The field was renamed (or deprecated) by a change that committed after this request was checked. */ changedUnderneath(ctx, before, now) {
|
|
4070
4129
|
if (now.code === before.code && !!now.deprecatedAt === !!before.deprecatedAt) return false;
|
|
4071
|
-
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4130
|
+
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.DEFINITION_CHANGED */.M3.DEFINITION_CHANGED));
|
|
4072
4131
|
return true;
|
|
4073
4132
|
}
|
|
4074
4133
|
// ── dispatch ────────────────────────────────────────────────────────────────────────
|
|
@@ -4114,7 +4173,7 @@ class SchemaEvolutionService {
|
|
|
4114
4173
|
return (0,_flusys_nestjs_shared_utils__rspack_import_1.withSavepoint)(ctx.qr, ()=>this.scalar(ctx, sql, params)).catch(()=>0);
|
|
4115
4174
|
}
|
|
4116
4175
|
paramValue(fieldType, value) {
|
|
4117
|
-
return fieldType ===
|
|
4176
|
+
return fieldType === _enums_field_type_enum_js__rspack_import_21/* .FieldType.JSON */.P.JSON || fieldType === _enums_field_type_enum_js__rspack_import_21/* .FieldType.MULTI_SELECT */.P.MULTI_SELECT ? JSON.stringify(value) : value;
|
|
4118
4177
|
}
|
|
4119
4178
|
notNullSql(ctx, table, column, fieldType, notNull) {
|
|
4120
4179
|
if (ctx.driver === 'postgres') {
|
|
@@ -4122,7 +4181,7 @@ class SchemaEvolutionService {
|
|
|
4122
4181
|
}
|
|
4123
4182
|
return `ALTER TABLE ${ctx.q(table)} MODIFY ${ctx.q(column)} ${(0,_schema_columns_js__rspack_import_17/* .sqlTypeFor */.cg)(fieldType, ctx.driver, this.adapter)} ${notNull ? 'NOT NULL' : 'NULL'}`;
|
|
4124
4183
|
}
|
|
4125
|
-
/** Makes a column NOT NULL (or nullable again), with the reverse statement for the plan. */ setRequired(ctx, table, column, fieldType, required, step = required ?
|
|
4184
|
+
/** Makes a column NOT NULL (or nullable again), with the reverse statement for the plan. */ setRequired(ctx, table, column, fieldType, required, step = required ? _config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.MAKE_REQUIRED */.EQ.MAKE_REQUIRED : _config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.MAKE_OPTIONAL */.EQ.MAKE_OPTIONAL) {
|
|
4126
4185
|
return ctx.rawDdl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(step, {
|
|
4127
4186
|
column
|
|
4128
4187
|
}), [
|
|
@@ -4133,7 +4192,7 @@ class SchemaEvolutionService {
|
|
|
4133
4192
|
}
|
|
4134
4193
|
checkValue(field, value) {
|
|
4135
4194
|
const { errors } = (0,_field_value_validator_js__rspack_import_12/* .validateRecord */.e)([
|
|
4136
|
-
|
|
4195
|
+
(0,_field_value_validator_js__rspack_import_12/* .valueRulesOf */.C)(field)
|
|
4137
4196
|
], {
|
|
4138
4197
|
[field.code]: value
|
|
4139
4198
|
}, 'insert');
|
|
@@ -4142,7 +4201,7 @@ class SchemaEvolutionService {
|
|
|
4142
4201
|
async requireTable(ctx, tableName) {
|
|
4143
4202
|
const table = await ctx.qr.getTable(tableName);
|
|
4144
4203
|
if (!table) {
|
|
4145
|
-
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4204
|
+
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.TABLE_MISSING */.M3.TABLE_MISSING, {
|
|
4146
4205
|
table: tableName
|
|
4147
4206
|
}));
|
|
4148
4207
|
}
|
|
@@ -4171,6 +4230,16 @@ class SchemaEvolutionService {
|
|
|
4171
4230
|
indexOn(table, column, unique) {
|
|
4172
4231
|
return table.indices.filter((i)=>i.columnNames.length === 1 && i.columnNames[0] === column && i.isUnique === unique);
|
|
4173
4232
|
}
|
|
4233
|
+
/** `performance.partialIndexes`: plain indexes of a soft-delete entity cover live rows only (PostgreSQL). */ liveOnly(definition, driver) {
|
|
4234
|
+
return !!this.config?.isPartialIndexesEnabled() && definition.isSoftDeleteEnabled && driver === 'postgres';
|
|
4235
|
+
}
|
|
4236
|
+
/** The plain index on `column` exists with the shape the entity wants (live rows only, or all rows). */ hasPlainIndex(table, column, liveOnly) {
|
|
4237
|
+
return this.indexOn(table, column, false).some((index)=>(0,_schema_columns_js__rspack_import_17/* .isLiveRowsIndex */.YS)(index) === liveOnly);
|
|
4238
|
+
}
|
|
4239
|
+
/** Replaces whatever plain index `column` has with one of the wanted shape. */ async rebuildPlainIndex(ctx, table, tableName, column, liveOnly) {
|
|
4240
|
+
for (const index of this.indexOn(table, column, false))await ctx.qr.dropIndex(table, index);
|
|
4241
|
+
await ctx.qr.createIndex(table, (0,_schema_columns_js__rspack_import_17/* .plainIndex */.v7)(tableName, column, ctx.driver, this.adapter, liveOnly));
|
|
4242
|
+
}
|
|
4174
4243
|
// ── add_field ───────────────────────────────────────────────────────────────────────
|
|
4175
4244
|
async prepareAddField(request, user, fieldId) {
|
|
4176
4245
|
const { definition: loaded } = await this.loadEntity(request.entityDefinitionId);
|
|
@@ -4178,11 +4247,11 @@ class SchemaEvolutionService {
|
|
|
4178
4247
|
if (!spec) {
|
|
4179
4248
|
throw new _nestjs_common__rspack_import_2.BadRequestException({
|
|
4180
4249
|
message: "add_field needs a 'field' definition.",
|
|
4181
|
-
messageKey:
|
|
4250
|
+
messageKey: _config_message_keys_js__rspack_import_20/* .FIELD_DEFINITION_MESSAGES.DEFINITION_REQUIRED */.oc.DEFINITION_REQUIRED
|
|
4182
4251
|
});
|
|
4183
4252
|
}
|
|
4184
|
-
(0,_identifier_rules_js__rspack_import_14/* .assertValidIdentifier */.
|
|
4185
|
-
(0,_identifier_rules_js__rspack_import_14/* .assertIndexableField */.
|
|
4253
|
+
(0,_identifier_rules_js__rspack_import_14/* .assertValidIdentifier */.k)(spec.code, 'field');
|
|
4254
|
+
(0,_identifier_rules_js__rspack_import_14/* .assertIndexableField */.f)(spec);
|
|
4186
4255
|
const lockCodes = await (0,_schema_change_executor_service_js__rspack_import_16/* .relationTargetCodes */.e)(this.dataSourceProvider, [
|
|
4187
4256
|
spec.relationTargetEntityId
|
|
4188
4257
|
]);
|
|
@@ -4190,16 +4259,16 @@ class SchemaEvolutionService {
|
|
|
4190
4259
|
const { definition, fields } = await this.current(ctx, request, loaded.id);
|
|
4191
4260
|
const existing = fields.find((f)=>f.code === spec.code);
|
|
4192
4261
|
if (existing) {
|
|
4193
|
-
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(existing.deprecatedAt ?
|
|
4262
|
+
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(existing.deprecatedAt ? _config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.FIELD_EXISTS_DEPRECATED */.M3.FIELD_EXISTS_DEPRECATED : _config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.FIELD_EXISTS */.M3.FIELD_EXISTS, {
|
|
4194
4263
|
code: spec.code
|
|
4195
4264
|
}));
|
|
4196
4265
|
}
|
|
4197
4266
|
const nullable = spec.nullable ?? true;
|
|
4198
4267
|
const unique = spec.unique ?? false;
|
|
4199
4268
|
const dbType = this.adapter.mapFieldType(spec.fieldType, ctx.driver);
|
|
4200
|
-
const isRelation = spec.fieldType ===
|
|
4269
|
+
const isRelation = spec.fieldType === _enums_field_type_enum_js__rspack_import_21/* .FieldType.RELATION */.P.RELATION;
|
|
4201
4270
|
if (isRelation && !spec.relationTargetEntityId) {
|
|
4202
|
-
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4271
|
+
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.RELATION_TARGET_REQUIRED */.M3.RELATION_TARGET_REQUIRED, {
|
|
4203
4272
|
field: spec.code
|
|
4204
4273
|
}));
|
|
4205
4274
|
} else if (isRelation) {
|
|
@@ -4208,18 +4277,14 @@ class SchemaEvolutionService {
|
|
|
4208
4277
|
id: spec.relationTargetEntityId
|
|
4209
4278
|
}
|
|
4210
4279
|
});
|
|
4211
|
-
if (!target) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4280
|
+
if (!target) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.RELATION_TARGET_MISSING */.M3.RELATION_TARGET_MISSING));
|
|
4212
4281
|
}
|
|
4213
|
-
if ((spec.fieldType ===
|
|
4214
|
-
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4282
|
+
if ((spec.fieldType === _enums_field_type_enum_js__rspack_import_21/* .FieldType.SINGLE_SELECT */.P.SINGLE_SELECT || spec.fieldType === _enums_field_type_enum_js__rspack_import_21/* .FieldType.MULTI_SELECT */.P.MULTI_SELECT) && !spec.selectOptions?.length) {
|
|
4283
|
+
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.NO_SELECT_OPTIONS_YET */.Uu.NO_SELECT_OPTIONS_YET));
|
|
4215
4284
|
}
|
|
4216
4285
|
if (spec.defaultValue !== undefined && spec.defaultValue !== null) {
|
|
4217
|
-
const problem = this.checkValue(
|
|
4218
|
-
|
|
4219
|
-
code: spec.code,
|
|
4220
|
-
fieldType: spec.fieldType
|
|
4221
|
-
}, spec.defaultValue);
|
|
4222
|
-
if (problem) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_19/* .SCHEMA_BLOCKER_MESSAGES.DEFAULT_INVALID */.M3.DEFAULT_INVALID, {
|
|
4286
|
+
const problem = this.checkValue(spec, spec.defaultValue);
|
|
4287
|
+
if (problem) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.DEFAULT_INVALID */.M3.DEFAULT_INVALID, {
|
|
4223
4288
|
problem
|
|
4224
4289
|
}));
|
|
4225
4290
|
}
|
|
@@ -4228,27 +4293,23 @@ class SchemaEvolutionService {
|
|
|
4228
4293
|
const backfill = request.backfillValue ?? spec.defaultValue ?? null;
|
|
4229
4294
|
if (!nullable && rows > 0) {
|
|
4230
4295
|
if (backfill === null) {
|
|
4231
|
-
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4296
|
+
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.REQUIRED_NEEDS_VALUE */.M3.REQUIRED_NEEDS_VALUE, {
|
|
4232
4297
|
count: rows
|
|
4233
4298
|
}));
|
|
4234
4299
|
} else {
|
|
4235
|
-
const problem = this.checkValue(
|
|
4236
|
-
|
|
4237
|
-
code: spec.code,
|
|
4238
|
-
fieldType: spec.fieldType
|
|
4239
|
-
}, backfill);
|
|
4240
|
-
if (problem) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_19/* .SCHEMA_BLOCKER_MESSAGES.BACKFILL_INVALID */.M3.BACKFILL_INVALID, {
|
|
4300
|
+
const problem = this.checkValue(spec, backfill);
|
|
4301
|
+
if (problem) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.BACKFILL_INVALID */.M3.BACKFILL_INVALID, {
|
|
4241
4302
|
problem
|
|
4242
4303
|
}));
|
|
4243
4304
|
}
|
|
4244
4305
|
}
|
|
4245
4306
|
// Only a required field is backfilled; every existing row gets the same value, so two rows or more would clash.
|
|
4246
4307
|
if (unique && !nullable && backfill !== null && rows > 1) {
|
|
4247
|
-
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4308
|
+
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.UNIQUE_BACKFILL_CONFLICT */.M3.UNIQUE_BACKFILL_CONFLICT));
|
|
4248
4309
|
}
|
|
4249
4310
|
if (ctx.blocked || !table) {
|
|
4250
4311
|
return {
|
|
4251
|
-
operation:
|
|
4312
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.ADD_COLUMN */.i.ADD_COLUMN,
|
|
4252
4313
|
diff: {}
|
|
4253
4314
|
};
|
|
4254
4315
|
}
|
|
@@ -4262,13 +4323,13 @@ class SchemaEvolutionService {
|
|
|
4262
4323
|
enforceNotNull: false,
|
|
4263
4324
|
withUnique: false
|
|
4264
4325
|
});
|
|
4265
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4326
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.ADD_COLUMN */.EQ.ADD_COLUMN, {
|
|
4266
4327
|
column: spec.code
|
|
4267
4328
|
}), async ()=>{
|
|
4268
4329
|
await ctx.qr.addColumn(table, column);
|
|
4269
4330
|
});
|
|
4270
4331
|
if (!nullable && rows > 0) {
|
|
4271
|
-
await ctx.data((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4332
|
+
await ctx.data((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.BACKFILL_EXISTING */.EQ.BACKFILL_EXISTING, {
|
|
4272
4333
|
count: rows
|
|
4273
4334
|
}), `UPDATE ${ctx.q(definition.tableName)} SET ${ctx.q(spec.code)} = ${this.adapter.sqlLiteral(this.paramValue(spec.fieldType, backfill), ctx.driver)}`, async ()=>{
|
|
4274
4335
|
await ctx.qr.query((0,_flusys_nestjs_shared_classes__rspack_import_0.buildQuery)(`UPDATE ${ctx.q(definition.tableName)} SET ${ctx.q(spec.code)} = ?`, ctx.driver), [
|
|
@@ -4280,17 +4341,17 @@ class SchemaEvolutionService {
|
|
|
4280
4341
|
await this.setRequired(ctx, definition.tableName, spec.code, spec.fieldType, true);
|
|
4281
4342
|
}
|
|
4282
4343
|
if (unique) {
|
|
4283
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4344
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.ADD_UNIQUE */.EQ.ADD_UNIQUE, {
|
|
4284
4345
|
column: spec.code
|
|
4285
4346
|
}), async ()=>{
|
|
4286
4347
|
await (0,_schema_columns_js__rspack_import_17/* .addUnique */.$6)(ctx.qr, table, spec.code, ctx.driver, this.adapter);
|
|
4287
4348
|
});
|
|
4288
4349
|
}
|
|
4289
|
-
if (
|
|
4290
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4350
|
+
if ((0,_schema_columns_js__rspack_import_17/* .indexedByDefault */.w5)(spec) && !unique) {
|
|
4351
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.ADD_INDEX */.EQ.ADD_INDEX, {
|
|
4291
4352
|
column: spec.code
|
|
4292
4353
|
}), async ()=>{
|
|
4293
|
-
await ctx.qr.createIndex(table, (0,_schema_columns_js__rspack_import_17/* .plainIndex */.v7)(definition.tableName, spec.code, ctx.driver, this.adapter));
|
|
4354
|
+
await ctx.qr.createIndex(table, (0,_schema_columns_js__rspack_import_17/* .plainIndex */.v7)(definition.tableName, spec.code, ctx.driver, this.adapter, this.liveOnly(definition, ctx.driver)));
|
|
4294
4355
|
});
|
|
4295
4356
|
}
|
|
4296
4357
|
let savedFieldId = null;
|
|
@@ -4307,7 +4368,7 @@ class SchemaEvolutionService {
|
|
|
4307
4368
|
dbType,
|
|
4308
4369
|
nullable,
|
|
4309
4370
|
unique,
|
|
4310
|
-
isIndexed:
|
|
4371
|
+
isIndexed: (0,_schema_columns_js__rspack_import_17/* .indexedByDefault */.w5)(spec),
|
|
4311
4372
|
defaultValue: spec.defaultValue ?? null,
|
|
4312
4373
|
validationRules: spec.validationRules ?? null,
|
|
4313
4374
|
selectOptions: spec.selectOptions ?? null,
|
|
@@ -4321,7 +4382,7 @@ class SchemaEvolutionService {
|
|
|
4321
4382
|
savedFieldId = saved.id;
|
|
4322
4383
|
});
|
|
4323
4384
|
return {
|
|
4324
|
-
operation:
|
|
4385
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.ADD_COLUMN */.i.ADD_COLUMN,
|
|
4325
4386
|
fieldDefinitionId: savedFieldId,
|
|
4326
4387
|
diff: {
|
|
4327
4388
|
field: {
|
|
@@ -4349,11 +4410,11 @@ class SchemaEvolutionService {
|
|
|
4349
4410
|
if (loadedField.deprecatedAt) {
|
|
4350
4411
|
throw new _nestjs_common__rspack_import_2.BadRequestException({
|
|
4351
4412
|
message: 'A deprecated field cannot be changed. Restore it first.',
|
|
4352
|
-
messageKey:
|
|
4413
|
+
messageKey: _config_message_keys_js__rspack_import_20/* .FIELD_DEFINITION_MESSAGES.DEPRECATED_LOCKED */.oc.DEPRECATED_LOCKED
|
|
4353
4414
|
});
|
|
4354
4415
|
}
|
|
4355
4416
|
const newCode = typeof changes.code === 'string' && changes.code !== loadedField.code ? changes.code : null;
|
|
4356
|
-
if (newCode) (0,_identifier_rules_js__rspack_import_14/* .assertValidIdentifier */.
|
|
4417
|
+
if (newCode) (0,_identifier_rules_js__rspack_import_14/* .assertValidIdentifier */.k)(newCode, 'field');
|
|
4357
4418
|
const structuralKeys = (field)=>[
|
|
4358
4419
|
'fieldType',
|
|
4359
4420
|
'nullable',
|
|
@@ -4364,7 +4425,7 @@ class SchemaEvolutionService {
|
|
|
4364
4425
|
if (newCode && requested.length) {
|
|
4365
4426
|
throw new _nestjs_common__rspack_import_2.BadRequestException({
|
|
4366
4427
|
message: `Rename '${loadedField.code}' in its own change - it cannot be combined with: ${requested.join(', ')}.`,
|
|
4367
|
-
messageKey:
|
|
4428
|
+
messageKey: _config_message_keys_js__rspack_import_20/* .FIELD_DEFINITION_MESSAGES.RENAME_ALONE */.oc.RENAME_ALONE,
|
|
4368
4429
|
messageVariables: {
|
|
4369
4430
|
field: loadedField.code,
|
|
4370
4431
|
changes: requested.join(', ')
|
|
@@ -4376,7 +4437,7 @@ class SchemaEvolutionService {
|
|
|
4376
4437
|
'unique',
|
|
4377
4438
|
'isIndexed'
|
|
4378
4439
|
].some((k)=>k in changes)) {
|
|
4379
|
-
(0,_identifier_rules_js__rspack_import_14/* .assertIndexableField */.
|
|
4440
|
+
(0,_identifier_rules_js__rspack_import_14/* .assertIndexableField */.f)({
|
|
4380
4441
|
...loadedField,
|
|
4381
4442
|
...changes,
|
|
4382
4443
|
code: loadedField.code
|
|
@@ -4384,10 +4445,10 @@ class SchemaEvolutionService {
|
|
|
4384
4445
|
}
|
|
4385
4446
|
const targetType = changes.fieldType ?? loadedField.fieldType;
|
|
4386
4447
|
const newTargetId = typeof changes.relationTargetEntityId === 'string' ? changes.relationTargetEntityId : null;
|
|
4387
|
-
if (newTargetId && targetType !==
|
|
4448
|
+
if (newTargetId && targetType !== _enums_field_type_enum_js__rspack_import_21/* .FieldType.RELATION */.P.RELATION) {
|
|
4388
4449
|
throw new _nestjs_common__rspack_import_2.BadRequestException({
|
|
4389
4450
|
message: 'relationTargetEntityId can only be set on a RELATION field.',
|
|
4390
|
-
messageKey:
|
|
4451
|
+
messageKey: _config_message_keys_js__rspack_import_20/* .SCHEMA_MESSAGES.INVALID_CHANGE_VALUE */.Hu.INVALID_CHANGE_VALUE,
|
|
4391
4452
|
messageVariables: {
|
|
4392
4453
|
property: 'relationTargetEntityId'
|
|
4393
4454
|
}
|
|
@@ -4401,7 +4462,7 @@ class SchemaEvolutionService {
|
|
|
4401
4462
|
const { definition, fields, field } = await this.current(ctx, request, loaded.id, loadedField.id);
|
|
4402
4463
|
if (this.changedUnderneath(ctx, loadedField, field)) {
|
|
4403
4464
|
return {
|
|
4404
|
-
operation:
|
|
4465
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.ALTER_FIELD */.i.ALTER_FIELD,
|
|
4405
4466
|
fieldDefinitionId: field.id,
|
|
4406
4467
|
diff: {}
|
|
4407
4468
|
};
|
|
@@ -4415,7 +4476,7 @@ class SchemaEvolutionService {
|
|
|
4415
4476
|
const table = structural.length || newCode ? await this.requireTable(ctx, definition.tableName) : undefined;
|
|
4416
4477
|
const column = table?.findColumnByName(field.code);
|
|
4417
4478
|
if ((structural.length || newCode) && table && !column) {
|
|
4418
|
-
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4479
|
+
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.COLUMN_MISSING */.M3.COLUMN_MISSING, {
|
|
4419
4480
|
column: field.code
|
|
4420
4481
|
}));
|
|
4421
4482
|
}
|
|
@@ -4430,10 +4491,10 @@ class SchemaEvolutionService {
|
|
|
4430
4491
|
}
|
|
4431
4492
|
if ('selectOptions' in changes) {
|
|
4432
4493
|
patch.selectOptions = changes.selectOptions;
|
|
4433
|
-
if (merged.fieldType ===
|
|
4494
|
+
if (merged.fieldType === _enums_field_type_enum_js__rspack_import_21/* .FieldType.SINGLE_SELECT */.P.SINGLE_SELECT && Array.isArray(changes.selectOptions) && changes.selectOptions.length && !ctx.blocked) {
|
|
4434
4495
|
const values = changes.selectOptions.map((o)=>String(o.value));
|
|
4435
4496
|
const stray = await this.advisoryScalar(ctx, (0,_flusys_nestjs_shared_classes__rspack_import_0.buildQuery)(`SELECT COUNT(*) AS c FROM ${ctx.q(definition.tableName)} WHERE ${ctx.q(field.code)} IS NOT NULL AND ${ctx.q(field.code)} NOT IN (${values.map(()=>'?').join(', ')})`, ctx.driver), values);
|
|
4436
|
-
if (stray > 0) ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4497
|
+
if (stray > 0) ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.STRAY_VALUES */.Uu.STRAY_VALUES, {
|
|
4437
4498
|
count: stray
|
|
4438
4499
|
}));
|
|
4439
4500
|
}
|
|
@@ -4441,31 +4502,31 @@ class SchemaEvolutionService {
|
|
|
4441
4502
|
if ('validationRules' in changes) {
|
|
4442
4503
|
patch.validationRules = changes.validationRules;
|
|
4443
4504
|
const rules = changes.validationRules ?? {};
|
|
4444
|
-
const isNumber = merged.fieldType ===
|
|
4505
|
+
const isNumber = merged.fieldType === _enums_field_type_enum_js__rspack_import_21/* .FieldType.INTEGER */.P.INTEGER || merged.fieldType === _enums_field_type_enum_js__rspack_import_21/* .FieldType.DECIMAL */.P.DECIMAL;
|
|
4445
4506
|
const violating = [];
|
|
4446
4507
|
if (isNumber && typeof rules.min === 'number') violating.push(`${ctx.q(field.code)} < ${Number(rules.min)}`);
|
|
4447
4508
|
if (isNumber && typeof rules.max === 'number') violating.push(`${ctx.q(field.code)} > ${Number(rules.max)}`);
|
|
4448
4509
|
if (!isNumber && typeof rules.minLength === 'number') violating.push(`CHAR_LENGTH(${ctx.q(field.code)}) < ${Number(rules.minLength)}`);
|
|
4449
4510
|
if (!isNumber && typeof rules.maxLength === 'number') violating.push(`CHAR_LENGTH(${ctx.q(field.code)}) > ${Number(rules.maxLength)}`);
|
|
4450
4511
|
if (violating.length && [
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4512
|
+
_enums_field_type_enum_js__rspack_import_21/* .FieldType.INTEGER */.P.INTEGER,
|
|
4513
|
+
_enums_field_type_enum_js__rspack_import_21/* .FieldType.DECIMAL */.P.DECIMAL,
|
|
4514
|
+
_enums_field_type_enum_js__rspack_import_21/* .FieldType.TEXT */.P.TEXT,
|
|
4515
|
+
_enums_field_type_enum_js__rspack_import_21/* .FieldType.LONG_TEXT */.P.LONG_TEXT,
|
|
4516
|
+
_enums_field_type_enum_js__rspack_import_21/* .FieldType.EMAIL */.P.EMAIL
|
|
4456
4517
|
].includes(merged.fieldType)) {
|
|
4457
4518
|
const bad = await this.advisoryScalar(ctx, `SELECT COUNT(*) AS c FROM ${ctx.q(definition.tableName)} WHERE ${ctx.q(field.code)} IS NOT NULL AND (${violating.join(' OR ')})`);
|
|
4458
|
-
if (bad > 0) ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4519
|
+
if (bad > 0) ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.RULES_VIOLATED */.Uu.RULES_VIOLATED, {
|
|
4459
4520
|
count: bad
|
|
4460
4521
|
}));
|
|
4461
4522
|
}
|
|
4462
4523
|
}
|
|
4463
4524
|
// ── relation target ──
|
|
4464
|
-
if (merged.fieldType ===
|
|
4525
|
+
if (merged.fieldType === _enums_field_type_enum_js__rspack_import_21/* .FieldType.RELATION */.P.RELATION) {
|
|
4465
4526
|
const targetId = 'relationTargetEntityId' in changes ? changes.relationTargetEntityId : field.relationTargetEntityId;
|
|
4466
|
-
const becomesRelation = field.fieldType !==
|
|
4527
|
+
const becomesRelation = field.fieldType !== _enums_field_type_enum_js__rspack_import_21/* .FieldType.RELATION */.P.RELATION;
|
|
4467
4528
|
if (!targetId && (becomesRelation || 'relationTargetEntityId' in changes)) {
|
|
4468
|
-
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4529
|
+
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.RELATION_TARGET_REQUIRED */.M3.RELATION_TARGET_REQUIRED, {
|
|
4469
4530
|
field: field.code
|
|
4470
4531
|
}));
|
|
4471
4532
|
} else if (targetId && (becomesRelation || targetId !== field.relationTargetEntityId)) {
|
|
@@ -4474,7 +4535,7 @@ class SchemaEvolutionService {
|
|
|
4474
4535
|
id: targetId
|
|
4475
4536
|
}
|
|
4476
4537
|
});
|
|
4477
|
-
if (!target) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4538
|
+
if (!target) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.RELATION_TARGET_MISSING */.M3.RELATION_TARGET_MISSING));
|
|
4478
4539
|
else if (target.id !== field.relationTargetEntityId) patch.relationTargetEntityId = target.id;
|
|
4479
4540
|
}
|
|
4480
4541
|
} else if (field.relationTargetEntityId && changes.fieldType !== undefined) {
|
|
@@ -4483,7 +4544,7 @@ class SchemaEvolutionService {
|
|
|
4483
4544
|
if ('defaultValue' in changes) {
|
|
4484
4545
|
if (changes.defaultValue !== null && changes.defaultValue !== undefined) {
|
|
4485
4546
|
const problem = this.checkValue(merged, changes.defaultValue);
|
|
4486
|
-
if (problem) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4547
|
+
if (problem) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.DEFAULT_INVALID */.M3.DEFAULT_INVALID, {
|
|
4487
4548
|
problem
|
|
4488
4549
|
}));
|
|
4489
4550
|
}
|
|
@@ -4502,7 +4563,7 @@ class SchemaEvolutionService {
|
|
|
4502
4563
|
const where = check.badRowsWhere(ctx.q(field.code), ctx.driver);
|
|
4503
4564
|
const bad = await this.scalar(ctx, `SELECT COUNT(*) AS c FROM ${ctx.q(definition.tableName)} WHERE ${ctx.q(field.code)} IS NOT NULL AND (${where})`);
|
|
4504
4565
|
if (bad > 0) {
|
|
4505
|
-
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4566
|
+
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.CONVERSION_BAD_ROWS */.M3.CONVERSION_BAD_ROWS, {
|
|
4506
4567
|
count: bad,
|
|
4507
4568
|
check: check.description,
|
|
4508
4569
|
from: field.fieldType,
|
|
@@ -4515,12 +4576,12 @@ class SchemaEvolutionService {
|
|
|
4515
4576
|
ctx.markDestructive();
|
|
4516
4577
|
}
|
|
4517
4578
|
const newDefaultProblem = merged.defaultValue !== null && merged.defaultValue !== undefined ? this.checkValue(merged, merged.defaultValue) : null;
|
|
4518
|
-
if (newDefaultProblem) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4579
|
+
if (newDefaultProblem) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.CURRENT_DEFAULT_INVALID */.M3.CURRENT_DEFAULT_INVALID, {
|
|
4519
4580
|
type: merged.fieldType,
|
|
4520
4581
|
problem: newDefaultProblem
|
|
4521
4582
|
}));
|
|
4522
|
-
if ((merged.fieldType ===
|
|
4523
|
-
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4583
|
+
if ((merged.fieldType === _enums_field_type_enum_js__rspack_import_21/* .FieldType.SINGLE_SELECT */.P.SINGLE_SELECT || merged.fieldType === _enums_field_type_enum_js__rspack_import_21/* .FieldType.MULTI_SELECT */.P.MULTI_SELECT) && !merged.selectOptions?.length) {
|
|
4584
|
+
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.NO_SELECT_OPTIONS_CONVERT */.Uu.NO_SELECT_OPTIONS_CONVERT));
|
|
4524
4585
|
}
|
|
4525
4586
|
if (!ctx.blocked) {
|
|
4526
4587
|
const newDbType = this.adapter.mapFieldType(merged.fieldType, ctx.driver);
|
|
@@ -4532,7 +4593,7 @@ class SchemaEvolutionService {
|
|
|
4532
4593
|
const nullSql = column.isNullable ? 'NULL' : 'NOT NULL';
|
|
4533
4594
|
const up = ctx.driver === 'postgres' ? `ALTER TABLE ${t} ALTER COLUMN ${c} TYPE ${to} USING ${conversion.using ? conversion.using(c) : `${c}::${to}`}` : `ALTER TABLE ${t} MODIFY ${c} ${to} ${nullSql}`;
|
|
4534
4595
|
const down = ctx.driver === 'postgres' ? `ALTER TABLE ${t} ALTER COLUMN ${c} TYPE ${from} USING ${c}::${from}` : `ALTER TABLE ${t} MODIFY ${c} ${from} ${nullSql}`;
|
|
4535
|
-
await ctx.rawDdl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4596
|
+
await ctx.rawDdl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.CONVERT_TYPE */.EQ.CONVERT_TYPE, {
|
|
4536
4597
|
column: field.code,
|
|
4537
4598
|
from: field.fieldType,
|
|
4538
4599
|
to: merged.fieldType
|
|
@@ -4553,21 +4614,21 @@ class SchemaEvolutionService {
|
|
|
4553
4614
|
const nulls = await this.scalar(ctx, `SELECT COUNT(*) AS c FROM ${ctx.q(definition.tableName)} WHERE ${ctx.q(field.code)} IS NULL`);
|
|
4554
4615
|
const value = request.backfillValue ?? merged.defaultValue ?? null;
|
|
4555
4616
|
if (nulls > 0 && value === null) {
|
|
4556
|
-
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4617
|
+
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.NULLS_NEED_VALUE */.M3.NULLS_NEED_VALUE, {
|
|
4557
4618
|
count: nulls,
|
|
4558
4619
|
field: field.code
|
|
4559
4620
|
}));
|
|
4560
4621
|
} else if (nulls > 0) {
|
|
4561
4622
|
const problem = this.checkValue(merged, value);
|
|
4562
|
-
if (problem) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4623
|
+
if (problem) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.BACKFILL_INVALID */.M3.BACKFILL_INVALID, {
|
|
4563
4624
|
problem
|
|
4564
4625
|
}));
|
|
4565
4626
|
else {
|
|
4566
|
-
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4627
|
+
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.BACKFILL_WILL_SET */.Uu.BACKFILL_WILL_SET, {
|
|
4567
4628
|
count: nulls,
|
|
4568
4629
|
value: JSON.stringify(value)
|
|
4569
4630
|
}));
|
|
4570
|
-
await ctx.data((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4631
|
+
await ctx.data((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.BACKFILL_RECORDS */.EQ.BACKFILL_RECORDS, {
|
|
4571
4632
|
count: nulls
|
|
4572
4633
|
}), `UPDATE ${ctx.q(definition.tableName)} SET ${ctx.q(field.code)} = ${this.adapter.sqlLiteral(this.paramValue(merged.fieldType, value), ctx.driver)} WHERE ${ctx.q(field.code)} IS NULL`, async ()=>{
|
|
4573
4634
|
await ctx.qr.query((0,_flusys_nestjs_shared_classes__rspack_import_0.buildQuery)(`UPDATE ${ctx.q(definition.tableName)} SET ${ctx.q(field.code)} = ? WHERE ${ctx.q(field.code)} IS NULL`, ctx.driver), [
|
|
@@ -4589,19 +4650,19 @@ class SchemaEvolutionService {
|
|
|
4589
4650
|
if (changes.unique === true) {
|
|
4590
4651
|
const dups = await this.countDuplicates(ctx, definition.tableName, field.code);
|
|
4591
4652
|
if (dups > 0) {
|
|
4592
|
-
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4653
|
+
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.DUPLICATE_VALUES */.M3.DUPLICATE_VALUES, {
|
|
4593
4654
|
count: dups,
|
|
4594
4655
|
field: field.code
|
|
4595
4656
|
}));
|
|
4596
4657
|
} else {
|
|
4597
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4658
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.ADD_UNIQUE */.EQ.ADD_UNIQUE, {
|
|
4598
4659
|
column: field.code
|
|
4599
4660
|
}), async ()=>{
|
|
4600
4661
|
await (0,_schema_columns_js__rspack_import_17/* .addUnique */.$6)(ctx.qr, table, field.code, ctx.driver, this.adapter);
|
|
4601
4662
|
});
|
|
4602
4663
|
}
|
|
4603
4664
|
} else {
|
|
4604
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4665
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.REMOVE_UNIQUE */.EQ.REMOVE_UNIQUE, {
|
|
4605
4666
|
column: field.code
|
|
4606
4667
|
}), async ()=>this.dropUniques(ctx, table, field.code));
|
|
4607
4668
|
}
|
|
@@ -4610,13 +4671,13 @@ class SchemaEvolutionService {
|
|
|
4610
4671
|
// ── index ──
|
|
4611
4672
|
if (changes.isIndexed !== undefined && changes.isIndexed !== field.isIndexed && table && column && !ctx.blocked) {
|
|
4612
4673
|
if (changes.isIndexed) {
|
|
4613
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4674
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.ADD_INDEX */.EQ.ADD_INDEX, {
|
|
4614
4675
|
column: field.code
|
|
4615
4676
|
}), async ()=>{
|
|
4616
|
-
await ctx.qr.createIndex(table, (0,_schema_columns_js__rspack_import_17/* .plainIndex */.v7)(definition.tableName, field.code, ctx.driver, this.adapter));
|
|
4677
|
+
await ctx.qr.createIndex(table, (0,_schema_columns_js__rspack_import_17/* .plainIndex */.v7)(definition.tableName, field.code, ctx.driver, this.adapter, this.liveOnly(definition, ctx.driver)));
|
|
4617
4678
|
});
|
|
4618
4679
|
} else {
|
|
4619
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4680
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.REMOVE_INDEX */.EQ.REMOVE_INDEX, {
|
|
4620
4681
|
column: field.code
|
|
4621
4682
|
}), async ()=>{
|
|
4622
4683
|
for (const idx of this.indexOn(table, field.code, false))await ctx.qr.dropIndex(table, idx);
|
|
@@ -4627,22 +4688,22 @@ class SchemaEvolutionService {
|
|
|
4627
4688
|
// ── rename ──
|
|
4628
4689
|
if (newCode && table && column) {
|
|
4629
4690
|
const taken = fields.find((f)=>f.code === newCode);
|
|
4630
|
-
if (taken) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(taken.deprecatedAt ?
|
|
4691
|
+
if (taken) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(taken.deprecatedAt ? _config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.FIELD_CODE_TAKEN_DEPRECATED */.M3.FIELD_CODE_TAKEN_DEPRECATED : _config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.FIELD_CODE_TAKEN */.M3.FIELD_CODE_TAKEN, {
|
|
4631
4692
|
code: newCode
|
|
4632
4693
|
}));
|
|
4633
4694
|
if (impact.length && request.rewriteReferences === false) {
|
|
4634
|
-
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4695
|
+
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.RENAME_IN_USE */.M3.RENAME_IN_USE, {
|
|
4635
4696
|
field: field.code,
|
|
4636
|
-
references: (0,
|
|
4697
|
+
references: (0,_schema_change_types_js__rspack_import_23/* .describeImpact */.a)(impact)
|
|
4637
4698
|
}));
|
|
4638
4699
|
} else if (impact.length) {
|
|
4639
|
-
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4700
|
+
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.REFERENCES_REWRITTEN */.Uu.REFERENCES_REWRITTEN, {
|
|
4640
4701
|
count: impact.length,
|
|
4641
4702
|
code: newCode
|
|
4642
4703
|
}));
|
|
4643
4704
|
}
|
|
4644
4705
|
if (!ctx.blocked) {
|
|
4645
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4706
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.RENAME_COLUMN */.EQ.RENAME_COLUMN, {
|
|
4646
4707
|
from: field.code,
|
|
4647
4708
|
to: newCode
|
|
4648
4709
|
}), async ()=>{
|
|
@@ -4651,15 +4712,14 @@ class SchemaEvolutionService {
|
|
|
4651
4712
|
// TypeORM moves the index/unique onto the renamed column but keeps its name, which is
|
|
4652
4713
|
// derived from the old code - recreate them so a new field with the old code can have its own.
|
|
4653
4714
|
if (field.isIndexed && !field.unique) {
|
|
4654
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4715
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.RENAME_INDEX */.EQ.RENAME_INDEX, {
|
|
4655
4716
|
column: field.code
|
|
4656
4717
|
}), async ()=>{
|
|
4657
|
-
|
|
4658
|
-
await ctx.qr.createIndex(table, (0,_schema_columns_js__rspack_import_17/* .plainIndex */.v7)(definition.tableName, newCode, ctx.driver, this.adapter));
|
|
4718
|
+
await this.rebuildPlainIndex(ctx, table, definition.tableName, newCode, this.liveOnly(definition, ctx.driver));
|
|
4659
4719
|
});
|
|
4660
4720
|
}
|
|
4661
4721
|
if (field.unique) {
|
|
4662
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4722
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.RENAME_INDEX */.EQ.RENAME_INDEX, {
|
|
4663
4723
|
column: field.code
|
|
4664
4724
|
}), async ()=>{
|
|
4665
4725
|
await this.dropUniques(ctx, table, newCode);
|
|
@@ -4670,7 +4730,7 @@ class SchemaEvolutionService {
|
|
|
4670
4730
|
}
|
|
4671
4731
|
}
|
|
4672
4732
|
if (ctx.blocked) return {
|
|
4673
|
-
operation:
|
|
4733
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.ALTER_FIELD */.i.ALTER_FIELD,
|
|
4674
4734
|
fieldDefinitionId: field.id,
|
|
4675
4735
|
diff: {}
|
|
4676
4736
|
};
|
|
@@ -4682,7 +4742,7 @@ class SchemaEvolutionService {
|
|
|
4682
4742
|
});
|
|
4683
4743
|
const metadataOnly = !structural.length && !newCode;
|
|
4684
4744
|
return {
|
|
4685
|
-
operation: newCode ?
|
|
4745
|
+
operation: newCode ? _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.RENAME_FIELD */.i.RENAME_FIELD : _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.ALTER_FIELD */.i.ALTER_FIELD,
|
|
4686
4746
|
fieldDefinitionId: field.id,
|
|
4687
4747
|
diff: {
|
|
4688
4748
|
field: field.code,
|
|
@@ -4693,13 +4753,7 @@ class SchemaEvolutionService {
|
|
|
4693
4753
|
])),
|
|
4694
4754
|
after: patch
|
|
4695
4755
|
},
|
|
4696
|
-
bumpVersion: !metadataOnly || Object.keys(patch).some((k)=>
|
|
4697
|
-
'selectOptions',
|
|
4698
|
-
'validationRules',
|
|
4699
|
-
'defaultValue',
|
|
4700
|
-
'label',
|
|
4701
|
-
'relationTargetEntityId'
|
|
4702
|
-
].includes(k))
|
|
4756
|
+
bumpVersion: !metadataOnly || Object.keys(patch).some((k)=>FIELD_CACHE_KEYS.has(k))
|
|
4703
4757
|
};
|
|
4704
4758
|
};
|
|
4705
4759
|
return {
|
|
@@ -4714,23 +4768,23 @@ class SchemaEvolutionService {
|
|
|
4714
4768
|
const impact = await this.references.forField(loaded.code, loadedField.code);
|
|
4715
4769
|
const run = async (ctx)=>{
|
|
4716
4770
|
const { definition, field } = await this.current(ctx, request, loaded.id, loadedField.id);
|
|
4717
|
-
if (field.code !== loadedField.code) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4718
|
-
if (field.deprecatedAt) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4771
|
+
if (field.code !== loadedField.code) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.DEFINITION_CHANGED */.M3.DEFINITION_CHANGED));
|
|
4772
|
+
if (field.deprecatedAt) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.ALREADY_DEPRECATED */.M3.ALREADY_DEPRECATED, {
|
|
4719
4773
|
field: field.code
|
|
4720
4774
|
}));
|
|
4721
|
-
if (impact.length) ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4722
|
-
references: (0,
|
|
4775
|
+
if (impact.length) ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.STILL_REFERENCED */.Uu.STILL_REFERENCED, {
|
|
4776
|
+
references: (0,_schema_change_types_js__rspack_import_23/* .describeImpact */.a)(impact)
|
|
4723
4777
|
}));
|
|
4724
4778
|
const table = await this.requireTable(ctx, definition.tableName);
|
|
4725
4779
|
const column = table?.findColumnByName(field.code);
|
|
4726
4780
|
if (ctx.blocked) return {
|
|
4727
|
-
operation:
|
|
4781
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.MARK_DEPRECATED */.i.MARK_DEPRECATED,
|
|
4728
4782
|
fieldDefinitionId: field.id,
|
|
4729
4783
|
diff: {}
|
|
4730
4784
|
};
|
|
4731
4785
|
// A hidden NOT NULL column would make every new record fail (nobody supplies it any more).
|
|
4732
4786
|
if (column && !column.isNullable) {
|
|
4733
|
-
await this.setRequired(ctx, definition.tableName, field.code, field.fieldType, false,
|
|
4787
|
+
await this.setRequired(ctx, definition.tableName, field.code, field.fieldType, false, _config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.RELAX_DEPRECATED */.EQ.RELAX_DEPRECATED);
|
|
4734
4788
|
}
|
|
4735
4789
|
await ctx.metadata(async ()=>{
|
|
4736
4790
|
await ctx.qr.manager.getRepository(_entities_field_definition_entity_js__rspack_import_8/* .FieldDefinition */.c).update(field.id, {
|
|
@@ -4739,7 +4793,7 @@ class SchemaEvolutionService {
|
|
|
4739
4793
|
});
|
|
4740
4794
|
});
|
|
4741
4795
|
return {
|
|
4742
|
-
operation:
|
|
4796
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.MARK_DEPRECATED */.i.MARK_DEPRECATED,
|
|
4743
4797
|
fieldDefinitionId: field.id,
|
|
4744
4798
|
diff: {
|
|
4745
4799
|
field: field.code
|
|
@@ -4756,15 +4810,15 @@ class SchemaEvolutionService {
|
|
|
4756
4810
|
const { field: loadedField, definition: loaded } = await this.loadField(request.fieldDefinitionId);
|
|
4757
4811
|
const run = async (ctx)=>{
|
|
4758
4812
|
const { definition, field } = await this.current(ctx, request, loaded.id, loadedField.id);
|
|
4759
|
-
if (!field.deprecatedAt) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4813
|
+
if (!field.deprecatedAt) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.NOT_DEPRECATED */.M3.NOT_DEPRECATED, {
|
|
4760
4814
|
field: field.code
|
|
4761
4815
|
}));
|
|
4762
4816
|
const table = await this.requireTable(ctx, definition.tableName);
|
|
4763
|
-
if (table && !table.findColumnByName(field.code)) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4817
|
+
if (table && !table.findColumnByName(field.code)) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.COLUMN_GONE */.M3.COLUMN_GONE, {
|
|
4764
4818
|
column: field.code
|
|
4765
4819
|
}));
|
|
4766
4820
|
if (ctx.blocked) return {
|
|
4767
|
-
operation:
|
|
4821
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.RESTORE_FIELD */.i.RESTORE_FIELD,
|
|
4768
4822
|
fieldDefinitionId: field.id,
|
|
4769
4823
|
diff: {}
|
|
4770
4824
|
};
|
|
@@ -4773,9 +4827,9 @@ class SchemaEvolutionService {
|
|
|
4773
4827
|
deprecatedAt: null
|
|
4774
4828
|
});
|
|
4775
4829
|
});
|
|
4776
|
-
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4830
|
+
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.FIELD_OPTIONAL_AGAIN */.Uu.FIELD_OPTIONAL_AGAIN));
|
|
4777
4831
|
return {
|
|
4778
|
-
operation:
|
|
4832
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.RESTORE_FIELD */.i.RESTORE_FIELD,
|
|
4779
4833
|
fieldDefinitionId: field.id,
|
|
4780
4834
|
diff: {
|
|
4781
4835
|
field: field.code
|
|
@@ -4794,45 +4848,45 @@ class SchemaEvolutionService {
|
|
|
4794
4848
|
const run = async (ctx)=>{
|
|
4795
4849
|
const { definition, field } = await this.current(ctx, request, loaded.id, loadedField.id);
|
|
4796
4850
|
if (this.changedUnderneath(ctx, loadedField, field)) return {
|
|
4797
|
-
operation:
|
|
4851
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.DROP_COLUMN */.i.DROP_COLUMN,
|
|
4798
4852
|
fieldDefinitionId: field.id,
|
|
4799
4853
|
diff: {}
|
|
4800
4854
|
};
|
|
4801
|
-
if (!field.deprecatedAt) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4802
|
-
if (request.confirmCode !== field.code) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4855
|
+
if (!field.deprecatedAt) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.PURGE_REQUIRES_DEPRECATED */.M3.PURGE_REQUIRES_DEPRECATED));
|
|
4856
|
+
if (request.confirmCode !== field.code) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.PURGE_CONFIRM_CODE */.M3.PURGE_CONFIRM_CODE, {
|
|
4803
4857
|
code: field.code
|
|
4804
4858
|
}));
|
|
4805
|
-
if (impact.length) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4859
|
+
if (impact.length) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.PURGE_IN_USE */.M3.PURGE_IN_USE, {
|
|
4806
4860
|
field: field.code,
|
|
4807
|
-
references: (0,
|
|
4861
|
+
references: (0,_schema_change_types_js__rspack_import_23/* .describeImpact */.a)(impact)
|
|
4808
4862
|
}));
|
|
4809
4863
|
const table = await this.requireTable(ctx, definition.tableName);
|
|
4810
4864
|
const column = table?.findColumnByName(field.code);
|
|
4811
4865
|
if (ctx.blocked) return {
|
|
4812
|
-
operation:
|
|
4866
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.DROP_COLUMN */.i.DROP_COLUMN,
|
|
4813
4867
|
fieldDefinitionId: field.id,
|
|
4814
4868
|
diff: {}
|
|
4815
4869
|
};
|
|
4816
4870
|
if (table && column) {
|
|
4817
4871
|
const values = await this.scalar(ctx, `SELECT COUNT(*) AS c FROM ${ctx.q(definition.tableName)} WHERE ${ctx.q(field.code)} IS NOT NULL`);
|
|
4818
4872
|
ctx.setAffectedRows(values);
|
|
4819
|
-
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4873
|
+
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.VALUES_DELETED */.Uu.VALUES_DELETED, {
|
|
4820
4874
|
count: values
|
|
4821
4875
|
}));
|
|
4822
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4876
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.DROP_COLUMN */.EQ.DROP_COLUMN, {
|
|
4823
4877
|
column: field.code
|
|
4824
4878
|
}), async ()=>{
|
|
4825
4879
|
await ctx.qr.dropColumn(table, column);
|
|
4826
4880
|
});
|
|
4827
4881
|
} else {
|
|
4828
|
-
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4882
|
+
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.COLUMN_ALREADY_MISSING */.Uu.COLUMN_ALREADY_MISSING));
|
|
4829
4883
|
}
|
|
4830
4884
|
ctx.markDestructive();
|
|
4831
4885
|
await ctx.metadata(async ()=>{
|
|
4832
4886
|
await ctx.qr.manager.getRepository(_entities_field_definition_entity_js__rspack_import_8/* .FieldDefinition */.c).delete(field.id);
|
|
4833
4887
|
});
|
|
4834
4888
|
return {
|
|
4835
|
-
operation:
|
|
4889
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.DROP_COLUMN */.i.DROP_COLUMN,
|
|
4836
4890
|
fieldDefinitionId: null,
|
|
4837
4891
|
diff: {
|
|
4838
4892
|
field: field.code,
|
|
@@ -4852,16 +4906,16 @@ class SchemaEvolutionService {
|
|
|
4852
4906
|
const changes = request.changes ?? {};
|
|
4853
4907
|
this.rejectUnknownKeys(changes, _dtos_schema_change_dto_js__rspack_import_6/* .ENTITY_CHANGE_KEYS */.Oi, 'entity');
|
|
4854
4908
|
if (changes.status !== undefined && ![
|
|
4855
|
-
|
|
4856
|
-
|
|
4909
|
+
_enums_entity_status_enum_js__rspack_import_24/* .EntityStatus.ACTIVE */.c.ACTIVE,
|
|
4910
|
+
_enums_entity_status_enum_js__rspack_import_24/* .EntityStatus.DEPRECATED */.c.DEPRECATED
|
|
4857
4911
|
].includes(changes.status)) {
|
|
4858
4912
|
throw new _nestjs_common__rspack_import_2.BadRequestException({
|
|
4859
4913
|
message: "status must be 'ACTIVE' or 'DEPRECATED'.",
|
|
4860
|
-
messageKey:
|
|
4914
|
+
messageKey: _config_message_keys_js__rspack_import_20/* .ENTITY_DEFINITION_MESSAGES.INVALID_STATUS */.pL.INVALID_STATUS
|
|
4861
4915
|
});
|
|
4862
4916
|
}
|
|
4863
4917
|
this.validateChanges(_dtos_schema_change_dto_js__rspack_import_6/* .EntityChangesDto */.OW, changes);
|
|
4864
|
-
const impact = changes.status ===
|
|
4918
|
+
const impact = changes.status === _enums_entity_status_enum_js__rspack_import_24/* .EntityStatus.DEPRECATED */.c.DEPRECATED ? await this.references.forEntity(loaded.code) : [];
|
|
4865
4919
|
const run = async (ctx)=>{
|
|
4866
4920
|
const { definition } = await this.current(ctx, request, loaded.id);
|
|
4867
4921
|
const patch = {};
|
|
@@ -4878,37 +4932,38 @@ class SchemaEvolutionService {
|
|
|
4878
4932
|
const touchesColumns = wantsSoft === true && !definition.isSoftDeleteEnabled || wantsAudit === true && !definition.isAuditEnabled;
|
|
4879
4933
|
const table = touchesColumns ? await this.requireTable(ctx, definition.tableName) : undefined;
|
|
4880
4934
|
if (ctx.blocked) return {
|
|
4881
|
-
operation:
|
|
4935
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.ALTER_ENTITY */.i.ALTER_ENTITY,
|
|
4882
4936
|
diff: {}
|
|
4883
4937
|
};
|
|
4884
4938
|
if (wantsSoft !== undefined && wantsSoft !== definition.isSoftDeleteEnabled) {
|
|
4885
4939
|
if (wantsSoft && table) {
|
|
4886
4940
|
if (!table.findColumnByName('deleted_at')) {
|
|
4887
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4941
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.ADD_DELETED_AT */.EQ.ADD_DELETED_AT), async ()=>{
|
|
4888
4942
|
await ctx.qr.addColumn(table, (0,_schema_columns_js__rspack_import_17/* .softDeleteColumn */.OG)());
|
|
4889
4943
|
});
|
|
4890
4944
|
}
|
|
4891
4945
|
} else if (!wantsSoft) {
|
|
4892
|
-
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4946
|
+
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.SOFT_DELETE_OFF */.Uu.SOFT_DELETE_OFF));
|
|
4893
4947
|
ctx.markDestructive();
|
|
4894
4948
|
}
|
|
4895
4949
|
patch.isSoftDeleteEnabled = wantsSoft;
|
|
4950
|
+
await this.reshapePlainIndexes(ctx, definition, wantsSoft);
|
|
4896
4951
|
}
|
|
4897
4952
|
if (wantsAudit !== undefined && wantsAudit !== definition.isAuditEnabled) {
|
|
4898
4953
|
if (wantsAudit && table) {
|
|
4899
4954
|
const missing = (0,_schema_columns_js__rspack_import_17/* .auditColumns */.HK)(ctx.driver).filter((c)=>!table.findColumnByName(c.name));
|
|
4900
4955
|
if (missing.length) {
|
|
4901
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4956
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.ADD_AUDIT_COLUMNS */.EQ.ADD_AUDIT_COLUMNS), async ()=>{
|
|
4902
4957
|
for (const c of missing)await ctx.qr.addColumn(table, c);
|
|
4903
4958
|
});
|
|
4904
4959
|
}
|
|
4905
4960
|
} else if (!wantsAudit) {
|
|
4906
|
-
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4961
|
+
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.AUDIT_OFF */.Uu.AUDIT_OFF));
|
|
4907
4962
|
}
|
|
4908
4963
|
patch.isAuditEnabled = wantsAudit;
|
|
4909
4964
|
}
|
|
4910
|
-
if (changes.status ===
|
|
4911
|
-
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4965
|
+
if (changes.status === _enums_entity_status_enum_js__rspack_import_24/* .EntityStatus.DEPRECATED */.c.DEPRECATED && impact.length) {
|
|
4966
|
+
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.ENTITY_REFERENCED */.Uu.ENTITY_REFERENCED, {
|
|
4912
4967
|
count: impact.length
|
|
4913
4968
|
}));
|
|
4914
4969
|
}
|
|
@@ -4916,7 +4971,7 @@ class SchemaEvolutionService {
|
|
|
4916
4971
|
if (Object.keys(patch).length) await ctx.qr.manager.getRepository(_entities_entity_definition_entity_js__rspack_import_7/* .EntityDefinition */.f).update(definition.id, patch);
|
|
4917
4972
|
});
|
|
4918
4973
|
return {
|
|
4919
|
-
operation:
|
|
4974
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.ALTER_ENTITY */.i.ALTER_ENTITY,
|
|
4920
4975
|
diff: {
|
|
4921
4976
|
changed: Object.keys(patch),
|
|
4922
4977
|
after: patch
|
|
@@ -4929,6 +4984,32 @@ class SchemaEvolutionService {
|
|
|
4929
4984
|
impact
|
|
4930
4985
|
};
|
|
4931
4986
|
}
|
|
4987
|
+
/**
|
|
4988
|
+
* Soft delete switched on or off: a plain index over live rows only is of no use to reads that no longer
|
|
4989
|
+
* ask for live rows (and the other way round), so every plain index takes the shape the entity now wants.
|
|
4990
|
+
*/ async reshapePlainIndexes(ctx, definition, softDelete) {
|
|
4991
|
+
if (ctx.driver !== 'postgres') return;
|
|
4992
|
+
const table = await ctx.qr.getTable(definition.tableName);
|
|
4993
|
+
if (!table) return;
|
|
4994
|
+
const liveOnly = this.liveOnly({
|
|
4995
|
+
isSoftDeleteEnabled: softDelete
|
|
4996
|
+
}, ctx.driver);
|
|
4997
|
+
const fields = await ctx.qr.manager.getRepository(_entities_field_definition_entity_js__rspack_import_8/* .FieldDefinition */.c).find({
|
|
4998
|
+
where: {
|
|
4999
|
+
entityDefinitionId: definition.id
|
|
5000
|
+
}
|
|
5001
|
+
});
|
|
5002
|
+
for (const field of fields.filter((f)=>f.isIndexed && !f.unique && table.findColumnByName(f.code))){
|
|
5003
|
+
// A missing index is left to `repair`; only one of the wrong shape is rebuilt here.
|
|
5004
|
+
const existing = this.indexOn(table, field.code, false);
|
|
5005
|
+
if (!existing.length || existing.every((index)=>(0,_schema_columns_js__rspack_import_17/* .isLiveRowsIndex */.YS)(index) === liveOnly)) continue;
|
|
5006
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.RECREATE_INDEX */.EQ.RECREATE_INDEX, {
|
|
5007
|
+
column: field.code
|
|
5008
|
+
}), async ()=>{
|
|
5009
|
+
await this.rebuildPlainIndex(ctx, table, definition.tableName, field.code, liveOnly);
|
|
5010
|
+
});
|
|
5011
|
+
}
|
|
5012
|
+
}
|
|
4932
5013
|
/** `"orders.customer_id", ...` - relation fields of other entities that point at this one. */ async relationsInto(ctx, definition) {
|
|
4933
5014
|
const pointing = (await ctx.qr.manager.getRepository(_entities_field_definition_entity_js__rspack_import_8/* .FieldDefinition */.c).find({
|
|
4934
5015
|
where: {
|
|
@@ -4954,34 +5035,34 @@ class SchemaEvolutionService {
|
|
|
4954
5035
|
const impact = await this.references.forEntity(loaded.code);
|
|
4955
5036
|
const run = async (ctx)=>{
|
|
4956
5037
|
const { definition } = await this.current(ctx, request, loaded.id);
|
|
4957
|
-
if (request.confirmCode !== definition.code) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5038
|
+
if (request.confirmCode !== definition.code) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.DROP_CONFIRM_CODE */.M3.DROP_CONFIRM_CODE, {
|
|
4958
5039
|
code: definition.code
|
|
4959
5040
|
}));
|
|
4960
|
-
if (impact.length) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
4961
|
-
references: (0,
|
|
5041
|
+
if (impact.length) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.DROP_IN_USE */.M3.DROP_IN_USE, {
|
|
5042
|
+
references: (0,_schema_change_types_js__rspack_import_23/* .describeImpact */.a)(impact)
|
|
4962
5043
|
}));
|
|
4963
5044
|
const relations = await this.relationsInto(ctx, definition);
|
|
4964
|
-
if (relations) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5045
|
+
if (relations) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_BLOCKER_MESSAGES.DROP_RELATION_IN_USE */.M3.DROP_RELATION_IN_USE, {
|
|
4965
5046
|
fields: relations
|
|
4966
5047
|
}));
|
|
4967
5048
|
const table = await ctx.qr.getTable(definition.tableName);
|
|
4968
5049
|
if (ctx.blocked) return {
|
|
4969
|
-
operation:
|
|
5050
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.DROP_TABLE */.i.DROP_TABLE,
|
|
4970
5051
|
diff: {}
|
|
4971
5052
|
};
|
|
4972
5053
|
if (table) {
|
|
4973
5054
|
const rows = await this.scalar(ctx, `SELECT COUNT(*) AS c FROM ${ctx.q(definition.tableName)}`);
|
|
4974
5055
|
ctx.setAffectedRows(rows);
|
|
4975
|
-
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5056
|
+
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.RECORDS_DELETED */.Uu.RECORDS_DELETED, {
|
|
4976
5057
|
count: rows
|
|
4977
5058
|
}));
|
|
4978
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5059
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.DROP_TABLE */.EQ.DROP_TABLE, {
|
|
4979
5060
|
table: definition.tableName
|
|
4980
5061
|
}), async ()=>{
|
|
4981
5062
|
await ctx.qr.dropTable(table);
|
|
4982
5063
|
});
|
|
4983
5064
|
} else {
|
|
4984
|
-
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5065
|
+
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.TABLE_ALREADY_MISSING */.Uu.TABLE_ALREADY_MISSING));
|
|
4985
5066
|
}
|
|
4986
5067
|
ctx.markDestructive();
|
|
4987
5068
|
await ctx.metadata(async ()=>{
|
|
@@ -4991,7 +5072,7 @@ class SchemaEvolutionService {
|
|
|
4991
5072
|
await ctx.qr.manager.getRepository(_entities_entity_definition_entity_js__rspack_import_7/* .EntityDefinition */.f).delete(definition.id);
|
|
4992
5073
|
});
|
|
4993
5074
|
return {
|
|
4994
|
-
operation:
|
|
5075
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.DROP_TABLE */.i.DROP_TABLE,
|
|
4995
5076
|
diff: {
|
|
4996
5077
|
entity: definition.code
|
|
4997
5078
|
},
|
|
@@ -5012,7 +5093,7 @@ class SchemaEvolutionService {
|
|
|
5012
5093
|
findings.push({
|
|
5013
5094
|
kind: 'missing_table',
|
|
5014
5095
|
severity: 'error',
|
|
5015
|
-
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5096
|
+
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_FINDING_MESSAGES.MISSING_TABLE */.Vu.MISSING_TABLE, {
|
|
5016
5097
|
table: definition.tableName
|
|
5017
5098
|
}),
|
|
5018
5099
|
repairable: true
|
|
@@ -5032,7 +5113,7 @@ class SchemaEvolutionService {
|
|
|
5032
5113
|
kind: 'missing_column',
|
|
5033
5114
|
severity: 'error',
|
|
5034
5115
|
field: name,
|
|
5035
|
-
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5116
|
+
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_FINDING_MESSAGES.SYSTEM_COLUMN_MISSING */.Vu.SYSTEM_COLUMN_MISSING, {
|
|
5036
5117
|
column: name
|
|
5037
5118
|
}),
|
|
5038
5119
|
repairable: name !== 'id'
|
|
@@ -5047,7 +5128,7 @@ class SchemaEvolutionService {
|
|
|
5047
5128
|
kind: 'missing_column',
|
|
5048
5129
|
severity: field.deprecatedAt ? 'warning' : 'error',
|
|
5049
5130
|
field: field.code,
|
|
5050
|
-
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5131
|
+
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_FINDING_MESSAGES.COLUMN_MISSING */.Vu.COLUMN_MISSING, {
|
|
5051
5132
|
column: field.code
|
|
5052
5133
|
}),
|
|
5053
5134
|
repairable: true
|
|
@@ -5062,7 +5143,7 @@ class SchemaEvolutionService {
|
|
|
5062
5143
|
kind: 'type_mismatch',
|
|
5063
5144
|
severity: 'error',
|
|
5064
5145
|
field: field.code,
|
|
5065
|
-
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5146
|
+
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_FINDING_MESSAGES.TYPE_MISMATCH */.Vu.TYPE_MISMATCH, {
|
|
5066
5147
|
column: field.code,
|
|
5067
5148
|
actual: column.type,
|
|
5068
5149
|
fieldType: field.fieldType,
|
|
@@ -5076,7 +5157,7 @@ class SchemaEvolutionService {
|
|
|
5076
5157
|
kind: 'nullability_mismatch',
|
|
5077
5158
|
severity: 'warning',
|
|
5078
5159
|
field: field.code,
|
|
5079
|
-
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5160
|
+
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_FINDING_MESSAGES.REQUIRED_BUT_NULLABLE */.Vu.REQUIRED_BUT_NULLABLE, {
|
|
5080
5161
|
column: field.code
|
|
5081
5162
|
}),
|
|
5082
5163
|
repairable: true
|
|
@@ -5087,18 +5168,19 @@ class SchemaEvolutionService {
|
|
|
5087
5168
|
kind: 'nullability_mismatch',
|
|
5088
5169
|
severity: 'warning',
|
|
5089
5170
|
field: field.code,
|
|
5090
|
-
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5171
|
+
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_FINDING_MESSAGES.OPTIONAL_BUT_NOT_NULL */.Vu.OPTIONAL_BUT_NOT_NULL, {
|
|
5091
5172
|
column: field.code
|
|
5092
5173
|
}),
|
|
5093
5174
|
repairable: true
|
|
5094
5175
|
});
|
|
5095
5176
|
}
|
|
5096
|
-
|
|
5177
|
+
// A plain index of the other shape (live rows only / all rows) counts as missing: repair rebuilds it.
|
|
5178
|
+
if (field.isIndexed && !field.unique && !this.hasPlainIndex(table, field.code, this.liveOnly(definition, driver))) {
|
|
5097
5179
|
findings.push({
|
|
5098
5180
|
kind: 'missing_index',
|
|
5099
5181
|
severity: 'warning',
|
|
5100
5182
|
field: field.code,
|
|
5101
|
-
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5183
|
+
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_FINDING_MESSAGES.INDEX_MISSING */.Vu.INDEX_MISSING, {
|
|
5102
5184
|
column: field.code
|
|
5103
5185
|
}),
|
|
5104
5186
|
repairable: true
|
|
@@ -5109,7 +5191,7 @@ class SchemaEvolutionService {
|
|
|
5109
5191
|
kind: 'missing_unique',
|
|
5110
5192
|
severity: 'warning',
|
|
5111
5193
|
field: field.code,
|
|
5112
|
-
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5194
|
+
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_FINDING_MESSAGES.UNIQUE_MISSING */.Vu.UNIQUE_MISSING, {
|
|
5113
5195
|
column: field.code
|
|
5114
5196
|
}),
|
|
5115
5197
|
repairable: true
|
|
@@ -5120,7 +5202,7 @@ class SchemaEvolutionService {
|
|
|
5120
5202
|
kind: 'stale_metadata',
|
|
5121
5203
|
severity: 'warning',
|
|
5122
5204
|
field: field.code,
|
|
5123
|
-
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5205
|
+
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_FINDING_MESSAGES.STALE_METADATA */.Vu.STALE_METADATA, {
|
|
5124
5206
|
dbType: field.dbType,
|
|
5125
5207
|
driver,
|
|
5126
5208
|
fieldType: field.fieldType
|
|
@@ -5135,7 +5217,7 @@ class SchemaEvolutionService {
|
|
|
5135
5217
|
kind: 'extra_column',
|
|
5136
5218
|
severity: 'warning',
|
|
5137
5219
|
field: column.name,
|
|
5138
|
-
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5220
|
+
...(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_FINDING_MESSAGES.EXTRA_COLUMN */.Vu.EXTRA_COLUMN, {
|
|
5139
5221
|
column: column.name
|
|
5140
5222
|
}),
|
|
5141
5223
|
repairable: false
|
|
@@ -5166,24 +5248,24 @@ class SchemaEvolutionService {
|
|
|
5166
5248
|
columns,
|
|
5167
5249
|
uniques
|
|
5168
5250
|
});
|
|
5169
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5251
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.RECREATE_TABLE */.EQ.RECREATE_TABLE, {
|
|
5170
5252
|
table: definition.tableName
|
|
5171
5253
|
}), async ()=>{
|
|
5172
5254
|
await ctx.qr.createTable(recreated, false);
|
|
5173
5255
|
});
|
|
5174
5256
|
fixed.push('missing_table');
|
|
5175
5257
|
for (const indexed of fields.filter((f)=>f.isIndexed && !f.unique)){
|
|
5176
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5258
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.RECREATE_INDEX */.EQ.RECREATE_INDEX, {
|
|
5177
5259
|
column: indexed.code
|
|
5178
5260
|
}), async ()=>{
|
|
5179
|
-
await ctx.qr.createIndex(recreated, (0,_schema_columns_js__rspack_import_17/* .plainIndex */.v7)(definition.tableName, indexed.code, ctx.driver, this.adapter));
|
|
5261
|
+
await ctx.qr.createIndex(recreated, (0,_schema_columns_js__rspack_import_17/* .plainIndex */.v7)(definition.tableName, indexed.code, ctx.driver, this.adapter, this.liveOnly(definition, ctx.driver)));
|
|
5180
5262
|
});
|
|
5181
5263
|
fixed.push(`missing_index:${indexed.code}`);
|
|
5182
5264
|
}
|
|
5183
|
-
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5265
|
+
ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.TABLE_RECREATED_EMPTY */.Uu.TABLE_RECREATED_EMPTY));
|
|
5184
5266
|
ctx.markDestructive();
|
|
5185
5267
|
return {
|
|
5186
|
-
operation:
|
|
5268
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.REPAIR */.i.REPAIR,
|
|
5187
5269
|
diff: {
|
|
5188
5270
|
fixed,
|
|
5189
5271
|
manual: 0
|
|
@@ -5197,16 +5279,16 @@ class SchemaEvolutionService {
|
|
|
5197
5279
|
case 'missing_column':
|
|
5198
5280
|
{
|
|
5199
5281
|
if (!field) {
|
|
5200
|
-
const sys =
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5282
|
+
const sys = (0,_schema_columns_js__rspack_import_17/* .buildSystemColumns */.Rm)({
|
|
5283
|
+
isSoftDeleteEnabled: true,
|
|
5284
|
+
isAuditEnabled: true
|
|
5285
|
+
}, ctx.driver).find((c)=>c.name === finding.field && !c.isPrimary);
|
|
5204
5286
|
if (!sys) break;
|
|
5205
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5287
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.ADD_SYSTEM_COLUMN */.EQ.ADD_SYSTEM_COLUMN, {
|
|
5206
5288
|
column: sys.name
|
|
5207
5289
|
}), async ()=>ctx.qr.addColumn(table, sys));
|
|
5208
5290
|
} else {
|
|
5209
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5291
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.ADD_MISSING_COLUMN */.EQ.ADD_MISSING_COLUMN, {
|
|
5210
5292
|
column: field.code
|
|
5211
5293
|
}), async ()=>{
|
|
5212
5294
|
await ctx.qr.addColumn(table, (0,_schema_columns_js__rspack_import_17/* .buildFieldColumn */.fu)(field, ctx.driver, this.adapter, {
|
|
@@ -5216,7 +5298,7 @@ class SchemaEvolutionService {
|
|
|
5216
5298
|
});
|
|
5217
5299
|
// Re-added columns start empty, so a required field stays nullable until its records have values.
|
|
5218
5300
|
const rows = !field.nullable && !field.deprecatedAt ? await this.scalar(ctx, `SELECT COUNT(*) AS c FROM ${ctx.q(definition.tableName)}`) : 0;
|
|
5219
|
-
if (rows > 0) ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5301
|
+
if (rows > 0) ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.REQUIRED_HAS_NULLS */.Uu.REQUIRED_HAS_NULLS, {
|
|
5220
5302
|
field: field.code,
|
|
5221
5303
|
count: rows
|
|
5222
5304
|
}));
|
|
@@ -5225,10 +5307,10 @@ class SchemaEvolutionService {
|
|
|
5225
5307
|
break;
|
|
5226
5308
|
}
|
|
5227
5309
|
case 'missing_index':
|
|
5228
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5310
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.RECREATE_INDEX */.EQ.RECREATE_INDEX, {
|
|
5229
5311
|
column: finding.field
|
|
5230
5312
|
}), async ()=>{
|
|
5231
|
-
await
|
|
5313
|
+
await this.rebuildPlainIndex(ctx, table, definition.tableName, finding.field, this.liveOnly(definition, ctx.driver));
|
|
5232
5314
|
});
|
|
5233
5315
|
fixed.push(`missing_index:${finding.field}`);
|
|
5234
5316
|
break;
|
|
@@ -5236,12 +5318,12 @@ class SchemaEvolutionService {
|
|
|
5236
5318
|
{
|
|
5237
5319
|
const code = finding.field;
|
|
5238
5320
|
const dups = await this.countDuplicates(ctx, definition.tableName, code);
|
|
5239
|
-
if (dups > 0) ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5321
|
+
if (dups > 0) ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.UNIQUE_NOT_RECREATED */.Uu.UNIQUE_NOT_RECREATED, {
|
|
5240
5322
|
field: code,
|
|
5241
5323
|
count: dups
|
|
5242
5324
|
}));
|
|
5243
5325
|
else {
|
|
5244
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5326
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_STEP_MESSAGES.RECREATE_UNIQUE */.EQ.RECREATE_UNIQUE, {
|
|
5245
5327
|
column: code
|
|
5246
5328
|
}), async ()=>{
|
|
5247
5329
|
await (0,_schema_columns_js__rspack_import_17/* .addUnique */.$6)(ctx.qr, table, code, ctx.driver, this.adapter);
|
|
@@ -5256,7 +5338,7 @@ class SchemaEvolutionService {
|
|
|
5256
5338
|
if (!field || !column) break;
|
|
5257
5339
|
if (!field.nullable && column.isNullable) {
|
|
5258
5340
|
const nulls = await this.scalar(ctx, `SELECT COUNT(*) AS c FROM ${ctx.q(definition.tableName)} WHERE ${ctx.q(field.code)} IS NULL`);
|
|
5259
|
-
if (nulls > 0) ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5341
|
+
if (nulls > 0) ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.REQUIRED_HAS_NULLS */.Uu.REQUIRED_HAS_NULLS, {
|
|
5260
5342
|
field: field.code,
|
|
5261
5343
|
count: nulls
|
|
5262
5344
|
}));
|
|
@@ -5275,12 +5357,12 @@ class SchemaEvolutionService {
|
|
|
5275
5357
|
}
|
|
5276
5358
|
}
|
|
5277
5359
|
const manual = findings.filter((f)=>!f.repairable);
|
|
5278
|
-
for (const f of manual)ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5360
|
+
for (const f of manual)ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.NEEDS_MANUAL_ATTENTION */.Uu.NEEDS_MANUAL_ATTENTION, {
|
|
5279
5361
|
finding: (0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(f.messageKey, f.messageVariables)
|
|
5280
5362
|
}));
|
|
5281
|
-
if (fixed.length === 0 && manual.length === 0) ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5363
|
+
if (fixed.length === 0 && manual.length === 0) ctx.warn((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_20/* .SCHEMA_WARNING_MESSAGES.NOTHING_TO_REPAIR */.Uu.NOTHING_TO_REPAIR));
|
|
5282
5364
|
return {
|
|
5283
|
-
operation:
|
|
5365
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_22/* .DdlOperation.REPAIR */.i.REPAIR,
|
|
5284
5366
|
diff: {
|
|
5285
5367
|
fixed,
|
|
5286
5368
|
manual: manual.length
|
|
@@ -5300,17 +5382,20 @@ SchemaEvolutionService = _ts_decorate([
|
|
|
5300
5382
|
scope: _nestjs_common__rspack_import_2.Scope.REQUEST
|
|
5301
5383
|
}),
|
|
5302
5384
|
_ts_param(0, (0,_nestjs_common__rspack_import_2.Inject)(_entity_builder_datasource_provider_js__rspack_import_10/* .EntityBuilderDataSourceProvider */.D)),
|
|
5303
|
-
_ts_param(1, (0,_nestjs_common__rspack_import_2.Inject)(
|
|
5385
|
+
_ts_param(1, (0,_nestjs_common__rspack_import_2.Inject)(_schema_dialect_adapter_service_js__rspack_import_19/* .SchemaDialectAdapterService */.I)),
|
|
5304
5386
|
_ts_param(2, (0,_nestjs_common__rspack_import_2.Inject)(_schema_change_executor_service_js__rspack_import_16/* .SchemaChangeExecutor */.T)),
|
|
5305
5387
|
_ts_param(3, (0,_nestjs_common__rspack_import_2.Inject)(_reference_scanner_service_js__rspack_import_15/* .ReferenceScannerService */.t)),
|
|
5306
5388
|
_ts_param(4, (0,_nestjs_common__rspack_import_2.Inject)(_entity_permission_service_js__rspack_import_11/* .EntityPermissionService */.u)),
|
|
5389
|
+
_ts_param(5, (0,_nestjs_common__rspack_import_2.Optional)()),
|
|
5390
|
+
_ts_param(5, (0,_nestjs_common__rspack_import_2.Inject)(_entity_builder_config_service_js__rspack_import_18/* .EntityBuilderConfigService */.E)),
|
|
5307
5391
|
_ts_metadata("design:type", Function),
|
|
5308
5392
|
_ts_metadata("design:paramtypes", [
|
|
5309
5393
|
typeof _entity_builder_datasource_provider_js__rspack_import_10/* .EntityBuilderDataSourceProvider */.D === "undefined" ? Object : _entity_builder_datasource_provider_js__rspack_import_10/* .EntityBuilderDataSourceProvider */.D,
|
|
5310
|
-
typeof
|
|
5394
|
+
typeof _schema_dialect_adapter_service_js__rspack_import_19/* .SchemaDialectAdapterService */.I === "undefined" ? Object : _schema_dialect_adapter_service_js__rspack_import_19/* .SchemaDialectAdapterService */.I,
|
|
5311
5395
|
typeof _schema_change_executor_service_js__rspack_import_16/* .SchemaChangeExecutor */.T === "undefined" ? Object : _schema_change_executor_service_js__rspack_import_16/* .SchemaChangeExecutor */.T,
|
|
5312
5396
|
typeof _reference_scanner_service_js__rspack_import_15/* .ReferenceScannerService */.t === "undefined" ? Object : _reference_scanner_service_js__rspack_import_15/* .ReferenceScannerService */.t,
|
|
5313
|
-
typeof _entity_permission_service_js__rspack_import_11/* .EntityPermissionService */.u === "undefined" ? Object : _entity_permission_service_js__rspack_import_11/* .EntityPermissionService */.u
|
|
5397
|
+
typeof _entity_permission_service_js__rspack_import_11/* .EntityPermissionService */.u === "undefined" ? Object : _entity_permission_service_js__rspack_import_11/* .EntityPermissionService */.u,
|
|
5398
|
+
typeof _entity_builder_config_service_js__rspack_import_18/* .EntityBuilderConfigService */.E === "undefined" ? Object : _entity_builder_config_service_js__rspack_import_18/* .EntityBuilderConfigService */.E
|
|
5314
5399
|
])
|
|
5315
5400
|
], SchemaEvolutionService);
|
|
5316
5401
|
|
|
@@ -5327,13 +5412,13 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
5327
5412
|
/* import */ var _flusys_nestjs_shared_utils__rspack_import_1 = __webpack_require__(9216);
|
|
5328
5413
|
/* import */ var _nestjs_common__rspack_import_2 = __webpack_require__(6157);
|
|
5329
5414
|
/* import */ var typeorm__rspack_import_3 = __webpack_require__(7158);
|
|
5330
|
-
/* import */ var
|
|
5415
|
+
/* import */ var _config_message_keys_js__rspack_import_18 = __webpack_require__(5732);
|
|
5331
5416
|
/* import */ var _entities_entity_definition_entity_js__rspack_import_4 = __webpack_require__(3189);
|
|
5332
5417
|
/* import */ var _entities_field_definition_entity_js__rspack_import_5 = __webpack_require__(2206);
|
|
5333
5418
|
/* import */ var _entities_flow_definition_entity_js__rspack_import_6 = __webpack_require__(3770);
|
|
5334
|
-
/* import */ var
|
|
5335
|
-
/* import */ var
|
|
5336
|
-
/* import */ var
|
|
5419
|
+
/* import */ var _enums_ddl_operation_enum_js__rspack_import_21 = __webpack_require__(9949);
|
|
5420
|
+
/* import */ var _enums_entity_status_enum_js__rspack_import_22 = __webpack_require__(1313);
|
|
5421
|
+
/* import */ var _enums_field_type_enum_js__rspack_import_20 = __webpack_require__(9614);
|
|
5337
5422
|
/* import */ var _flow_engine_flow_errors_js__rspack_import_7 = __webpack_require__(8542);
|
|
5338
5423
|
/* import */ var _entity_builder_datasource_provider_js__rspack_import_8 = __webpack_require__(424);
|
|
5339
5424
|
/* import */ var _entity_flow_scaffold_js__rspack_import_9 = __webpack_require__(8271);
|
|
@@ -5343,7 +5428,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
5343
5428
|
/* import */ var _identifier_rules_js__rspack_import_13 = __webpack_require__(413);
|
|
5344
5429
|
/* import */ var _schema_change_executor_service_js__rspack_import_14 = __webpack_require__(6605);
|
|
5345
5430
|
/* import */ var _schema_columns_js__rspack_import_15 = __webpack_require__(5313);
|
|
5346
|
-
/* import */ var
|
|
5431
|
+
/* import */ var _entity_builder_config_service_js__rspack_import_16 = __webpack_require__(4281);
|
|
5432
|
+
/* import */ var _schema_dialect_adapter_service_js__rspack_import_17 = __webpack_require__(7259);
|
|
5347
5433
|
function _ts_decorate(decorators, target, key, desc) {
|
|
5348
5434
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5349
5435
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
@@ -5387,6 +5473,7 @@ function _ts_param(paramIndex, decorator) {
|
|
|
5387
5473
|
|
|
5388
5474
|
|
|
5389
5475
|
|
|
5476
|
+
|
|
5390
5477
|
|
|
5391
5478
|
|
|
5392
5479
|
const presetId = (id)=>id ? {
|
|
@@ -5398,26 +5485,28 @@ class SchemaSyncService {
|
|
|
5398
5485
|
executor;
|
|
5399
5486
|
entityPermissionService;
|
|
5400
5487
|
flowDefinitionService;
|
|
5488
|
+
config;
|
|
5401
5489
|
logger = new _nestjs_common__rspack_import_2.Logger(SchemaSyncService.name);
|
|
5402
|
-
constructor(dataSourceProvider, dialectAdapter, executor, entityPermissionService, flowDefinitionService){
|
|
5490
|
+
constructor(dataSourceProvider, dialectAdapter, executor, entityPermissionService, flowDefinitionService, config){
|
|
5403
5491
|
this.dataSourceProvider = dataSourceProvider;
|
|
5404
5492
|
this.dialectAdapter = dialectAdapter;
|
|
5405
5493
|
this.executor = executor;
|
|
5406
5494
|
this.entityPermissionService = entityPermissionService;
|
|
5407
5495
|
this.flowDefinitionService = flowDefinitionService;
|
|
5496
|
+
this.config = config;
|
|
5408
5497
|
}
|
|
5409
5498
|
validateCreateRequest(dto) {
|
|
5410
|
-
(0,_identifier_rules_js__rspack_import_13/* .assertValidIdentifier */.
|
|
5499
|
+
(0,_identifier_rules_js__rspack_import_13/* .assertValidIdentifier */.k)(dto.code, 'entity');
|
|
5411
5500
|
const fields = dto.fields ?? [];
|
|
5412
5501
|
for (const field of fields){
|
|
5413
|
-
(0,_identifier_rules_js__rspack_import_13/* .assertValidIdentifier */.
|
|
5414
|
-
(0,_identifier_rules_js__rspack_import_13/* .assertIndexableField */.
|
|
5502
|
+
(0,_identifier_rules_js__rspack_import_13/* .assertValidIdentifier */.k)(field.code, 'field');
|
|
5503
|
+
(0,_identifier_rules_js__rspack_import_13/* .assertIndexableField */.f)(field);
|
|
5415
5504
|
}
|
|
5416
5505
|
const duplicate = fields.map((f)=>f.code).find((code, index, all)=>all.indexOf(code) !== index);
|
|
5417
5506
|
if (duplicate) {
|
|
5418
5507
|
throw new _nestjs_common__rspack_import_2.BadRequestException({
|
|
5419
5508
|
message: `Field code '${duplicate}' is defined more than once.`,
|
|
5420
|
-
messageKey:
|
|
5509
|
+
messageKey: _config_message_keys_js__rspack_import_18/* .SCHEMA_MESSAGES.DUPLICATE_FIELD_CODE */.Hu.DUPLICATE_FIELD_CODE,
|
|
5421
5510
|
messageVariables: {
|
|
5422
5511
|
code: duplicate
|
|
5423
5512
|
}
|
|
@@ -5446,7 +5535,7 @@ class SchemaSyncService {
|
|
|
5446
5535
|
const taken = await ctx.qr.query((0,_flusys_nestjs_shared_classes__rspack_import_0.buildQuery)(`SELECT table_name FROM information_schema.tables WHERE table_schema = ${schemaExpr} AND table_name = ?`, ctx.driver), [
|
|
5447
5536
|
tableName
|
|
5448
5537
|
]);
|
|
5449
|
-
if (taken.length) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5538
|
+
if (taken.length) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_18/* .SCHEMA_BLOCKER_MESSAGES.TABLE_EXISTS */.M3.TABLE_EXISTS, {
|
|
5450
5539
|
table: tableName
|
|
5451
5540
|
}));
|
|
5452
5541
|
const definitions = ctx.qr.manager.getRepository(_entities_entity_definition_entity_js__rspack_import_4/* .EntityDefinition */.f);
|
|
@@ -5455,12 +5544,12 @@ class SchemaSyncService {
|
|
|
5455
5544
|
code: dto.code
|
|
5456
5545
|
}
|
|
5457
5546
|
});
|
|
5458
|
-
if (known) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5547
|
+
if (known) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_18/* .SCHEMA_BLOCKER_MESSAGES.ENTITY_CODE_EXISTS */.M3.ENTITY_CODE_EXISTS, {
|
|
5459
5548
|
code: dto.code
|
|
5460
5549
|
}));
|
|
5461
|
-
for (const spec of fieldSpecs.filter((f)=>f.fieldType ===
|
|
5550
|
+
for (const spec of fieldSpecs.filter((f)=>f.fieldType === _enums_field_type_enum_js__rspack_import_20/* .FieldType.RELATION */.P.RELATION)){
|
|
5462
5551
|
if (!spec.relationTargetEntityId) {
|
|
5463
|
-
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5552
|
+
ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_18/* .SCHEMA_BLOCKER_MESSAGES.RELATION_TARGET_REQUIRED */.M3.RELATION_TARGET_REQUIRED, {
|
|
5464
5553
|
field: spec.code
|
|
5465
5554
|
}));
|
|
5466
5555
|
continue;
|
|
@@ -5470,24 +5559,16 @@ class SchemaSyncService {
|
|
|
5470
5559
|
id: spec.relationTargetEntityId
|
|
5471
5560
|
}
|
|
5472
5561
|
});
|
|
5473
|
-
if (!target) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5562
|
+
if (!target) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_18/* .SCHEMA_BLOCKER_MESSAGES.RELATION_FIELD_TARGET_MISSING */.M3.RELATION_FIELD_TARGET_MISSING, {
|
|
5474
5563
|
field: spec.code
|
|
5475
5564
|
}));
|
|
5476
5565
|
}
|
|
5477
5566
|
const withDefault = fieldSpecs.filter((f)=>f.defaultValue !== undefined && f.defaultValue !== null);
|
|
5478
|
-
const { errors: defaultErrors } = (0,_field_value_validator_js__rspack_import_11/* .validateRecord */.e)(withDefault.map((f)=>
|
|
5479
|
-
code: f.code,
|
|
5480
|
-
label: f.label,
|
|
5481
|
-
fieldType: f.fieldType,
|
|
5482
|
-
nullable: true,
|
|
5483
|
-
defaultValue: null,
|
|
5484
|
-
selectOptions: f.selectOptions ?? null,
|
|
5485
|
-
validationRules: f.validationRules ?? null
|
|
5486
|
-
})), Object.fromEntries(withDefault.map((f)=>[
|
|
5567
|
+
const { errors: defaultErrors } = (0,_field_value_validator_js__rspack_import_11/* .validateRecord */.e)(withDefault.map(_field_value_validator_js__rspack_import_11/* .valueRulesOf */.C), Object.fromEntries(withDefault.map((f)=>[
|
|
5487
5568
|
f.code,
|
|
5488
5569
|
f.defaultValue
|
|
5489
5570
|
])), 'insert');
|
|
5490
|
-
for (const error of defaultErrors)ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5571
|
+
for (const error of defaultErrors)ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_18/* .SCHEMA_BLOCKER_MESSAGES.DEFAULT_INVALID */.M3.DEFAULT_INVALID, {
|
|
5491
5572
|
problem: (0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(error.messageKey, error.messageVariables)
|
|
5492
5573
|
}));
|
|
5493
5574
|
if (flowEndpoints.length) {
|
|
@@ -5498,15 +5579,14 @@ class SchemaSyncService {
|
|
|
5498
5579
|
},
|
|
5499
5580
|
where: {
|
|
5500
5581
|
slug
|
|
5501
|
-
}
|
|
5502
|
-
withDeleted: true
|
|
5582
|
+
}
|
|
5503
5583
|
});
|
|
5504
|
-
if (clash) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5584
|
+
if (clash) ctx.block((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_18/* .SCHEMA_BLOCKER_MESSAGES.FLOW_SLUG_TAKEN */.M3.FLOW_SLUG_TAKEN, {
|
|
5505
5585
|
slug
|
|
5506
5586
|
}));
|
|
5507
5587
|
}
|
|
5508
5588
|
if (ctx.blocked) return {
|
|
5509
|
-
operation:
|
|
5589
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_21/* .DdlOperation.CREATE_TABLE */.i.CREATE_TABLE,
|
|
5510
5590
|
diff: {}
|
|
5511
5591
|
};
|
|
5512
5592
|
const columns = fieldSpecs.map((spec)=>(0,_schema_columns_js__rspack_import_15/* .buildFieldColumn */.fu)({
|
|
@@ -5529,16 +5609,16 @@ class SchemaSyncService {
|
|
|
5529
5609
|
...columns
|
|
5530
5610
|
]
|
|
5531
5611
|
});
|
|
5532
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5612
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_18/* .SCHEMA_STEP_MESSAGES.CREATE_TABLE */.EQ.CREATE_TABLE, {
|
|
5533
5613
|
table: tableName
|
|
5534
5614
|
}), async ()=>{
|
|
5535
5615
|
await ctx.qr.createTable(table, false);
|
|
5536
5616
|
});
|
|
5537
|
-
for (const spec of fieldSpecs.filter((f)=>
|
|
5538
|
-
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5617
|
+
for (const spec of fieldSpecs.filter((f)=>(0,_schema_columns_js__rspack_import_15/* .indexedByDefault */.w5)(f) && !f.unique)){
|
|
5618
|
+
await ctx.ddl((0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_18/* .SCHEMA_STEP_MESSAGES.ADD_INDEX */.EQ.ADD_INDEX, {
|
|
5539
5619
|
column: spec.code
|
|
5540
5620
|
}), async ()=>{
|
|
5541
|
-
await ctx.qr.createIndex(table, (0,_schema_columns_js__rspack_import_15/* .plainIndex */.v7)(tableName, spec.code, ctx.driver, this.dialectAdapter));
|
|
5621
|
+
await ctx.qr.createIndex(table, (0,_schema_columns_js__rspack_import_15/* .plainIndex */.v7)(tableName, spec.code, ctx.driver, this.dialectAdapter, isSoftDeleteEnabled && !!this.config?.isPartialIndexesEnabled()));
|
|
5542
5622
|
});
|
|
5543
5623
|
}
|
|
5544
5624
|
await ctx.metadata(async ()=>{
|
|
@@ -5549,7 +5629,7 @@ class SchemaSyncService {
|
|
|
5549
5629
|
label: dto.label,
|
|
5550
5630
|
description: dto.description ?? null,
|
|
5551
5631
|
tableName,
|
|
5552
|
-
status:
|
|
5632
|
+
status: _enums_entity_status_enum_js__rspack_import_22/* .EntityStatus.ACTIVE */.c.ACTIVE,
|
|
5553
5633
|
schemaVersion: 1,
|
|
5554
5634
|
isSoftDeleteEnabled,
|
|
5555
5635
|
isAuditEnabled,
|
|
@@ -5566,11 +5646,11 @@ class SchemaSyncService {
|
|
|
5566
5646
|
dbType: this.dialectAdapter.mapFieldType(spec.fieldType, ctx.driver),
|
|
5567
5647
|
nullable: spec.nullable ?? true,
|
|
5568
5648
|
unique: spec.unique ?? false,
|
|
5569
|
-
isIndexed:
|
|
5649
|
+
isIndexed: (0,_schema_columns_js__rspack_import_15/* .indexedByDefault */.w5)(spec),
|
|
5570
5650
|
defaultValue: spec.defaultValue ?? null,
|
|
5571
5651
|
validationRules: spec.validationRules ?? null,
|
|
5572
5652
|
selectOptions: spec.selectOptions ?? null,
|
|
5573
|
-
relationTargetEntityId: spec.fieldType ===
|
|
5653
|
+
relationTargetEntityId: spec.fieldType === _enums_field_type_enum_js__rspack_import_20/* .FieldType.RELATION */.P.RELATION ? spec.relationTargetEntityId : null,
|
|
5574
5654
|
order: spec.order ?? index,
|
|
5575
5655
|
uiConfig: spec.uiConfig ?? null,
|
|
5576
5656
|
isSearchable: spec.isSearchable ?? false,
|
|
@@ -5581,7 +5661,7 @@ class SchemaSyncService {
|
|
|
5581
5661
|
created.definition = definition;
|
|
5582
5662
|
});
|
|
5583
5663
|
return {
|
|
5584
|
-
operation:
|
|
5664
|
+
operation: _enums_ddl_operation_enum_js__rspack_import_21/* .DdlOperation.CREATE_TABLE */.i.CREATE_TABLE,
|
|
5585
5665
|
entityDefinitionId: created.definition?.id ?? null,
|
|
5586
5666
|
diff: {
|
|
5587
5667
|
fields: fieldSpecs.map((f)=>({
|
|
@@ -5617,7 +5697,7 @@ class SchemaSyncService {
|
|
|
5617
5697
|
} catch (error) {
|
|
5618
5698
|
this.logger.error(`The flow '${flow.slug}' of entity '${dto.code}' could not be created: ${error.message}`);
|
|
5619
5699
|
return [
|
|
5620
|
-
(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(
|
|
5700
|
+
(0,_flusys_nestjs_shared_utils__rspack_import_1.messageRef)(_config_message_keys_js__rspack_import_18/* .SCHEMA_WARNING_MESSAGES.ENDPOINT_FLOW_FAILED */.Uu.ENDPOINT_FLOW_FAILED, {
|
|
5621
5701
|
slug: flow.slug,
|
|
5622
5702
|
detail: (0,_flow_engine_flow_errors_js__rspack_import_7/* .errorRef */.O$)(error)
|
|
5623
5703
|
})
|
|
@@ -5640,10 +5720,10 @@ class SchemaSyncService {
|
|
|
5640
5720
|
try {
|
|
5641
5721
|
({ plan: { warnings: planWarnings } } = await this.executor.apply(await this.createTarget(dto, user), this.createRun(dto, user, created, ids)));
|
|
5642
5722
|
} catch (error) {
|
|
5643
|
-
if (error instanceof _nestjs_common__rspack_import_2.ConflictException && error.getResponse().blockers?.some((b)=>b.messageKey ===
|
|
5723
|
+
if (error instanceof _nestjs_common__rspack_import_2.ConflictException && error.getResponse().blockers?.some((b)=>b.messageKey === _config_message_keys_js__rspack_import_18/* .SCHEMA_BLOCKER_MESSAGES.ENTITY_CODE_EXISTS */.M3.ENTITY_CODE_EXISTS || b.messageKey === _config_message_keys_js__rspack_import_18/* .SCHEMA_BLOCKER_MESSAGES.TABLE_EXISTS */.M3.TABLE_EXISTS)) {
|
|
5644
5724
|
throw new _nestjs_common__rspack_import_2.ConflictException({
|
|
5645
5725
|
message: `An entity with the code '${dto.code}' already exists.`,
|
|
5646
|
-
messageKey:
|
|
5726
|
+
messageKey: _config_message_keys_js__rspack_import_18/* .ENTITY_DEFINITION_MESSAGES.CODE_ALREADY_EXISTS */.pL.CODE_ALREADY_EXISTS,
|
|
5647
5727
|
messageVariables: {
|
|
5648
5728
|
code: dto.code
|
|
5649
5729
|
}
|
|
@@ -5665,17 +5745,20 @@ SchemaSyncService = _ts_decorate([
|
|
|
5665
5745
|
scope: _nestjs_common__rspack_import_2.Scope.REQUEST
|
|
5666
5746
|
}),
|
|
5667
5747
|
_ts_param(0, (0,_nestjs_common__rspack_import_2.Inject)(_entity_builder_datasource_provider_js__rspack_import_8/* .EntityBuilderDataSourceProvider */.D)),
|
|
5668
|
-
_ts_param(1, (0,_nestjs_common__rspack_import_2.Inject)(
|
|
5748
|
+
_ts_param(1, (0,_nestjs_common__rspack_import_2.Inject)(_schema_dialect_adapter_service_js__rspack_import_17/* .SchemaDialectAdapterService */.I)),
|
|
5669
5749
|
_ts_param(2, (0,_nestjs_common__rspack_import_2.Inject)(_schema_change_executor_service_js__rspack_import_14/* .SchemaChangeExecutor */.T)),
|
|
5670
5750
|
_ts_param(3, (0,_nestjs_common__rspack_import_2.Inject)(_entity_permission_service_js__rspack_import_10/* .EntityPermissionService */.u)),
|
|
5671
5751
|
_ts_param(4, (0,_nestjs_common__rspack_import_2.Inject)(_flow_definition_service_js__rspack_import_12/* .FlowDefinitionService */.Tk)),
|
|
5752
|
+
_ts_param(5, (0,_nestjs_common__rspack_import_2.Optional)()),
|
|
5753
|
+
_ts_param(5, (0,_nestjs_common__rspack_import_2.Inject)(_entity_builder_config_service_js__rspack_import_16/* .EntityBuilderConfigService */.E)),
|
|
5672
5754
|
_ts_metadata("design:type", Function),
|
|
5673
5755
|
_ts_metadata("design:paramtypes", [
|
|
5674
5756
|
typeof _entity_builder_datasource_provider_js__rspack_import_8/* .EntityBuilderDataSourceProvider */.D === "undefined" ? Object : _entity_builder_datasource_provider_js__rspack_import_8/* .EntityBuilderDataSourceProvider */.D,
|
|
5675
|
-
typeof
|
|
5757
|
+
typeof _schema_dialect_adapter_service_js__rspack_import_17/* .SchemaDialectAdapterService */.I === "undefined" ? Object : _schema_dialect_adapter_service_js__rspack_import_17/* .SchemaDialectAdapterService */.I,
|
|
5676
5758
|
typeof _schema_change_executor_service_js__rspack_import_14/* .SchemaChangeExecutor */.T === "undefined" ? Object : _schema_change_executor_service_js__rspack_import_14/* .SchemaChangeExecutor */.T,
|
|
5677
5759
|
typeof _entity_permission_service_js__rspack_import_10/* .EntityPermissionService */.u === "undefined" ? Object : _entity_permission_service_js__rspack_import_10/* .EntityPermissionService */.u,
|
|
5678
|
-
typeof _flow_definition_service_js__rspack_import_12/* .FlowDefinitionService */.Tk === "undefined" ? Object : _flow_definition_service_js__rspack_import_12/* .FlowDefinitionService */.Tk
|
|
5760
|
+
typeof _flow_definition_service_js__rspack_import_12/* .FlowDefinitionService */.Tk === "undefined" ? Object : _flow_definition_service_js__rspack_import_12/* .FlowDefinitionService */.Tk,
|
|
5761
|
+
typeof _entity_builder_config_service_js__rspack_import_16/* .EntityBuilderConfigService */.E === "undefined" ? Object : _entity_builder_config_service_js__rspack_import_16/* .EntityBuilderConfigService */.E
|
|
5679
5762
|
])
|
|
5680
5763
|
], SchemaSyncService);
|
|
5681
5764
|
|