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
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ const getAlterScriptDtos = (data, app) => {
return [
...upsertedContainersScriptDtos,
...collectionsScriptDtos,
...viewScriptDtos,
...relationshipScriptDtos,
...viewScriptDtos,
...deletedContainersScriptDtos,
]
.filter(Boolean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const getAddCollectionScriptDto = (ddlProvider, inlineDeltaRelationships) => col
*/
const getDeleteCollectionScriptDto = ddlProvider => collection => {
const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema });
const script = ddlProvider.dropTable({ tableName: fullTableName });

return AlterScriptDto.getInstance([script], true, true);
Expand Down Expand Up @@ -126,7 +126,7 @@ const getModifyCollectionKeysScriptDtos = ddlProvider => collection => {
*/
const getAddColumnScriptDtos = ddlProvider => collection => {
const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema });
const schemaName = getSchemaNameFromCollection({ collection });
const schemaData = { schemaName };

Expand Down Expand Up @@ -155,7 +155,7 @@ const getAddColumnScriptDtos = ddlProvider => collection => {
*/
const getDeleteColumnScriptDtos = ddlProvider => collection => {
const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema, preferAlterName: false });

return toPairs(collection.properties)
.filter(([name, jsonSchema]) => !jsonSchema.compMod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const alterColumnName = (tableName, oldColumnName, newColumnName) => {
*/
const getRenameColumnScriptDtos = collection => {
const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema });
const isContainerActivated = isParentContainerActivated(collection);
const isCollectionActivated = isObjectInDeltaModelActivated(collection);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const hasPrecisionOrScaleChanged = (collection, oldFieldName, currentJsonSchema)
*/
const getUpdateTypesScriptDtos = ddlProvider => collection => {
const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema });
const isContainerActivated = isParentContainerActivated(collection);
const isCollectionActivated = isObjectInDeltaModelActivated(collection);
const schemaName = getSchemaNameFromCollection({ collection });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const getUpdatedCommentOnColumnScriptDtos = collection => {
const isContainerActivated = isParentContainerActivated(collection);
const isCollectionActivated = isObjectInDeltaModelActivated(collection);
const collectionSchema = getSchemaOfAlterCollection(collection);
const tableName = getFullCollectionName(collectionSchema);
const tableName = getFullCollectionName({ collectionSchema });

return _.toPairs(collection.properties)
.filter(([name, jsonSchema]) => {
Expand All @@ -38,7 +38,7 @@ const getDeletedCommentOnColumnScriptDtos = collection => {
const isContainerActivated = isParentContainerActivated(collection);
const isCollectionActivated = isObjectInDeltaModelActivated(collection);
const collectionSchema = getSchemaOfAlterCollection(collection);
const tableName = getFullCollectionName(collectionSchema);
const tableName = getFullCollectionName({ collectionSchema });

return _.toPairs(collection.properties)
.filter(([name, jsonSchema]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const getUpdatedDefaultColumnValueScriptDtos = ({ collection }) => {
.map(([columnName, jsonSchema]) => {
const newDefaultValue = jsonSchema.default;
const scriptGenerationConfig = {
tableName: getFullCollectionName(collectionSchema),
tableName: getFullCollectionName({ collectionSchema }),
columnName: wrapInQuotes(columnName),
defaultValue: newDefaultValue,
};
Expand Down Expand Up @@ -92,7 +92,7 @@ const getDeletedDefaultColumnValueScriptDtos = ({ collection }) => {
})
.map(([columnName, jsonSchema]) => {
const scriptGenerationConfig = {
tableName: getFullCollectionName(collectionSchema),
tableName: getFullCollectionName({ collectionSchema }),
columnName: wrapInQuotes(columnName),
};
const isActivated = isContainerActivated && isCollectionActivated && jsonSchema.isActivated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const dropNotNullConstraint = (tableName, columnName) => {
*/
const getModifyNonNullColumnsScriptDtos = collection => {
const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema });

const isContainerActivated = isParentContainerActivated(collection);
const isCollectionActivated = isObjectInDeltaModelActivated(collection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const getUpdateCheckConstraintScriptDtos = (constraintHistory, fullTableName) =>

const getModifyCheckConstraintScriptDtos = collection => {
const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema });
const constraintHistory = mapCheckConstraintNamesToChangeHistory(collection);

const isContainerActivated = isParentContainerActivated(collection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const getUpdatedCommentOnCollectionScriptDto = collection => {
}

const collectionSchema = getSchemaOfAlterCollection(collection);
const tableName = getFullCollectionName(collectionSchema);
const tableName = getFullCollectionName({ collectionSchema });

const isContainerActivated = isParentContainerActivated(collection);
const isCollectionActivated = isContainerActivated && isObjectInDeltaModelActivated(collection);
Expand All @@ -44,7 +44,7 @@ const getDeletedCommentOnCollectionScriptDto = collection => {
}

const collectionSchema = getSchemaOfAlterCollection(collection);
const tableName = getFullCollectionName(collectionSchema);
const tableName = getFullCollectionName({ collectionSchema });

const isContainerActivated = isParentContainerActivated(collection);
const isCollectionActivated = isContainerActivated && isObjectInDeltaModelActivated(collection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const {
getNamePrefixedWithSchemaName,
wrapInQuotes,
getSchemaOfAlterCollection,
getFullCollectionName,
getEntityName,
isObjectInDeltaModelActivated,
} = require('../../../utils/general');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const getAddCompositePkScriptDtos = collection => {
}

const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema });
const entityName = getEntityName(collectionSchema);

const isContainerActivated = isParentContainerActivated(collection);
Expand Down Expand Up @@ -198,7 +198,7 @@ const getDropCompositePkScriptDtos = collection => {
}

const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema });

const isContainerActivated = isParentContainerActivated(collection);
const isCollectionActivated = isContainerActivated && isObjectInDeltaModelActivated(collection);
Expand Down Expand Up @@ -367,7 +367,7 @@ const wasRegularPkModified = (columnJsonSchema, collection) => {

const getAddPkScriptDtos = collection => {
const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema });
const entityName = getEntityName(collectionSchema);

const isContainerActivated = isParentContainerActivated(collection);
Expand Down Expand Up @@ -397,7 +397,7 @@ const getAddPkScriptDtos = collection => {

const getDropPkScriptDto = collection => {
const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema });

const isContainerActivated = isParentContainerActivated(collection);
const isCollectionActivated = isContainerActivated && isObjectInDeltaModelActivated(collection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const getAddCompositeUniqueKeyScriptDtos = collection => {
}

const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema });
const entityName = getEntityName(collectionSchema);

const isContainerActivated = isParentContainerActivated(collection);
Expand Down Expand Up @@ -191,7 +191,7 @@ const getDropCompositeUniqueKeyScriptDtos = collection => {
}

const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema });
const entityName = getEntityName(collectionSchema);

const isContainerActivated = isParentContainerActivated(collection);
Expand Down Expand Up @@ -373,7 +373,7 @@ const wasRegularUniqueKeyModified = (columnJsonSchema, collection) => {

const getAddUniqueKeyScriptDtos = collection => {
const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema });
const entityName = getEntityName(collectionSchema);

const isContainerActivated = isParentContainerActivated(collection);
Expand Down Expand Up @@ -403,7 +403,7 @@ const getAddUniqueKeyScriptDtos = collection => {

const getDropUniqueKeyScriptDto = collection => {
const collectionSchema = getSchemaOfAlterCollection(collection);
const fullTableName = getFullCollectionName(collectionSchema);
const fullTableName = getFullCollectionName({ collectionSchema });
const entityName = getEntityName(collectionSchema);

const isContainerActivated = isParentContainerActivated(collection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const getUpsertCommentsScriptDto = view => {
const comment = description.new;

const viewSchema = getSchemaOfAlterCollection(view);
const viewName = getFullCollectionName(viewSchema);
const viewName = getFullCollectionName({
collectionSchema: viewSchema,
});

const isContainerActivated = isParentContainerActivated(view);
const isViewActivated = isContainerActivated && isObjectInDeltaModelActivated(view);
Expand All @@ -37,7 +39,9 @@ const getDropCommentsScriptDto = view => {

if (description.old && !description.new) {
const viewSchema = getSchemaOfAlterCollection(view);
const viewName = getFullCollectionName(viewSchema);
const viewName = getFullCollectionName({
collectionSchema: viewSchema,
});

const isContainerActivated = isParentContainerActivated(view);
const isViewActivated = isContainerActivated && isObjectInDeltaModelActivated(view);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ const createView = ({ ddlProvider, mapProperties, view }) => {
* @returns {string}
*/
const dropView = ({ ddlProvider, viewSchema }) => {
const viewName = getFullCollectionName(viewSchema);
const viewName = getFullCollectionName({
collectionSchema: viewSchema,
});

return ddlProvider.dropView({ viewName });
};
Expand Down
15 changes: 13 additions & 2 deletions forward_engineering/utils/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ const getColumnsList = (columns, isAllColumnsDeactivated, isParentActivated, map
*/
const toArray = ({ value }) => (Array.isArray(value) ? value : [value]);

const getAlterEntityName = entityData => {
return entityData?.compMod?.collectionName?.new;
};

const getEntityName = entityData => {
return entityData?.code || entityData?.collectionName || entityData?.name || '';
};
Expand All @@ -126,8 +130,15 @@ const getSchemaNameFromCollection = ({ collection }) => {
return collection.compMod?.keyspaceName;
};

const getFullCollectionName = collectionSchema => {
const name = getEntityName(collectionSchema);
const getFullCollectionName = ({ collectionSchema, preferAlterName = true }) => {
let name = '';

if (preferAlterName) {
name = getAlterEntityName(collectionSchema);
}

name = name || getEntityName(collectionSchema);

const schemaName = getSchemaNameFromCollection({ collection: collectionSchema });
return getNamePrefixedWithSchemaName({ name, schemaName });
};
Expand Down