Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions forward_engineering/alterScript/alterScriptFromDeltaHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,17 @@ const getSectionItems = section => ({
});

/**
* Build the container statements. Schemas can only be dropped once every table they hold is gone, so the deleted
* containers are reported separately and applied last.
* Build SET SCHEMA statements for added containers. Deleted and modified schemas do not produce schema-level DDL in Db2
* for z/OS.
*
* @param {{ collection: DeltaModel; app: App }} params Delta model and app instance.
* @returns {{ deletedContainersScriptDtos: AlterScriptDto[]; upsertedContainersScriptDtos: AlterScriptDto[] }}
* Container alter script DTOs.
* @returns {AlterScriptDto[]} Container alter script DTOs.
*/
const getAlterContainersScriptDtos = ({ collection, app }) => {
const { added, deleted, modified } = getSectionItems(collection.properties?.containers);
const { getAddContainerScriptDto, getDeleteContainerScriptDto, getModifyContainerScriptDto } =
getContainersScripts(app);
const { added } = getSectionItems(collection.properties?.containers);
const { getAddContainerScriptDto } = getContainersScripts(app);

return {
deletedContainersScriptDtos: deleted
.map(container => getDeleteContainerScriptDto(container))
.filter(scriptDto => scriptDto !== undefined),
upsertedContainersScriptDtos: [
...added.map(container => getAddContainerScriptDto(container)),
...modified.flatMap(container => getModifyContainerScriptDto(container)),
].filter(scriptDto => scriptDto !== undefined),
};
return added.map(container => getAddContainerScriptDto(container)).filter(scriptDto => scriptDto !== undefined);
};

/**
Expand Down Expand Up @@ -312,21 +302,20 @@ const getAlterScriptDtos = (data, app) => {
.filter(id => id !== undefined);
const relatedSchemas = buildRelatedSchemas(getSectionItems(collection.properties?.entities));

const { deletedContainersScriptDtos, upsertedContainersScriptDtos } = getAlterContainersScriptDtos({
const containerScriptDtos = getAlterContainersScriptDtos({
collection,
app,
});
const { deletedTypesScriptDtos, upsertedTypesScriptDtos } = getAlterTypesScriptDtos({ collection, app });

return [
...upsertedContainersScriptDtos,
...containerScriptDtos,
...upsertedTypesScriptDtos,
...getAlterCollectionScriptDtos({ collection, app, inlineDeltaRelationships, relatedSchemas }),
...getAlterVersioningScriptDtos({ collection, relatedSchemas }),
...getAlterRelationshipsScriptDtos({ collection, ignoreRelationshipIDs }),
...getAlterViewScriptDtos({ collection, app }),
...deletedTypesScriptDtos,
...deletedContainersScriptDtos,
]
.map(dto => prettifyAlterScriptDto(dto))
.filter(dto => dto !== undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,60 +10,28 @@
*/

const { createAlterScriptDto } = require('../dto/alterScriptDto');
const { wrapInQuotes } = require('../../utils/general');
const { getModifiedCommentOnSchemaScriptDtos } = require('./containerHelpers/commentsHelper');

/**
* Build the CREATE SCHEMA statement for an added container.
* Build the SET SCHEMA statement for an added container.
*
* @param {DdlProvider} ddlProvider DDL provider.
* @returns {(containerData: AlterContainer) => AlterScriptDto | undefined} Add container script builder.
*/
const getAddContainerScriptDto = ddlProvider => containerData => {
const script = ddlProvider.createSchema({
schemaName: containerData.role.name,
description: containerData.role.description,
isActivated: containerData.role.isActivated,
});

return createAlterScriptDto([script], true, false);
};

/**
* Build the DROP SCHEMA statement for a deleted container.
*
* @param {DdlProvider} ddlProvider DDL provider.
* @returns {(containerData: AlterContainer) => AlterScriptDto | undefined} Delete container script builder.
*/
const getDeleteContainerScriptDto = ddlProvider => containerData => {
const script = ddlProvider.dropSchema({ name: containerData.role.name });

return createAlterScriptDto([script], true, true);
};

