|
| 1 | +const _ = require('lodash'); |
1 | 2 | const defaultTypes = require('./configs/defaultTypes'); |
2 | 3 | const types = require('./configs/types'); |
3 | 4 | const templates = require('./configs/templates'); |
4 | 5 | const { commentIfDeactivated } = require('./helpers/commentIfDeactivated'); |
5 | 6 | const { joinActivatedAndDeactivatedStatements } = require('./utils/joinActivatedAndDeactivatedStatements'); |
6 | | - |
7 | | -module.exports = (baseProvider, options, app) => { |
8 | | - const _ = app.require('lodash'); |
9 | | - const { assignTemplates } = app.require('@hackolade/ddl-fe-utils'); |
10 | | - const { checkAllKeysDeactivated, divideIntoActivatedAndDeactivated, getEntityName } = |
11 | | - app.require('@hackolade/ddl-fe-utils').general; |
12 | | - const { wrapInBrackets } = require('./utils/general')(_); |
13 | | - |
14 | | - const { decorateType, getIdentity, getEncryptedWith, getColumnsComments, canHaveIdentity } = |
15 | | - require('./helpers/columnDefinitionHelper')(app); |
16 | | - const { |
17 | | - createIndex, |
18 | | - hydrateIndex, |
19 | | - getMemoryOptimizedIndexes, |
20 | | - createMemoryOptimizedIndex, |
21 | | - hydrateTableIndex, |
22 | | - createTableIndex, |
23 | | - } = require('./helpers/indexHelper')(app); |
24 | | - const { |
25 | | - getTableName, |
26 | | - getTableOptions, |
27 | | - hasType, |
28 | | - foreignKeysToString, |
29 | | - checkIndexActivated, |
30 | | - getDefaultValue, |
31 | | - getTempTableTime, |
32 | | - foreignActiveKeysToString, |
33 | | - additionalPropertiesForForeignKey, |
34 | | - getFKConstraintName, |
35 | | - } = require('./helpers/general')(app); |
36 | | - const keyHelper = require('./helpers/keyHelper')(app); |
37 | | - const { getTerminator } = require('./helpers/optionsHelper'); |
38 | | - const { createPKConstraint, createUKConstraint, createDefaultConstraint, generateConstraintsString } = |
39 | | - require('./helpers/constraintsHelper')(app); |
40 | | - const { wrapIfNotExistSchema, wrapIfNotExistDatabase, wrapIfNotExistTable, wrapIfNotExistView } = |
41 | | - require('./helpers/ifNotExistStatementHelper')(app); |
42 | | - const { getPartitionedTables, getCreateViewData } = require('./helpers/viewHelper')(app); |
43 | | - const { getFullTableName, escapeSpecialCharacters, wrapInBracketsIfNecessary } = require('./utils/general')(_); |
44 | | - |
| 7 | +const { assignTemplates } = require('./utils/assignTemplates'); |
| 8 | +const { |
| 9 | + wrapInBrackets, |
| 10 | + escapeSpecialCharacters, |
| 11 | + wrapInBracketsIfNecessary, |
| 12 | + checkAllKeysDeactivated, |
| 13 | + divideIntoActivatedAndDeactivated, |
| 14 | + getEntityName, |
| 15 | +} = require('./utils/general'); |
| 16 | +const { |
| 17 | + decorateType, |
| 18 | + getIdentity, |
| 19 | + getEncryptedWith, |
| 20 | + getColumnsComments, |
| 21 | + canHaveIdentity, |
| 22 | +} = require('./helpers/columnDefinitionHelper'); |
| 23 | +const { |
| 24 | + createIndex, |
| 25 | + hydrateIndex, |
| 26 | + getMemoryOptimizedIndexes, |
| 27 | + createMemoryOptimizedIndex, |
| 28 | + hydrateTableIndex, |
| 29 | + createTableIndex, |
| 30 | +} = require('./helpers/indexHelper'); |
| 31 | +const { |
| 32 | + getTableName, |
| 33 | + getTableOptions, |
| 34 | + hasType, |
| 35 | + foreignKeysToString, |
| 36 | + checkIndexActivated, |
| 37 | + getDefaultValue, |
| 38 | + getTempTableTime, |
| 39 | + foreignActiveKeysToString, |
| 40 | + additionalPropertiesForForeignKey, |
| 41 | + getFKConstraintName, |
| 42 | +} = require('./helpers/general'); |
| 43 | +const keyHelper = require('./helpers/keyHelper'); |
| 44 | +const { getTerminator } = require('./helpers/optionsHelper'); |
| 45 | +const { |
| 46 | + createPKConstraint, |
| 47 | + createUKConstraint, |
| 48 | + createDefaultConstraint, |
| 49 | + generateConstraintsString, |
| 50 | +} = require('./helpers/constraintsHelper'); |
| 51 | +const { |
| 52 | + wrapIfNotExistSchema, |
| 53 | + wrapIfNotExistDatabase, |
| 54 | + wrapIfNotExistTable, |
| 55 | + wrapIfNotExistView, |
| 56 | +} = require('./helpers/ifNotExistStatementHelper'); |
| 57 | +const { getPartitionedTables, getCreateViewData } = require('./helpers/viewHelper'); |
| 58 | + |
| 59 | +const ddlProvider = (baseProvider, options, app) => { |
45 | 60 | const terminator = getTerminator(options); |
46 | 61 |
|
47 | 62 | return { |
@@ -206,9 +221,9 @@ module.exports = (baseProvider, options, app) => { |
206 | 221 | ? ` MASKED WITH (FUNCTION='${columnDefinition.maskedWithFunction}')` |
207 | 222 | : ''; |
208 | 223 | const identityContainer = columnDefinition.identity && { identity: getIdentity(columnDefinition.identity) }; |
209 | | - const encryptedWith = !_.isEmpty(columnDefinition.encryption) |
210 | | - ? getEncryptedWith(columnDefinition.encryption[0]) |
211 | | - : ''; |
| 224 | + const encryptedWith = _.isEmpty(columnDefinition.encryption) |
| 225 | + ? '' |
| 226 | + : getEncryptedWith(columnDefinition.encryption[0]); |
212 | 227 | const unique = columnDefinition.unique |
213 | 228 | ? ' ' + createUKConstraint(templates, terminator, true)(columnDefinition.uniqueKeyOptions).statement |
214 | 229 | : ''; |
@@ -250,7 +265,7 @@ module.exports = (baseProvider, options, app) => { |
250 | 265 | createIndex(tableName, index, dbData, isParentActivated = true) { |
251 | 266 | const isActivated = checkIndexActivated(index); |
252 | 267 | if (!isParentActivated) { |
253 | | - return createTableIndex(terminator, tableName, index, isActivated && isParentActivated); |
| 268 | + return createTableIndex(terminator, tableName, index, isActivated); |
254 | 269 | } |
255 | 270 | return createTableIndex(terminator, tableName, index, isActivated && isParentActivated); |
256 | 271 | }, |
@@ -446,6 +461,15 @@ module.exports = (baseProvider, options, app) => { |
446 | 461 | return hasType(type); |
447 | 462 | }, |
448 | 463 |
|
| 464 | + hydrateJsonSchemaColumn(jsonSchema, definitionJsonSchema) { |
| 465 | + if (!jsonSchema.$ref || _.isEmpty(definitionJsonSchema)) { |
| 466 | + return jsonSchema; |
| 467 | + } |
| 468 | + |
| 469 | + jsonSchema = _.omit(jsonSchema, '$ref'); |
| 470 | + return { ...definitionJsonSchema, ...jsonSchema }; |
| 471 | + }, |
| 472 | + |
449 | 473 | hydrateColumn({ columnDefinition, jsonSchema, schemaData, parentJsonSchema }) { |
450 | 474 | let encryption = []; |
451 | 475 |
|
@@ -476,7 +500,8 @@ module.exports = (baseProvider, options, app) => { |
476 | 500 | const isTempTableEndTimeColumnHidden = |
477 | 501 | _.get(parentJsonSchema, 'periodForSystemTime[0].startTime[0].type', '') === 'hidden'; |
478 | 502 |
|
479 | | - return Object.assign({}, columnDefinition, { |
| 503 | + return { |
| 504 | + ...columnDefinition, |
480 | 505 | defaultConstraint: { |
481 | 506 | name: jsonSchema.defaultConstraintName, |
482 | 507 | value: columnDefinition.default, |
@@ -513,7 +538,7 @@ module.exports = (baseProvider, options, app) => { |
513 | 538 | increment: Number(_.get(jsonSchema, 'identity.identityIncrement', 0)), |
514 | 539 | }, |
515 | 540 | }), |
516 | | - }); |
| 541 | + }; |
517 | 542 | }, |
518 | 543 |
|
519 | 544 | hydrateIndex(indexData, tableData, schemaData) { |
@@ -557,7 +582,8 @@ module.exports = (baseProvider, options, app) => { |
557 | 582 | idToNameHashTable[_.get(jsonSchema, 'periodForSystemTime[0].startTime[0].keyId', '')]; |
558 | 583 | const temporalTableTimeEndColumnName = |
559 | 584 | idToNameHashTable[_.get(jsonSchema, 'periodForSystemTime[0].endTime[0].keyId', '')]; |
560 | | - return Object.assign({}, tableData, { |
| 585 | + return { |
| 586 | + ...tableData, |
561 | 587 | foreignKeyConstraints: tableData.foreignKeyConstraints || [], |
562 | 588 | keyConstraints: keyHelper.getTableKeyConstraints({ jsonSchema }), |
563 | 589 | ifNotExist: jsonSchema.ifNotExist, |
@@ -587,7 +613,7 @@ module.exports = (baseProvider, options, app) => { |
587 | 613 | memoryOptimizedIndexes: isMemoryOptimized |
588 | 614 | ? getMemoryOptimizedIndexes(entityData, tableData.schemaData) |
589 | 615 | : [], |
590 | | - }); |
| 616 | + }; |
591 | 617 | }, |
592 | 618 |
|
593 | 619 | hydrateViewColumn(data) { |
@@ -1071,3 +1097,5 @@ module.exports = (baseProvider, options, app) => { |
1071 | 1097 | }, |
1072 | 1098 | }; |
1073 | 1099 | }; |
| 1100 | + |
| 1101 | +module.exports = ddlProvider; |
0 commit comments