From 4f7142748e0101571441a0a6f02ded7cc380f1d4 Mon Sep 17 00:00:00 2001 From: Taras Dubyk Date: Mon, 29 Jul 2024 13:25:07 +0300 Subject: [PATCH] HCK-7383 add FE script formats: quoted and nonquoted object names (#113) * add FE script formats FE * use quotes regarding to script format * fix table columns names handling * handle script formats for alter script * fix missed options handling --------- Co-authored-by: chulanovskyi-bs <56116665+chulanovskyi-bs@users.noreply.github.com> --- .../alterScript/alterScriptFromDeltaHelper.js | 85 ++++++++++++++----- .../alterContainerHelper.js | 12 +-- .../alterScriptHelpers/alterEntityHelper.js | 57 ++++++++----- .../alterRelationshipsHelper.js | 22 ++--- .../alterScriptHelpers/alterUdtHelper.js | 46 +++++----- .../alterScriptHelpers/alterViewHelper.js | 28 +++--- .../columnHelpers/alterTypeHelper.js | 14 +-- .../columnHelpers/renameColumnHelper.js | 16 ++-- .../entityHelpers/indexesHelper.js | 28 +++--- forward_engineering/config.json | 39 +++++++-- .../ddlHelpers/columnDefinitionHelper.js | 6 +- .../ddlHelpers/constraintHelper.js | 4 +- .../abstractDualityViewDdlCreator.js | 10 ++- .../dualityViewDdlCreatorFactory.js | 15 +++- .../sqlDualityViewDdlCreator.js | 33 ++----- .../ddlProvider/ddlHelpers/indexHelper.js | 6 +- .../ddlProvider/ddlHelpers/synonymHelper.js | 4 +- .../ddlProvider/ddlHelpers/tableHelper.js | 22 +++-- .../ddlProvider/ddlHelpers/viewHelper.js | 8 +- .../ddlProvider/ddlProvider.js | 33 ++++--- forward_engineering/utils/general.js | 13 ++- 21 files changed, 309 insertions(+), 192 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptFromDeltaHelper.js b/forward_engineering/alterScript/alterScriptFromDeltaHelper.js index 987ba96..eceb2af 100644 --- a/forward_engineering/alterScript/alterScriptFromDeltaHelper.js +++ b/forward_engineering/alterScript/alterScriptFromDeltaHelper.js @@ -34,21 +34,22 @@ const _ = require('lodash'); * @param dto {{ * collection: Object, * app: App, + * scriptFormat: string, * }} * @return {AlterScriptDto[]} * */ -const getAlterContainersScriptDtos = ({ collection, app }) => { +const getAlterContainersScriptDtos = ({ collection, app, scriptFormat }) => { const addedContainers = collection.properties?.containers?.properties?.added?.items; const deletedContainers = collection.properties?.containers?.properties?.deleted?.items; const addContainersScriptDtos = [] .concat(addedContainers) .filter(Boolean) - .map(container => getAddContainerScriptDto(app)(Object.keys(container.properties)[0])); + .map(container => getAddContainerScriptDto(app, scriptFormat)(Object.keys(container.properties)[0])); const deleteContainersScriptDtos = [] .concat(deletedContainers) .filter(Boolean) - .map(container => getDeleteContainerScriptDto(app)(Object.keys(container.properties)[0])); + .map(container => getDeleteContainerScriptDto(app, scriptFormat)(Object.keys(container.properties)[0])); return [...addContainersScriptDtos, ...deleteContainersScriptDtos].filter(Boolean); }; @@ -61,6 +62,7 @@ const getAlterContainersScriptDtos = ({ collection, app }) => { * modelDefinitions: ModelDefinitions, * internalDefinitions: InternalDefinitions, * externalDefinitions: ExternalDefinitions, + * scriptFormat: string, * }} * @return {AlterScriptDto[]} * */ @@ -71,6 +73,7 @@ const getAlterCollectionsScriptDtos = ({ modelDefinitions, internalDefinitions, externalDefinitions, + scriptFormat, }) => { const createScriptsData = [] .concat(collection.properties?.entities?.properties?.added?.items) @@ -89,22 +92,38 @@ const getAlterCollectionsScriptDtos = ({ const createCollectionsScriptDtos = createScriptsData .filter(collection => collection.compMod?.created) - .map(getAddCollectionScriptDto({ app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions })); + .map( + getAddCollectionScriptDto({ + app, + dbVersion, + modelDefinitions, + internalDefinitions, + externalDefinitions, + scriptFormat, + }), + ); const deleteCollectionScriptDtos = deleteScriptsData .filter(collection => collection.compMod?.deleted) - .map(getDeleteCollectionScriptDto(app)); + .map(getDeleteCollectionScriptDto(app, scriptFormat)); const modifyCollectionScriptDtos = modifyScriptsData .filter(collection => collection.compMod?.modified) - .flatMap(getModifyCollectionScriptDtos({ app, dbVersion })); + .flatMap(getModifyCollectionScriptDtos({ app, dbVersion, scriptFormat })); const addColumnScriptDtos = createScriptsData .filter(item => !item?.compMod?.created) .flatMap( - getAddColumnScriptDtos({ app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions }), + getAddColumnScriptDtos({ + app, + dbVersion, + modelDefinitions, + internalDefinitions, + externalDefinitions, + scriptFormat, + }), ); const deleteColumnScriptDtos = deleteScriptsData .filter(item => !item?.compMod?.deleted) - .flatMap(getDeleteColumnScriptDtos(app)); - const modifyColumnScriptDtos = modifyScriptsData.flatMap(getModifyColumnScriptDtos(app, dbVersion)); + .flatMap(getDeleteColumnScriptDtos(app, scriptFormat)); + const modifyColumnScriptDtos = modifyScriptsData.flatMap(getModifyColumnScriptDtos(app, dbVersion, scriptFormat)); return [ ...createCollectionsScriptDtos, @@ -120,23 +139,24 @@ const getAlterCollectionsScriptDtos = ({ * @param collection {Object} * @param app {App} * @param dbVersion {string} + * @param scriptFormat {string} * @return {AlterScriptDto[]} * */ -const getAlterViewScriptDtos = (collection, app, dbVersion) => { +const getAlterViewScriptDtos = (collection, app, dbVersion, scriptFormat) => { const createViewsScriptDtos = [] .concat(collection.properties?.views?.properties?.added?.items) .filter(Boolean) .map(item => Object.values(item.properties)[0]) .map(view => ({ ...view, ...(view.role || {}) })) .filter(view => view.compMod?.created) - .map(getAddViewScriptDto(app)); + .map(getAddViewScriptDto(app, scriptFormat)); const deleteViewsScriptDtos = [] .concat(collection.properties?.views?.properties?.deleted?.items) .filter(Boolean) .map(item => Object.values(item.properties)[0]) .map(view => ({ ...view, ...(view.role || {}) })) - .map(getDeleteViewScriptDto(app)); + .map(getDeleteViewScriptDto(app, scriptFormat)); return [...deleteViewsScriptDtos, ...createViewsScriptDtos].filter(Boolean); }; @@ -159,6 +179,7 @@ const getAlterModelDefinitionsScriptDtos = ({ modelDefinitions, internalDefinitions, externalDefinitions, + scriptFormat, }) => { const createUdtScriptDtos = [] .concat(collection.properties?.modelDefinitions?.properties?.added?.items) @@ -166,14 +187,23 @@ const getAlterModelDefinitionsScriptDtos = ({ .map(item => Object.values(item.properties)[0]) .map(item => ({ ...item, ...(_.omit(item.role, 'properties') || {}) })) .filter(item => item.compMod?.created) - .map(getCreateUdtScriptDto({ app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions })); + .map( + getCreateUdtScriptDto({ + app, + dbVersion, + modelDefinitions, + internalDefinitions, + externalDefinitions, + scriptFormat, + }), + ); const deleteUdtScriptDtos = [] .concat(collection.properties?.modelDefinitions?.properties?.deleted?.items) .filter(Boolean) .map(item => Object.values(item.properties)[0]) .map(item => ({ ...item, ...(_.omit(item.role, 'properties') || {}) })) .filter(collection => collection.compMod?.deleted) - .map(getDeleteUdtScriptDto(app)); + .map(getDeleteUdtScriptDto(app, scriptFormat)); const addColumnScriptDtos = [] .concat(collection.properties?.modelDefinitions?.properties?.added?.items) .filter(Boolean) @@ -188,6 +218,7 @@ const getAlterModelDefinitionsScriptDtos = ({ modelDefinitions, internalDefinitions, externalDefinitions, + scriptFormat, }), ); const deleteColumnScriptDtos = [] @@ -197,7 +228,7 @@ const getAlterModelDefinitionsScriptDtos = ({ .filter(item => !item.compMod) .map(item => ({ ...item, ...(_.omit(item.role, 'properties') || {}) })) .filter(item => item.childType === 'object_udt') - .flatMap(getDeleteColumnFromTypeScriptDtos(app)); + .flatMap(getDeleteColumnFromTypeScriptDtos(app, scriptFormat)); const modifyColumnScriptDtos = [] .concat(collection.properties?.modelDefinitions?.properties?.modified?.items) @@ -206,7 +237,7 @@ const getAlterModelDefinitionsScriptDtos = ({ .filter(item => !item.compMod) .map(item => ({ ...item, ...(_.omit(item.role, 'properties') || {}) })) .filter(item => item.childType === 'object_udt') - .flatMap(getModifyColumnOfTypeScriptDtos(app)); + .flatMap(getModifyColumnOfTypeScriptDtos(app, scriptFormat)); return [ ...deleteUdtScriptDtos, @@ -220,8 +251,12 @@ const getAlterModelDefinitionsScriptDtos = ({ /** * @return Array * */ -const getAlterRelationshipsScriptDtos = ({ collection, app }) => { - const ddlProvider = require('../ddlProvider/ddlProvider')(null, null, app); +const getAlterRelationshipsScriptDtos = ({ collection, app, scriptFormat }) => { + const ddlProvider = require('../ddlProvider/ddlProvider')( + null, + { targetScriptOptions: { keyword: scriptFormat } }, + app, + ); const addedRelationships = [] .concat(collection.properties?.relationships?.properties?.added?.items) @@ -241,9 +276,9 @@ const getAlterRelationshipsScriptDtos = ({ collection, app }) => { .map(item => Object.values(item.properties)[0]) .filter(relationship => relationship?.role?.compMod?.modified); - const deleteFkScriptDtos = getDeleteForeignKeyScriptDtos(ddlProvider, _)(deletedRelationships); + const deleteFkScriptDtos = getDeleteForeignKeyScriptDtos(ddlProvider, _, scriptFormat)(deletedRelationships); const addFkScriptDtos = getAddForeignKeyScriptDtos(ddlProvider, _)(addedRelationships); - const modifiedFkScriptDtos = getModifyForeignKeyScriptDtos(ddlProvider, _)(modifiedRelationships); + const modifiedFkScriptDtos = getModifyForeignKeyScriptDtos(ddlProvider, _, scriptFormat)(modifiedRelationships); return [...deleteFkScriptDtos, ...addFkScriptDtos, ...modifiedFkScriptDtos].filter(Boolean); }; @@ -321,11 +356,13 @@ const getAlterScriptDtos = (data, app) => { ); } + const scriptFormat = data.options?.targetScriptOptions?.keyword; + const modelDefinitions = JSON.parse(data.modelDefinitions); const internalDefinitions = JSON.parse(data.internalDefinitions); const externalDefinitions = JSON.parse(data.externalDefinitions); const dbVersion = data.modelData[0]?.dbVersion; - const containersScriptDtos = getAlterContainersScriptDtos({ collection, app }); + const containersScriptDtos = getAlterContainersScriptDtos({ collection, app, scriptFormat }); const collectionsScriptDtos = getAlterCollectionsScriptDtos({ collection, app, @@ -333,8 +370,9 @@ const getAlterScriptDtos = (data, app) => { modelDefinitions, internalDefinitions, externalDefinitions, + scriptFormat, }); - const viewScriptDtos = getAlterViewScriptDtos(collection, app, dbVersion); + const viewScriptDtos = getAlterViewScriptDtos(collection, app, dbVersion, scriptFormat); const modelDefinitionsScriptDtos = getAlterModelDefinitionsScriptDtos({ collection, app, @@ -342,8 +380,9 @@ const getAlterScriptDtos = (data, app) => { modelDefinitions, internalDefinitions, externalDefinitions, + scriptFormat, }); - const relationshipScriptDtos = getAlterRelationshipsScriptDtos({ collection, app }); + const relationshipScriptDtos = getAlterRelationshipsScriptDtos({ collection, app, scriptFormat }); const containersSequencesScriptDtos = getAlterContainersSequencesScriptDtos({ collection, app, dbVersion }); return [ diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterContainerHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterContainerHelper.js index 8d15895..268d09d 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterContainerHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterContainerHelper.js @@ -3,9 +3,9 @@ const _ = require('lodash'); /** * @return {(containerName: string) => AlterScriptDto | undefined} * */ -const getAddContainerScriptDto = app => containerName => { - const { wrapInQuotes } = require('../../utils/general')(_); - const ddlContainerName = wrapInQuotes(containerName); +const getAddContainerScriptDto = (app, scriptFormat) => containerName => { + const { prepareNameForScriptFormat } = require('../../utils/general')(_); + const ddlContainerName = prepareNameForScriptFormat(scriptFormat)(containerName); const createContainerStatement = `CREATE USER ${ddlContainerName} NO AUTHENTICATION;`; return AlterScriptDto.getInstance([createContainerStatement], true, false); @@ -14,9 +14,9 @@ const getAddContainerScriptDto = app => containerName => { /** * @return {(containerName: string) => AlterScriptDto | undefined} * */ -const getDeleteContainerScriptDto = app => containerName => { - const { wrapInQuotes } = require('../../utils/general')(_); - const ddlContainerName = wrapInQuotes(containerName); +const getDeleteContainerScriptDto = (app, scriptFormat) => containerName => { + const { prepareNameForScriptFormat } = require('../../utils/general')(_); + const ddlContainerName = prepareNameForScriptFormat(scriptFormat)(containerName); const dropContainerStatement = `DROP USER ${ddlContainerName};`; return AlterScriptDto.getInstance([dropContainerStatement], true, true); diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js index d6a2f19..27fd547 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js @@ -8,11 +8,15 @@ const _ = require('lodash'); * @return {(collection: AlterCollectionDto) => AlterScriptDto | undefined} * */ const getAddCollectionScriptDto = - ({ app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions }) => + ({ app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions, scriptFormat }) => collection => { const { getEntityName } = require('../../utils/general')(_); const { createColumnDefinitionBySchema } = require('./createColumnDefinition')(app); - const ddlProvider = require('../../ddlProvider/ddlProvider')(null, { dbVersion }, app); + const ddlProvider = require('../../ddlProvider/ddlProvider')( + null, + { dbVersion, targetScriptOptions: { keyword: scriptFormat } }, + app, + ); const { getDefinitionByReference } = app.require('@hackolade/ddl-fe-utils'); const schemaName = collection.compMod.keyspaceName; @@ -61,13 +65,13 @@ const getAddCollectionScriptDto = /** * @return {(collection: AlterCollectionDto) => AlterScriptDto | undefined} * */ -const getDeleteCollectionScriptDto = app => collection => { - const { getEntityName, getNamePrefixedWithSchemaName } = require('../../utils/general')(_); +const getDeleteCollectionScriptDto = (app, scriptFormat) => collection => { + const { getEntityName, getNamePrefixedWithSchemaNameForScriptFormat } = require('../../utils/general')(_); const jsonData = { ...collection, ...(_.omit(collection?.role, 'properties') || {}) }; const tableName = getEntityName(jsonData); const schemaName = collection.compMod.keyspaceName; - const fullName = getNamePrefixedWithSchemaName(tableName, schemaName); + const fullName = getNamePrefixedWithSchemaNameForScriptFormat(scriptFormat)(tableName, schemaName); const script = `DROP TABLE ${fullName};`; return AlterScriptDto.getInstance([script], true, true); @@ -77,11 +81,15 @@ const getDeleteCollectionScriptDto = app => collection => { * @return {(collection: AlterCollectionDto) => AlterScriptDto[]} * */ const getModifyCollectionScriptDtos = - ({ app, dbVersion }) => + ({ app, dbVersion, scriptFormat }) => collection => { - const ddlProvider = require('../../ddlProvider/ddlProvider')(null, { dbVersion }, app); + const ddlProvider = require('../../ddlProvider/ddlProvider')( + null, + { dbVersion, targetScriptOptions: { keyword: scriptFormat } }, + app, + ); - const modifyIndexesScriptDtos = getModifyIndexesScriptDtos({ _, ddlProvider })({ collection }); + const modifyIndexesScriptDtos = getModifyIndexesScriptDtos({ _, ddlProvider, scriptFormat })({ collection }); return [...modifyIndexesScriptDtos].filter(Boolean); }; @@ -89,17 +97,21 @@ const getModifyCollectionScriptDtos = * @return {(collection: Object) => AlterScriptDto[]} * */ const getAddColumnScriptDtos = - ({ app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions }) => + ({ app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions, scriptFormat }) => collection => { - const { getEntityName, getNamePrefixedWithSchemaName } = require('../../utils/general')(_); + const { getEntityName, getNamePrefixedWithSchemaNameForScriptFormat } = require('../../utils/general')(_); const { createColumnDefinitionBySchema } = require('./createColumnDefinition')(app); - const ddlProvider = require('../../ddlProvider/ddlProvider')(null, { dbVersion }, app); + const ddlProvider = require('../../ddlProvider/ddlProvider')( + null, + { dbVersion, targetScriptOptions: { keyword: scriptFormat } }, + app, + ); const { getDefinitionByReference } = app.require('@hackolade/ddl-fe-utils'); const collectionSchema = { ...collection, ...(_.omit(collection?.role, 'properties') || {}) }; const tableName = getEntityName(collectionSchema); const schemaName = collectionSchema.compMod?.keyspaceName; - const fullName = getNamePrefixedWithSchemaName(tableName, schemaName); + const fullName = getNamePrefixedWithSchemaNameForScriptFormat(scriptFormat)(tableName, schemaName); const schemaData = { schemaName, dbVersion }; const scripts = _.toPairs(collection.properties) @@ -157,16 +169,17 @@ const getNewlyCreatedIndexesScripts = ({ _, ddlProvider, collection }) => { /** * @return {(collection: Object) => AlterScriptDto[]} * */ -const getDeleteColumnScriptDtos = app => collection => { - const { getEntityName, getNamePrefixedWithSchemaName, wrapInQuotes } = require('../../utils/general')(_); +const getDeleteColumnScriptDtos = (app, scriptFormat) => collection => { + const { getEntityName, getNamePrefixedWithSchemaNameForScriptFormat, prepareNameForScriptFormat } = + require('../../utils/general')(_); const collectionSchema = { ...collection, ...(_.omit(collection?.role, 'properties') || {}) }; const tableName = getEntityName(collectionSchema); const schemaName = collectionSchema.compMod?.keyspaceName; - const fullName = getNamePrefixedWithSchemaName(tableName, schemaName); + const fullName = getNamePrefixedWithSchemaNameForScriptFormat(scriptFormat)(tableName, schemaName); return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => !jsonSchema.compMod) - .map(([name]) => `ALTER TABLE ${fullName} DROP COLUMN ${wrapInQuotes(name)};`) + .map(([name]) => `ALTER TABLE ${fullName} DROP COLUMN ${prepareNameForScriptFormat(scriptFormat)(name)};`) .map(script => AlterScriptDto.getInstance([script], true, true)) .filter(Boolean); }; @@ -174,11 +187,15 @@ const getDeleteColumnScriptDtos = app => collection => { /** * @return {(collection: Object) => AlterScriptDto[]} * */ -const getModifyColumnScriptDtos = (app, dbVersion) => collection => { - const ddlProvider = require('../../ddlProvider/ddlProvider')(null, { dbVersion }, app); +const getModifyColumnScriptDtos = (app, dbVersion, scriptFormat) => collection => { + const ddlProvider = require('../../ddlProvider/ddlProvider')( + null, + { dbVersion, targetScriptOptions: { keyword: scriptFormat } }, + app, + ); - const renameColumnScriptDtos = getRenameColumnScriptDtos(_, ddlProvider)(collection); - const updateTypeScriptDtos = getUpdateTypesScriptDtos(_, ddlProvider)(collection); + const renameColumnScriptDtos = getRenameColumnScriptDtos(_, ddlProvider, scriptFormat)(collection); + const updateTypeScriptDtos = getUpdateTypesScriptDtos(_, ddlProvider, scriptFormat)(collection); return [...renameColumnScriptDtos, ...updateTypeScriptDtos].filter(Boolean); }; diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterRelationshipsHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterRelationshipsHelper.js index 2efeecb..00ba89a 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterRelationshipsHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterRelationshipsHelper.js @@ -12,13 +12,13 @@ const getRelationshipName = relationship => { /** * @return {(relationship: AlterRelationshipDto) => string} * */ -const getFullChildTableName = _ => relationship => { - const { getNamePrefixedWithSchemaName } = require('../../utils/general')(_); +const getFullChildTableName = (_, scriptFormat) => relationship => { + const { getNamePrefixedWithSchemaNameForScriptFormat } = require('../../utils/general')(_); const compMod = relationship.role.compMod; const childBucketName = compMod.child.bucket.name; const childEntityName = compMod.child.collection.name; - return getNamePrefixedWithSchemaName(childEntityName, childBucketName); + return getNamePrefixedWithSchemaNameForScriptFormat(scriptFormat)(childEntityName, childBucketName); }; /** @@ -86,14 +86,14 @@ const getAddForeignKeyScriptDtos = (ddlProvider, _) => addedRelationships => { * statement: string, * }} * */ -const getDeleteSingleForeignKeyStatementDto = (ddlProvider, _) => relationship => { - const { wrapInQuotes } = require('../../utils/general')(_); +const getDeleteSingleForeignKeyStatementDto = (ddlProvider, _, scriptFormat) => relationship => { + const { prepareNameForScriptFormat } = require('../../utils/general')(_); const compMod = relationship.role.compMod; - const ddlChildEntityName = getFullChildTableName(_)(relationship); + const ddlChildEntityName = getFullChildTableName(_, scriptFormat)(relationship); const relationshipName = compMod.name?.old || getRelationshipName(relationship) || ''; - const ddlRelationshipName = wrapInQuotes(relationshipName); + const ddlRelationshipName = prepareNameForScriptFormat(scriptFormat)(relationshipName); const statement = ddlProvider.dropForeignKey(ddlChildEntityName, ddlRelationshipName); const isRelationshipActivated = Boolean(relationship.role?.compMod?.isActivated?.new); @@ -123,11 +123,11 @@ const canRelationshipBeDeleted = relationship => { /** * @return {(deletedRelationships: Array) => Array} * */ -const getDeleteForeignKeyScriptDtos = (ddlProvider, _) => deletedRelationships => { +const getDeleteForeignKeyScriptDtos = (ddlProvider, _, scriptFormat) => deletedRelationships => { return deletedRelationships .filter(relationship => canRelationshipBeDeleted(relationship)) .map(relationship => { - const scriptDto = getDeleteSingleForeignKeyStatementDto(ddlProvider, _)(relationship); + const scriptDto = getDeleteSingleForeignKeyStatementDto(ddlProvider, _, scriptFormat)(relationship); return AlterScriptDto.getInstance([scriptDto.statement], scriptDto.isActivated, true); }) .filter(Boolean) @@ -137,11 +137,11 @@ const getDeleteForeignKeyScriptDtos = (ddlProvider, _) => deletedRelationships = /** * @return {(modifiedRelationships: Array) => Array} * */ -const getModifyForeignKeyScriptDtos = (ddlProvider, _) => modifiedRelationships => { +const getModifyForeignKeyScriptDtos = (ddlProvider, _, scriptFormat) => modifiedRelationships => { return modifiedRelationships .filter(relationship => canRelationshipBeAdded(relationship) && canRelationshipBeDeleted(relationship)) .map(relationship => { - const deleteScriptDto = getDeleteSingleForeignKeyStatementDto(ddlProvider, _)(relationship); + const deleteScriptDto = getDeleteSingleForeignKeyStatementDto(ddlProvider, _, scriptFormat)(relationship); const addScriptDto = getAddSingleForeignKeyStatementDto(ddlProvider, _)(relationship); const isActivated = addScriptDto.isActivated && deleteScriptDto.isActivated; return AlterScriptDto.getDropAndRecreateInstance( diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterUdtHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterUdtHelper.js index 988474e..16fd010 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterUdtHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterUdtHelper.js @@ -7,10 +7,14 @@ const _ = require('lodash'); * @return {(jsonSchema: Object) => AlterScriptDto | undefined} * */ const getCreateUdtScriptDto = - ({ app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions }) => + ({ app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions, scriptFormat }) => jsonSchema => { const { createColumnDefinitionBySchema } = require('./createColumnDefinition')(app); - const ddlProvider = require('../../ddlProvider/ddlProvider')(null, { dbVersion }, app); + const ddlProvider = require('../../ddlProvider/ddlProvider')( + null, + { dbVersion, targetScriptOptions: { keyword: scriptFormat } }, + app, + ); const { getDefinitionByReference } = app.require('@hackolade/ddl-fe-utils'); const schemaData = { dbVersion }; @@ -50,10 +54,10 @@ const getCreateUdtScriptDto = /** * @return {(udt: Object) => AlterScriptDto | undefined} * */ -const getDeleteUdtScriptDto = app => udt => { - const { wrapInQuotes } = require('../../utils/general')(_); +const getDeleteUdtScriptDto = (app, scriptFormat) => udt => { + const { prepareNameForScriptFormat } = require('../../utils/general')(_); - const ddlUdtName = wrapInQuotes(udt.code || udt.name); + const ddlUdtName = prepareNameForScriptFormat(scriptFormat)(udt.code || udt.name); const dropUdtScript = `DROP TYPE ${ddlUdtName};`; return AlterScriptDto.getInstance([dropUdtScript], true, true); }; @@ -62,14 +66,18 @@ const getDeleteUdtScriptDto = app => udt => { * @return {(udt: Object) => AlterScriptDto[]} * */ const getAddColumnToTypeScriptDtos = - ({ app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions }) => + ({ app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions, scriptFormat }) => udt => { const { createColumnDefinitionBySchema } = require('./createColumnDefinition')(app); - const { wrapInQuotes } = require('../../utils/general')(_); - const ddlProvider = require('../../ddlProvider/ddlProvider')(null, { dbVersion }, app); + const { prepareNameForScriptFormat } = require('../../utils/general')(_); + const ddlProvider = require('../../ddlProvider/ddlProvider')( + null, + { dbVersion, targetScriptOptions: { keyword: scriptFormat } }, + app, + ); const { getDefinitionByReference } = app.require('@hackolade/ddl-fe-utils'); - const fullName = wrapInQuotes(udt.code || udt.name); + const fullName = prepareNameForScriptFormat(scriptFormat)(udt.code || udt.name); const schemaData = { dbVersion }; return _.toPairs(udt.properties) @@ -99,24 +107,24 @@ const getAddColumnToTypeScriptDtos = /** * @return {(udt: Object) => AlterScriptDto[]} * */ -const getDeleteColumnFromTypeScriptDtos = app => udt => { - const { wrapInQuotes } = require('../../utils/general')(_); +const getDeleteColumnFromTypeScriptDtos = (app, scriptFormat) => udt => { + const { prepareNameForScriptFormat } = require('../../utils/general')(_); - const fullName = wrapInQuotes(udt.code || udt.name); + const fullName = prepareNameForScriptFormat(scriptFormat)(udt.code || udt.name); return _.toPairs(udt.properties) .filter(([name, jsonSchema]) => !jsonSchema.compMod) - .map(([name]) => `ALTER TYPE ${fullName} DROP ATTRIBUTE ${wrapInQuotes(name)};`) + .map(([name]) => `ALTER TYPE ${fullName} DROP ATTRIBUTE ${prepareNameForScriptFormat(scriptFormat)(name)};`) .map(script => AlterScriptDto.getInstance([script], true, true)); }; /** * @return {(udt: Object) => AlterScriptDto[]} * */ -const getModifyColumnOfTypeScriptDtos = app => udt => { - const { wrapInQuotes } = require('../../utils/general')(_); +const getModifyColumnOfTypeScriptDtos = (app, scriptFormat) => udt => { + const { prepareNameForScriptFormat } = require('../../utils/general')(_); - const fullName = wrapInQuotes(udt.code || udt.name); + const fullName = prepareNameForScriptFormat(scriptFormat)(udt.code || udt.name); /** * @type {AlterScriptDto[]} @@ -124,10 +132,10 @@ const getModifyColumnOfTypeScriptDtos = app => udt => { const renameColumnScripts = _.values(udt.properties) .filter(jsonSchema => checkFieldPropertiesChanged(jsonSchema.compMod, ['name'])) .flatMap(jsonSchema => { - const oldDdlName = wrapInQuotes(jsonSchema.compMod.oldField.name); + const oldDdlName = prepareNameForScriptFormat(scriptFormat)(jsonSchema.compMod.oldField.name); const dropAttributeScript = `ALTER TYPE ${fullName} DROP ATTRIBUTE ${oldDdlName};`; - const newDdlName = wrapInQuotes(jsonSchema.compMod.newField.name); + const newDdlName = prepareNameForScriptFormat(scriptFormat)(jsonSchema.compMod.newField.name); const createAttributeScript = `ALTER TYPE ${fullName} ADD ATTRIBUTE ${newDdlName};`; return [ @@ -142,7 +150,7 @@ const getModifyColumnOfTypeScriptDtos = app => udt => { const changeTypeScripts = _.toPairs(udt.properties) .filter(([name, jsonSchema]) => checkFieldPropertiesChanged(jsonSchema.compMod, ['type', 'mode'])) .map(([name, jsonSchema]) => { - const ddlAttributeName = wrapInQuotes(name); + const ddlAttributeName = prepareNameForScriptFormat(scriptFormat)(name); const ddlType = _.toUpper(jsonSchema.compMod.newField.mode || jsonSchema.compMod.newField.type); const script = `ALTER TYPE ${fullName} MODIFY ATTRIBUTE ${ddlAttributeName} ${ddlType};`; return AlterScriptDto.getInstance([script], true, false); diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterViewHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterViewHelper.js index c27f99d..c6bf42d 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterViewHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterViewHelper.js @@ -5,8 +5,12 @@ const _ = require('lodash'); /** * @return {(view: Object) => AlterScriptDto | undefined} * */ -const getAddRegularViewScriptDto = app => view => { - const ddlProvider = require('../../ddlProvider/ddlProvider')(null, null, app); +const getAddRegularViewScriptDto = (app, scriptFormat) => view => { + const ddlProvider = require('../../ddlProvider/ddlProvider')( + null, + { targetScriptOptions: { keyword: scriptFormat } }, + app, + ); const viewData = { name: view.code || view.name, keys: [], @@ -20,8 +24,12 @@ const getAddRegularViewScriptDto = app => view => { /** * @return {(view: Object) => AlterScriptDto | undefined} * */ -const getDualityViewScriptDto = app => view => { - const ddlProvider = require('../../ddlProvider/ddlProvider')(null, null, app); +const getDualityViewScriptDto = (app, scriptFormat) => view => { + const ddlProvider = require('../../ddlProvider/ddlProvider')( + null, + { targetScriptOptions: { keyword: scriptFormat } }, + app, + ); const createDualityViewDto = mapDeltaDualityViewToFeDualityView(_)(view); const script = ddlProvider.createDualityView(createDualityViewDto); @@ -31,12 +39,12 @@ const getDualityViewScriptDto = app => view => { /** * @return {(view: Object) => AlterScriptDto | undefined} * */ -const getAddViewScriptDto = app => view => { +const getAddViewScriptDto = (app, scriptFormat) => view => { if (view.duality) { - return getDualityViewScriptDto(app)(view); + return getDualityViewScriptDto(app, scriptFormat)(view); } if (view.selectStatement) { - return getAddRegularViewScriptDto(app)(view); + return getAddRegularViewScriptDto(app, scriptFormat)(view); } return undefined; }; @@ -44,9 +52,9 @@ const getAddViewScriptDto = app => view => { /** * @return {(view: Object) => AlterScriptDto | undefined} * */ -const getDeleteViewScriptDto = app => view => { - const { wrapInQuotes } = require('../../utils/general')(_); - const ddlViewName = wrapInQuotes(view.code || view.name); +const getDeleteViewScriptDto = (app, scriptFormat) => view => { + const { prepareNameForScriptFormat } = require('../../utils/general')(_); + const ddlViewName = prepareNameForScriptFormat(scriptFormat)(view.code || view.name); const dropViewScript = `DROP VIEW ${ddlViewName};`; return AlterScriptDto.getInstance([dropViewScript], true, true); diff --git a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/alterTypeHelper.js b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/alterTypeHelper.js index c008789..f3b0ae8 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/alterTypeHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/alterTypeHelper.js @@ -4,20 +4,24 @@ const { AlterScriptDto } = require('../../types/AlterScriptDto'); /** * @return {(collection: Object) => AlterScriptDto[]} * */ -const getUpdateTypesScriptDtos = (_, ddlProvider) => collection => { - const { checkFieldPropertiesChanged, wrapInQuotes, getNamePrefixedWithSchemaName, getEntityName } = - require('../../../utils/general')(_); +const getUpdateTypesScriptDtos = (_, ddlProvider, scriptFormat) => collection => { + const { + checkFieldPropertiesChanged, + prepareNameForScriptFormat, + getNamePrefixedWithSchemaNameForScriptFormat, + getEntityName, + } = require('../../../utils/general')(_); const collectionSchema = { ...collection, ...(_.omit(collection?.role, 'properties') || {}) }; const tableName = getEntityName(collectionSchema); const schemaName = collectionSchema.compMod?.keyspaceName; - const fullName = getNamePrefixedWithSchemaName(tableName, schemaName); + const fullName = getNamePrefixedWithSchemaNameForScriptFormat(scriptFormat)(tableName, schemaName); return _.toPairs(collection.properties) .filter(([name, jsonSchema]) => checkFieldPropertiesChanged(jsonSchema.compMod, ['type', 'mode'])) .map( ([name, jsonSchema]) => - `ALTER TABLE ${fullName} MODIFY (${wrapInQuotes(name)} ${_.toUpper( + `ALTER TABLE ${fullName} MODIFY (${prepareNameForScriptFormat(scriptFormat)(name)} ${_.toUpper( jsonSchema.compMod.newField.mode || jsonSchema.compMod.newField.type, )});`, ) diff --git a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/renameColumnHelper.js b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/renameColumnHelper.js index e2a6b80..fde3234 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/renameColumnHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/columnHelpers/renameColumnHelper.js @@ -3,19 +3,23 @@ const { AlterScriptDto } = require('../../types/AlterScriptDto'); /** * @return {(collection: Object) => AlterScriptDto[]} * */ -const getRenameColumnScriptDtos = (_, ddlProvider) => collection => { - const { checkFieldPropertiesChanged, getEntityName, getNamePrefixedWithSchemaName, wrapInQuotes } = - require('../../../utils/general')(_); +const getRenameColumnScriptDtos = (_, ddlProvider, scriptFormat) => collection => { + const { + checkFieldPropertiesChanged, + getEntityName, + getNamePrefixedWithSchemaNameForScriptFormat, + prepareNameForScriptFormat, + } = require('../../../utils/general')(_); const collectionSchema = { ...collection, ...(_.omit(collection?.role, 'properties') || {}) }; const tableName = getEntityName(collectionSchema); const schemaName = collectionSchema.compMod?.keyspaceName; - const fullName = getNamePrefixedWithSchemaName(tableName, schemaName); + const fullName = getNamePrefixedWithSchemaNameForScriptFormat(scriptFormat)(tableName, schemaName); return _.values(collection.properties) .filter(jsonSchema => checkFieldPropertiesChanged(jsonSchema.compMod, ['name'])) .map(jsonSchema => { - const oldColumnName = wrapInQuotes(jsonSchema.compMod.oldField.name); - const newColumnName = wrapInQuotes(jsonSchema.compMod.newField.name); + const oldColumnName = prepareNameForScriptFormat(scriptFormat)(jsonSchema.compMod.oldField.name); + const newColumnName = prepareNameForScriptFormat(scriptFormat)(jsonSchema.compMod.newField.name); return ddlProvider.renameColumn(fullName, oldColumnName, newColumnName); }) .map(script => AlterScriptDto.getInstance([script], true, false)); diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexesHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexesHelper.js index 104c8ee..7b9a7e5 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexesHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexesHelper.js @@ -1,7 +1,7 @@ const { AlterScriptDto } = require('../../types/AlterScriptDto.js'); const { AlterCollectionDto } = require('../../types/AlterCollectionDto'); const { AlterIndexDto } = require('../../types/AlterIndexDto'); -const { wrapInQuotes } = require('../../../utils/general.js')(); +const { prepareNameForScriptFormat } = require('../../../utils/general.js')(); /** * @typedef {{ @@ -111,7 +111,7 @@ const addNameToIndexKey = ({ index, collection }) => { * @returns {GetAlterScriptDtosFunction} */ const getDeletedIndexesScriptDtos = - ({ _, ddlProvider }) => + ({ _, ddlProvider, scriptFormat }) => ({ collection }) => { const newIndexes = collection?.role?.compMod?.Indxs?.new || []; const oldIndexes = collection?.role?.compMod?.Indxs?.old || []; @@ -126,16 +126,18 @@ const getDeletedIndexesScriptDtos = return !correspondingNewIndex; }); - return deletedIndexes.map(index => getDeleteIndexScriptDto({ ddlProvider })({ index, collection })); + return deletedIndexes.map(index => + getDeleteIndexScriptDto({ ddlProvider, scriptFormat })({ index, collection }), + ); }; /** * @returns {GetAlterScriptDtoFunction} */ const getDeleteIndexScriptDto = - ({ ddlProvider }) => + ({ ddlProvider, scriptFormat }) => ({ index }) => { - const name = wrapInQuotes(index.indxName); + const name = prepareNameForScriptFormat(scriptFormat)(index.indxName); const script = ddlProvider.dropIndex({ name }); return AlterScriptDto.getInstance([script], index.isActivated, true); @@ -183,7 +185,7 @@ const getAddIndexScriptDto = * @returns {GetAlterScriptDtosFunction} */ const getModifiedIndexesScriptDtos = - ({ _, ddlProvider }) => + ({ _, ddlProvider, scriptFormat }) => ({ collection }) => { const newIndexes = collection?.role?.compMod?.Indxs?.new || []; const oldIndexes = collection?.role?.compMod?.Indxs?.old || []; @@ -207,7 +209,7 @@ const getModifiedIndexesScriptDtos = .filter(Boolean); return modifiedIndexes.flatMap(modifiedIndex => - getModifyIndexScriptDto({ _, ddlProvider })({ modifiedIndex, collection }), + getModifyIndexScriptDto({ _, ddlProvider, scriptFormat })({ modifiedIndex, collection }), ); }; @@ -215,10 +217,10 @@ const getModifiedIndexesScriptDtos = * @returns {GetAlterScriptDtoFunctionForModifiedIndex} */ const getModifyIndexScriptDto = - ({ _, ddlProvider }) => + ({ _, ddlProvider, scriptFormat }) => ({ modifiedIndex: { oldIndex, newIndex }, collection }) => { - const oldName = wrapInQuotes(oldIndex.indxName); - const newName = wrapInQuotes(newIndex.indxName); + const oldName = prepareNameForScriptFormat(scriptFormat)(oldIndex.indxName); + const newName = prepareNameForScriptFormat(scriptFormat)(newIndex.indxName); let alterScriptDtos = []; @@ -270,11 +272,11 @@ const getModifyIndexScriptDto = * @returns {GetAlterScriptDtosFunction} * */ const getModifyIndexesScriptDtos = - ({ _, ddlProvider }) => + ({ _, ddlProvider, scriptFormat }) => ({ collection }) => { - const removedIndexScriptDtos = getDeletedIndexesScriptDtos({ _, ddlProvider })({ collection }); + const removedIndexScriptDtos = getDeletedIndexesScriptDtos({ _, ddlProvider, scriptFormat })({ collection }); const addedIndexScriptDtos = getAddedIndexesScriptDtos({ _, ddlProvider })({ collection }); - const modifiedIndexScriptDtos = getModifiedIndexesScriptDtos({ _, ddlProvider })({ collection }); + const modifiedIndexScriptDtos = getModifiedIndexesScriptDtos({ _, ddlProvider, scriptFormat })({ collection }); return [...removedIndexScriptDtos, ...addedIndexScriptDtos, ...modifiedIndexScriptDtos].filter(Boolean); }; diff --git a/forward_engineering/config.json b/forward_engineering/config.json index 1e5fd6f..0103d88 100644 --- a/forward_engineering/config.json +++ b/forward_engineering/config.json @@ -1,13 +1,4 @@ { - "type": "ddl", - "ddlType": "plugin", - "mode": "sql", - "fileExtensions": [ - { - "value": "sql", - "label": "SQL" - } - ], "hasUpdateScript": false, "applyScriptToInstance": true, "combinedContainers": true, @@ -25,6 +16,36 @@ "entity": true, "view": true }, + "options": [ + { + "name": "quoted identifier", + "keyword": "quotedIdentifier", + "supportsDeltaModel": true, + "type": "ddl", + "ddlType": "plugin", + "mode": "sql", + "fileExtensions": [ + { + "value": "sql", + "label": "SQL" + } + ] + }, + { + "name": "nonquoted identifier", + "keyword": "nonquotedIdentifier", + "supportsDeltaModel": true, + "type": "ddl", + "ddlType": "plugin", + "mode": "sql", + "fileExtensions": [ + { + "value": "sql", + "label": "SQL" + } + ] + } + ], "additionalOptions": [ { "id": "applyDropStatements", diff --git a/forward_engineering/ddlProvider/ddlHelpers/columnDefinitionHelper.js b/forward_engineering/ddlProvider/ddlHelpers/columnDefinitionHelper.js index a3e6312..63b0b3e 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/columnDefinitionHelper.js +++ b/forward_engineering/ddlProvider/ddlHelpers/columnDefinitionHelper.js @@ -9,8 +9,8 @@ const shouldUseClobForJsonColumns = dbVersion => { return dbVersionAsNumber < DbVersion.JSON_TYPE_SINCE; }; -module.exports = ({ _, wrap, assignTemplates, templates, commentIfDeactivated, wrapComment, wrapInQuotes }) => { - const { getOptionsString } = require('./constraintHelper')({ _, wrapInQuotes }); +module.exports = ({ _, wrap, assignTemplates, templates, commentIfDeactivated, wrapComment, prepareName }) => { + const { getOptionsString } = require('./constraintHelper')({ _, prepareName }); const getColumnComments = (tableName, columnDefinitions) => { return _.chain(columnDefinitions) @@ -18,7 +18,7 @@ module.exports = ({ _, wrap, assignTemplates, templates, commentIfDeactivated, w .map(columnData => { const comment = assignTemplates(templates.comment, { object: 'COLUMN', - objectName: `${tableName}.${wrapInQuotes(columnData.name)}`, + objectName: `${tableName}.${prepareName(columnData.name)}`, comment: wrapComment(columnData.comment), }); diff --git a/forward_engineering/ddlProvider/ddlHelpers/constraintHelper.js b/forward_engineering/ddlProvider/ddlHelpers/constraintHelper.js index 917bde0..5b5d3cf 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/constraintHelper.js +++ b/forward_engineering/ddlProvider/ddlHelpers/constraintHelper.js @@ -1,8 +1,8 @@ const _ = require('lodash'); -module.exports = ({ wrapInQuotes, _ }) => { +module.exports = ({ prepareName, _ }) => { const getOptionsString = ({ constraintName, deferClause, rely, validate, indexClause, exceptionClause }) => { - const constraintString = constraintName ? ` CONSTRAINT ${wrapInQuotes(_.trim(constraintName))}` : ''; + const constraintString = constraintName ? ` CONSTRAINT ${prepareName(_.trim(constraintName))}` : ''; const statement = [deferClause, rely, indexClause, validate, exceptionClause].filter(Boolean).join(' '); return { diff --git a/forward_engineering/ddlProvider/ddlHelpers/dualityViewFeHelper/abstractDualityViewDdlCreator.js b/forward_engineering/ddlProvider/ddlHelpers/dualityViewFeHelper/abstractDualityViewDdlCreator.js index 70aa157..9f743f6 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/dualityViewFeHelper/abstractDualityViewDdlCreator.js +++ b/forward_engineering/ddlProvider/ddlHelpers/dualityViewFeHelper/abstractDualityViewDdlCreator.js @@ -8,15 +8,19 @@ class AbstractDualityViewFeDdlCreator { * @param ddlTemplates {Object} * @param assignTemplates {(template: string, values: Object) => string} * @param lodash {any} + * @param prepareName {(name: string) => string} + * @param getNamePrefixedWithSchemaName {(name: string, schemaName: string) => string * @throws {Error} * */ - constructor(ddlTemplates, assignTemplates, lodash) { + constructor(ddlTemplates, assignTemplates, lodash, prepareName, getNamePrefixedWithSchemaName) { if (this.constructor === AbstractDualityViewFeDdlCreator) { throw new Error("Abstract classes can't be instantiated."); } this._ddlTemplates = ddlTemplates; this._assignTemplates = assignTemplates; this._lodash = lodash; + this._prepareName = prepareName; + this._getNamePrefixedWithSchemaName = getNamePrefixedWithSchemaName; } /** @@ -177,14 +181,14 @@ class AbstractDualityViewFeDdlCreator { * */ getCreateJsonRelationalDualityViewHeadingDdl(createViewDto) { const { jsonSchema, view } = createViewDto; - const { getViewName, getNamePrefixedWithSchemaName } = require('../../../utils/general')(this._lodash); + const { getViewName } = require('../../../utils/general')(this._lodash); const template = this._ddlTemplates?.dualityView?.createJsonRelationalDualityViewHeading || ''; const orReplaceStatement = this._getOrReplaceStatement(view); const forceStatement = this._getForceStatement(jsonSchema); const editionableStatement = this._getEditionableStatement(jsonSchema); const viewName = getViewName(view); - const ddlViewName = getNamePrefixedWithSchemaName(viewName, view.schemaName); + const ddlViewName = this._getNamePrefixedWithSchemaName(viewName, view.schemaName); const params = { orReplaceStatement, diff --git a/forward_engineering/ddlProvider/ddlHelpers/dualityViewFeHelper/dualityViewDdlCreatorFactory.js b/forward_engineering/ddlProvider/ddlHelpers/dualityViewFeHelper/dualityViewDdlCreatorFactory.js index a310565..617f32c 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/dualityViewFeHelper/dualityViewDdlCreatorFactory.js +++ b/forward_engineering/ddlProvider/ddlHelpers/dualityViewFeHelper/dualityViewDdlCreatorFactory.js @@ -7,13 +7,24 @@ class DualityViewDdlCreatorFactory { * @param ddlTemplates {Object} * @param lodash {any} * @param assignTemplates {(template: string, values: Object) => string} + * @param prepareName {(name: string) => string} + * @param getNamePrefixedWithSchemaName {(name: string, schemaName: string) => string * @throws {Error} * @return {AbstractDualityViewFeDdlCreator} * */ - static getCreatorInstance(syntax, { ddlTemplates, assignTemplates, lodash }) { + static getCreatorInstance( + syntax, + { ddlTemplates, assignTemplates, lodash, prepareName, getNamePrefixedWithSchemaName }, + ) { switch (syntax?.toUpperCase()) { case DualityViewSyntaxType.SQL: - return new SqlDualityViewDdlCreator(ddlTemplates, assignTemplates, lodash); + return new SqlDualityViewDdlCreator( + ddlTemplates, + assignTemplates, + lodash, + prepareName, + getNamePrefixedWithSchemaName, + ); default: throw new Error(`Unknown syntax config: ${syntax}`); } diff --git a/forward_engineering/ddlProvider/ddlHelpers/dualityViewFeHelper/sqlDualityViewDdlCreator.js b/forward_engineering/ddlProvider/ddlHelpers/dualityViewFeHelper/sqlDualityViewDdlCreator.js index 69b553e..b9af107 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/dualityViewFeHelper/sqlDualityViewDdlCreator.js +++ b/forward_engineering/ddlProvider/ddlHelpers/dualityViewFeHelper/sqlDualityViewDdlCreator.js @@ -1,25 +1,13 @@ const { AbstractDualityViewFeDdlCreator } = require('./abstractDualityViewDdlCreator'); class SqlDualityViewDdlCreator extends AbstractDualityViewFeDdlCreator { - /** - * @param ddlTemplates {Object} - * @param lodash {any} - * @param assignTemplates {(template: string, values: Object) => string} - * @throws {Error} - * */ - constructor(ddlTemplates, assignTemplates, lodash) { - super(ddlTemplates, assignTemplates, lodash); - } - /** * @param view {DualityView} * @return {string} * */ _getFromRootTableAliasStatement(view) { - const { wrapInQuotes } = require('../../../utils/general')(this._lodash); - if (view.rootTableAlias) { - const ddlAlias = wrapInQuotes(view.rootTableAlias); + const ddlAlias = this._prepareName(view.rootTableAlias); return AbstractDualityViewFeDdlCreator.padInFront(ddlAlias); } return ''; @@ -30,10 +18,8 @@ class SqlDualityViewDdlCreator extends AbstractDualityViewFeDdlCreator { * @return {string} * */ _getFromChildTableAliasStatement(joinSubqueryJsonSchema) { - const { wrapInQuotes } = require('../../../utils/general')(this._lodash); - if (joinSubqueryJsonSchema.childTableAlias) { - const ddlAlias = wrapInQuotes(joinSubqueryJsonSchema.childTableAlias); + const ddlAlias = this._prepareName(joinSubqueryJsonSchema.childTableAlias); return AbstractDualityViewFeDdlCreator.padInFront(ddlAlias); } return ''; @@ -143,8 +129,7 @@ class SqlDualityViewDdlCreator extends AbstractDualityViewFeDdlCreator { * @return {string} * */ _getFromRootTableStatement(view) { - const { getNamePrefixedWithSchemaName } = require('../../../utils/general')(this._lodash); - const ddlTableName = getNamePrefixedWithSchemaName(view.tableName, view.schemaName); + const ddlTableName = this._getNamePrefixedWithSchemaName(view.tableName, view.schemaName); const aliasStatement = this._getFromRootTableAliasStatement(view); const tagsClauseStatement = this._getTableTagsStatement(view); @@ -169,11 +154,11 @@ class SqlDualityViewDdlCreator extends AbstractDualityViewFeDdlCreator { } const child = relatedSchemas[collectionId]; - const { getEntityName, getNamePrefixedWithSchemaName } = require('../../../utils/general')(this._lodash); + const { getEntityName } = require('../../../utils/general')(this._lodash); const tableName = getEntityName(child); const schemaName = child.bucketName; - const ddlTableName = getNamePrefixedWithSchemaName(tableName, schemaName); + const ddlTableName = this._getNamePrefixedWithSchemaName(tableName, schemaName); const aliasStatement = this._getFromChildTableAliasStatement(joinSubqueryJsonSchema); const tagsClauseStatement = this._getTableTagsStatement(joinSubqueryJsonSchema); @@ -198,21 +183,21 @@ class SqlDualityViewDdlCreator extends AbstractDualityViewFeDdlCreator { * @return {string} * */ _getNameOfReferencedColumnForDdl(parentEntity, propertyName, relatedSchemas) { - const { getEntityName, getNamePrefixedWithSchemaName } = require('../../../utils/general')(this._lodash); + const { getEntityName } = require('../../../utils/general')(this._lodash); if (AbstractDualityViewFeDdlCreator.isDualityView(parentEntity)) { const parentName = parentEntity.rootTableAlias || parentEntity.tableName; - return getNamePrefixedWithSchemaName(propertyName, parentName); + return this._getNamePrefixedWithSchemaName(propertyName, parentName); } if (AbstractDualityViewFeDdlCreator.isJoinSubquery(parentEntity)) { if (parentEntity.childTableAlias) { const parentName = parentEntity.childTableAlias; - return getNamePrefixedWithSchemaName(propertyName, parentName); + return this._getNamePrefixedWithSchemaName(propertyName, parentName); } const collectionId = this._lodash.first(parentEntity.joinedCollectionRefIdPath); if (collectionId) { const collection = relatedSchemas[collectionId]; const parentName = getEntityName(collection); - return getNamePrefixedWithSchemaName(propertyName, parentName); + return this._getNamePrefixedWithSchemaName(propertyName, parentName); } } return ''; diff --git a/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js b/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js index ec7e22c..2eb6ad5 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js +++ b/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js @@ -1,5 +1,5 @@ const _ = require('lodash'); -module.exports = ({ _, wrapInQuotes }) => { +module.exports = ({ _, prepareName }) => { const getIndexType = indexType => { return indexType ? ` ${_.toUpper(indexType)}` : ''; }; @@ -19,7 +19,7 @@ module.exports = ({ _, wrapInQuotes }) => { if (_.isArray(indxKey) && !_.isEmpty(indxKey)) { const indexedColumnsClause = _.map( indxKey, - ({ name, type }) => `${wrapInQuotes(name)} ${_.toUpper(type)}`, + ({ name, type }) => `${prepareName(name)} ${_.toUpper(type)}`, ).join(',\n\t'); return `\n(\n\t${indexedColumnsClause}\n)\n\t`; } @@ -57,7 +57,7 @@ module.exports = ({ _, wrapInQuotes }) => { return options; }; - const getIndexName = name => (name ? ` ${wrapInQuotes(name)}` : ''); + const getIndexName = name => (name ? ` ${prepareName(name)}` : ''); return { getIndexType, diff --git a/forward_engineering/ddlProvider/ddlHelpers/synonymHelper.js b/forward_engineering/ddlProvider/ddlHelpers/synonymHelper.js index 800cd1e..de7ae8c 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/synonymHelper.js +++ b/forward_engineering/ddlProvider/ddlHelpers/synonymHelper.js @@ -1,8 +1,8 @@ -module.exports = ({ wrapInQuotes, templates, assignTemplates, getNamePrefixedWithSchemaName }) => { +module.exports = ({ prepareName, templates, assignTemplates, getNamePrefixedWithSchemaName }) => { const generateSynonymCreateStatement = synonym => { const namePrefixedWithSchemaName = getNamePrefixedWithSchemaName(synonym.synonymName, synonym.schemaName); return assignTemplates(templates.createSynonym, { - name: synonym.synonymPublic ? wrapInQuotes(synonym.synonymName) : namePrefixedWithSchemaName, + name: synonym.synonymPublic ? prepareName(synonym.synonymName) : namePrefixedWithSchemaName, orReplace: synonym.synonymOrReplace ? ' OR REPLACE' : '', editionable: synonym.synonymEditionable ? ' ' + synonym.synonymEditionable : '', public: synonym.synonymPublic ? ' PUBLIC' : '', diff --git a/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js b/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js index 7552a5e..88c850e 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js +++ b/forward_engineering/ddlProvider/ddlHelpers/tableHelper.js @@ -4,10 +4,10 @@ module.exports = ({ getColumnsList, checkAllKeysDeactivated, commentIfDeactivated, - wrapInQuotes, + prepareName, assignTemplates, }) => { - const { getOptionsString } = require('./constraintHelper')({ _, wrapInQuotes }); + const { getOptionsString } = require('./constraintHelper')({ _, prepareName }); const getTableType = ({ duplicated, @@ -87,7 +87,7 @@ module.exports = ({ } return ( `ORGANIZATION ${_.toUpper(organization) || 'HEAP'}` + - `${tablespace ? ` TABLESPACE ${wrapInQuotes(tablespace)}` : ''}` + + `${tablespace ? ` TABLESPACE ${prepareName(tablespace)}` : ''}` + ` ${logging ? 'LOGGING' : 'NOLOGGING'}` ); }; @@ -139,7 +139,9 @@ module.exports = ({ if (_.isEmpty(value.partitionKey)) { return ''; } - return getColumnsList(value.partitionKey, isAllColumnsDeactivated, isParentActivated); + return getColumnsList(value.partitionKey, isAllColumnsDeactivated, isParentActivated, ({ name }) => + prepareName(name), + ); }; const getPartitionClause = (value, isActivated) => { @@ -218,7 +220,7 @@ module.exports = ({ const isAllColumnsDeactivated = checkAllKeysDeactivated(compositePartitionKey); const subpartitionDescriptionToUse = subpartitionDescription ? `\n${subpartitionDescription}` : ''; - return ` SUBPARTITION BY ${_.toUpper(subpartitionType)} ${getColumnsList(compositePartitionKey, isAllColumnsDeactivated, isParentActivated)} ${subpartitionDescriptionToUse}`; + return ` SUBPARTITION BY ${_.toUpper(subpartitionType)} ${getColumnsList(compositePartitionKey, isAllColumnsDeactivated, isParentActivated, ({ name }) => prepareName(name))} ${subpartitionDescriptionToUse}`; } return ''; @@ -274,10 +276,10 @@ module.exports = ({ if (Array.isArray(keys)) { const activatedKeys = keys .filter(key => _.get(key, 'isActivated', true)) - .map(key => wrapInQuotes(_.trim(key.name))); + .map(key => prepareName(_.trim(key.name))); const deactivatedKeys = keys .filter(key => !_.get(key, 'isActivated', true)) - .map(key => wrapInQuotes(_.trim(key.name))); + .map(key => prepareName(_.trim(key.name))); const deactivatedKeysAsString = deactivatedKeys.length ? commentIfDeactivated(deactivatedKeys, { isActivated: false, isPartOfLine: true }) : ''; @@ -293,12 +295,14 @@ module.exports = ({ const createKeyConstraint = (templates, isParentActivated) => keyData => { const isAllColumnsDeactivated = checkAllKeysDeactivated(keyData.columns); - const columns = getColumnsList(keyData.columns, isAllColumnsDeactivated, isParentActivated); + const columns = getColumnsList(keyData.columns, isAllColumnsDeactivated, isParentActivated, ({ name }) => + prepareName(name), + ); const options = getOptionsString(keyData).statement; return { statement: assignTemplates(templates.createKeyConstraint, { - constraintName: keyData.constraintName ? `CONSTRAINT ${wrapInQuotes(keyData.constraintName)} ` : '', + constraintName: keyData.constraintName ? `CONSTRAINT ${prepareName(keyData.constraintName)} ` : '', keyType: keyData.keyType, columns, options, diff --git a/forward_engineering/ddlProvider/ddlHelpers/viewHelper.js b/forward_engineering/ddlProvider/ddlHelpers/viewHelper.js index 1183799..04fd5cd 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/viewHelper.js +++ b/forward_engineering/ddlProvider/ddlHelpers/viewHelper.js @@ -1,4 +1,4 @@ -module.exports = ({ _, wrapInQuotes }) => { +module.exports = ({ _, prepareName }) => { const getViewType = ({ editioning, editionable }) => { return `${editionable ? ' EDITIONABLE' : ''}${editioning ? ' EDITIONING' : ''}`; }; @@ -9,9 +9,9 @@ module.exports = ({ _, wrapInQuotes }) => { } if (key.alias) { - return `${wrapInQuotes(key.name)} as ${wrapInQuotes(key.alias)}`; + return `${prepareName(key.name)} as ${prepareName(key.alias)}`; } else { - return wrapInQuotes(key.name); + return prepareName(key.name); } }; @@ -28,7 +28,7 @@ module.exports = ({ _, wrapInQuotes }) => { return result; } - const tableName = `${wrapInQuotes(key.dbName)}.${wrapInQuotes(key.tableName)}`; + const tableName = `${prepareName(key.dbName)}.${prepareName(key.tableName)}`; if (!result.tables.includes(tableName)) { result.tables.push(tableName); diff --git a/forward_engineering/ddlProvider/ddlProvider.js b/forward_engineering/ddlProvider/ddlProvider.js index 311db94..330e347 100644 --- a/forward_engineering/ddlProvider/ddlProvider.js +++ b/forward_engineering/ddlProvider/ddlProvider.js @@ -28,12 +28,17 @@ module.exports = (baseProvider, options, app) => { hasType, wrap, clean, - wrapInQuotes, - getNamePrefixedWithSchemaName, + getNamePrefixedWithSchemaNameForScriptFormat, wrapComment, getColumnsList, + prepareNameForScriptFormat, } = require('../utils/general')(_); + const prepareName = prepareNameForScriptFormat(options?.targetScriptOptions?.keyword); + const getNamePrefixedWithSchemaName = getNamePrefixedWithSchemaNameForScriptFormat( + options?.targetScriptOptions?.keyword, + ); + const { assignTemplates } = require('../utils/assignTemplates')({ _ }); const keyHelper = require('./ddlHelpers/keyHelper')(_, clean); @@ -52,8 +57,8 @@ module.exports = (baseProvider, options, app) => { assignTemplates, templates, commentIfDeactivated, - wrapInQuotes, wrapComment, + prepareName, }); const { @@ -69,7 +74,7 @@ module.exports = (baseProvider, options, app) => { checkAllKeysDeactivated, getColumnsList, commentIfDeactivated, - wrapInQuotes, + prepareName, assignTemplates, }); @@ -79,17 +84,16 @@ module.exports = (baseProvider, options, app) => { assignTemplates, templates, getNamePrefixedWithSchemaName, - wrapInQuotes, }); const { getViewType, getViewData } = require('./ddlHelpers/viewHelper')({ _, - wrapInQuotes, + prepareName, }); const { getIndexType, getIndexKeys, getIndexOptions, getIndexName } = require('./ddlHelpers/indexHelper')({ _, - wrapInQuotes, + prepareName, }); const wrapIfNotExists = (statement, ifNotExist, errorCode = 955) => { @@ -104,7 +108,7 @@ module.exports = (baseProvider, options, app) => { }; const { generateSynonymStatements } = require('./ddlHelpers/synonymHelper')({ - wrapInQuotes, + prepareName, templates, assignTemplates, getNamePrefixedWithSchemaName, @@ -116,7 +120,6 @@ module.exports = (baseProvider, options, app) => { templates, assignTemplates, getNamePrefixedWithSchemaName, - wrapInQuotes, wrapIfNotExists, }); @@ -147,7 +150,7 @@ module.exports = (baseProvider, options, app) => { createSchema({ schemaName, ifNotExist, dbVersion, sequences }) { const usingTryCatchWrapper = shouldUseTryCatchIfNotExistsWrapper(dbVersion); const schemaStatement = assignTemplates(templates.createSchema, { - schemaName: wrapInQuotes(schemaName), + schemaName: prepareName(schemaName), ifNotExists: !usingTryCatchWrapper && ifNotExist ? ' IF NOT EXISTS' : '', }); const sequencesStatement = getSequencesScript({ schemaName, sequences, usingTryCatchWrapper }); @@ -215,7 +218,7 @@ module.exports = (baseProvider, options, app) => { return commentIfDeactivated( assignTemplates(template, { - name: wrapInQuotes(columnDefinition.name), + name: prepareName(columnDefinition.name), type: decorateType(type, columnDefinition), default: getColumnDefault(columnDefinition), encrypt: getColumnEncrypt(columnDefinition), @@ -238,7 +241,7 @@ module.exports = (baseProvider, options, app) => { createCheckConstraint({ name, expression, comments, description }) { return assignTemplates(templates.checkConstraint, { - name: name ? `CONSTRAINT ${wrapInQuotes(name)} ` : '', + name: name ? `CONSTRAINT ${prepareName(name)} ` : '', expression: _.trim(expression).replace(/^\(([\s\S]*)\)$/, '$1'), }); }, @@ -273,7 +276,7 @@ module.exports = (baseProvider, options, app) => { const foreignKeyStatement = assignTemplates(templates.createForeignKeyConstraint, { primaryTable: getNamePrefixedWithSchemaName(primaryTable, primarySchemaName || schemaData.schemaName), - name: name ? `CONSTRAINT ${wrapInQuotes(name)}` : '', + name: name ? `CONSTRAINT ${prepareName(name)}` : '', foreignKey: isActivated ? foreignKeysToString(foreignKeys) : foreignActiveKeysToString(foreignKeys), primaryKey: isActivated ? foreignKeysToString(primaryKeys) : foreignActiveKeysToString(primaryKeys), onDelete: foreignOnDelete ? ` ON DELETE ${foreignOnDelete}` : '', @@ -317,7 +320,7 @@ module.exports = (baseProvider, options, app) => { const foreignKeyStatement = assignTemplates(templates.createForeignKey, { primaryTable: getNamePrefixedWithSchemaName(primaryTable, primarySchemaName || schemaData.schemaName), foreignTable: getNamePrefixedWithSchemaName(foreignTable, foreignSchemaName || schemaData.schemaName), - name: name ? wrapInQuotes(name) : '', + name: name ? prepareName(name) : '', foreignKey: isActivated ? foreignKeysToString(foreignKeys) : foreignActiveKeysToString(foreignKeys), primaryKey: isActivated ? foreignKeysToString(primaryKeys) : foreignActiveKeysToString(primaryKeys), onDelete: foreignOnDelete ? ` ON DELETE ${foreignOnDelete}` : '', @@ -651,6 +654,8 @@ module.exports = (baseProvider, options, app) => { ddlTemplates: templates, assignTemplates, lodash: _, + prepareName, + getNamePrefixedWithSchemaName, }); return ddlCreator.convertDualityViewToDdl({ view, diff --git a/forward_engineering/utils/general.js b/forward_engineering/utils/general.js index 06d0082..701e646 100644 --- a/forward_engineering/utils/general.js +++ b/forward_engineering/utils/general.js @@ -141,14 +141,18 @@ module.exports = _ => { const wrapInQuotes = name => `"${name}"`; + const prepareNameForScriptFormat = scriptFormat => name => { + return scriptFormat === 'nonquotedIdentifier' ? name : wrapInQuotes(name); + }; + const wrapComment = comment => `'${comment}'`; - const getNamePrefixedWithSchemaName = (name, schemaName) => { + const getNamePrefixedWithSchemaNameForScriptFormat = scriptFormat => (name, schemaName) => { if (schemaName) { - return `${wrapInQuotes(schemaName)}.${wrapInQuotes(name)}`; + return `${prepareNameForScriptFormat(scriptFormat)(schemaName)}.${prepareNameForScriptFormat(scriptFormat)(name)}`; } - return wrapInQuotes(name); + return prepareNameForScriptFormat(scriptFormat)(name); }; const checkFieldPropertiesChanged = (compMod, propertiesToCheck) => { @@ -220,10 +224,11 @@ module.exports = _ => { wrap, wrapComment, wrapInQuotes, - getNamePrefixedWithSchemaName, + getNamePrefixedWithSchemaNameForScriptFormat, checkFieldPropertiesChanged, getColumnsList, escapeSingleQuote, getGroupItemsByCompMode, + prepareNameForScriptFormat, }; };