/**
* Build the statements for a modified container.
*
* @returns {(containerData: AlterContainer) => AlterScriptDto[]} Modify container script builder.
*/
const getModifyContainerScriptDto = () => containerData => {
const commentScriptDto = getModifiedCommentOnSchemaScriptDtos({
schemaName: wrapInQuotes(containerData.role.name),
compMod: containerData.role.compMod ?? {},
isActivated: containerData.isActivated !== false,
});

return commentScriptDto ? [commentScriptDto] : [];
};

/**
* Build the container-level script builders bound to a DDL provider.
*
* @param {App} app App instance.
* @returns {{
* getAddContainerScriptDto: (containerData: AlterContainer) => AlterScriptDto | undefined;
* getDeleteContainerScriptDto: (containerData: AlterContainer) => AlterScriptDto | undefined;
* getModifyContainerScriptDto: (containerData: AlterContainer) => AlterScriptDto[];
* }}
* Container script builders.
*/
Expand All @@ -72,8 +40,6 @@ const getContainersScripts = app => {

return {
getAddContainerScriptDto: getAddContainerScriptDto(ddlProvider),
getDeleteContainerScriptDto: getDeleteContainerScriptDto(ddlProvider),
getModifyContainerScriptDto: getModifyContainerScriptDto(),
};
};

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const { wrapInQuotes, commentIfDeactivated, wrapInSingleQuotes } = require('../.

/** @enum {string} */
const OBJECT_TYPE = {
schema: 'SCHEMA',
column: 'COLUMN',
table: 'TABLE',
index: 'INDEX',
Expand Down Expand Up @@ -146,21 +145,6 @@ const dropTypeCommentStatement = ({ typeName }) => {
});
};

/**
* Build a schema comment statement.
*
* @param {{ schemaName: string; description?: string }} params Schema comment params.
* @returns {string} Comment statement.
*/
const getSchemaCommentStatement = ({ schemaName, description }) => {
return getCommentStatement({
objectName: schemaName,
objectType: OBJECT_TYPE.schema,
description,
mode: COMMENT_MODE.set,
});
};

/**
* Build column comments for a table.
*
Expand All @@ -183,20 +167,6 @@ const getColumnComments = ({ tableName, columnDefinitions }) => {
.join('\n');
};

/**
* Build the statement removing a schema comment.
*
* @param {{ schemaName: string }} params Schema name.
* @returns {string} Comment statement.
*/
const dropSchemaCommentStatement = ({ schemaName }) =>
getCommentStatement({
objectName: schemaName,
objectType: OBJECT_TYPE.schema,
description: '',
mode: COMMENT_MODE.remove,
});

/**
* Build the statement removing a table comment.
*
Expand Down Expand Up @@ -227,14 +197,12 @@ const dropTableColumnCommentStatement = ({ tableName, columnName }) =>

module.exports = {
getColumnCommentStatement,
getSchemaCommentStatement,
getTableCommentStatement,
getIndexCommentStatement,
dropIndexCommentStatement,
getTypeCommentStatement,
dropTypeCommentStatement,
getColumnComments,
dropSchemaCommentStatement,
dropTableCommentStatement,
dropTableColumnCommentStatement,
};
48 changes: 14 additions & 34 deletions forward_engineering/ddlProvider/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* CreateSchemaParams,
* CreateTableParams,
* DdlProvider,
* DropSchemaParams,
* ForeignKeyInput,
* ForeignKeyStatement,
* HydrateColumnParams,
Expand Down Expand Up @@ -48,7 +47,6 @@ const { getColumnConstraints } = require('./ddlHelpers/columnDefinition/getColum
const {
getTableCommentStatement,
getColumnComments,
getSchemaCommentStatement,
getIndexCommentStatement,
getTypeCommentStatement,
} = require('./ddlHelpers/comment/commentHelper.js');
Expand Down Expand Up @@ -130,56 +128,38 @@ const hydrateSchema = containerData => ({
});

/**
* Create schema DDL.
* Set the current schema.
*
* @param {CreateSchemaParams} params Schema params.
* @returns {string} Schema DDL.
* @returns {string} SET SCHEMA DDL.
*/
const createSchema = ({ schemaName, description, isActivated = true }) => {
const createSchema = ({ schemaName, isActivated = true }) => {
const wrappedSchemaName = wrapInQuotes(schemaName);
const schemaStatement = assignTemplates({
template: templates.createSchema,
const setSchemaStatement = assignTemplates({
template: templates.setSchema,
templateData: {
schemaName: wrappedSchemaName,
},
});

const comment = getSchemaCommentStatement({ schemaName: wrappedSchemaName, description });
const commentStatement = comment ? '\n' + comment + '\n' : '\n';

return commentDeactivatedStatement(schemaStatement + commentStatement, { isActivated });
return commentDeactivatedStatement(setSchemaStatement + '\n', { isActivated });
};

/**
* Drop schema DDL.
* Return no DDL for dropping a schema. Db2 for z/OS schemas are qualifiers rather than standalone objects that can be
* dropped. This method remains in the provider for framework compatibility.
*
* @param {DropSchemaParams} params Schema params.
* @returns {string} Drop schema DDL.
* @returns {string} Empty DDL.
*/
const dropSchema = ({ name, isActivated = true }) => {
const dropSchemaStatement = assignTemplates({
template: templates.dropSchema,
templateData: {
schemaName: wrapInQuotes(name),
},
});

return commentDeactivatedStatement(dropSchemaStatement, { isActivated });
};
const dropSchema = () => '';

/**
* Alter schema DDL.
* Return no DDL for altering a schema. Db2 for z/OS does not support ALTER SCHEMA. This method remains in the provider
* for framework compatibility.
*
* @param {string} schemaName Schema name.
* @returns {string} Alter schema DDL.
* @returns {string} Empty DDL.
*/
const alterSchema = schemaName =>
assignTemplates({
template: templates.alterSchema,
templateData: {
schemaName: wrapInQuotes(schemaName),
},
});
const alterSchema = () => '';

/**
* Create distinct type DDL.
Expand Down
6 changes: 1 addition & 5 deletions forward_engineering/ddlProvider/templates.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module.exports = {
createSchema: 'CREATE SCHEMA ${schemaName};',

dropSchema: 'DROP SCHEMA ${schemaName} RESTRICT;',

alterSchema: 'ALTER SCHEMA ${schemaName};',
setSchema: 'SET SCHEMA = ${schemaName};',

createType: 'CREATE TYPE ${name} AS ${sourceType};',

Expand Down
4 changes: 2 additions & 2 deletions properties_pane/container_level/containerLevelConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ making sure that you maintain a proper JSON format.
"propertyTooltip": "",
"structure": [
{
"propertyName": "Before CREATE SCHEMA",
"propertyName": "Before SET SCHEMA",
"propertyKeyword": "beforeCreateContainer",
"propertyType": "details",
"markdown": false,
Expand All @@ -137,7 +137,7 @@ making sure that you maintain a proper JSON format.
}
},
{
"propertyName": "After CREATE SCHEMA",
"propertyName": "After SET SCHEMA",
"propertyKeyword": "afterCreateContainer",
"propertyType": "details",
"markdown": false,
Expand Down
4 changes: 2 additions & 2 deletions properties_pane/model_level/modelLevelConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ making sure that you maintain a proper JSON format.
}
},
{
"propertyName": "Before each CREATE SCHEMA",
"propertyName": "Before each SET SCHEMA",
"propertyKeyword": "beforeCreateContainer",
"propertyType": "details",
"markdown": false,
Expand All @@ -113,7 +113,7 @@ making sure that you maintain a proper JSON format.
}
},
{
"propertyName": "After each CREATE SCHEMA",
"propertyName": "After each SET SCHEMA",
"propertyKeyword": "afterCreateContainer",
"propertyType": "details",
"markdown": false,
Expand Down
Loading