Skip to content
Open
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 @@ -132,6 +132,7 @@ const sortCollectionsByRelationships = (collections, relationships) => {
* internalDefinitions: InternalDefinitions,
* externalDefinitions: ExternalDefinitions,
* shouldIgnoreColumnComments?: boolean,
* shouldIgnoreTableComments?: boolean,
* }}
* @return {AlterScriptDto[]}
* */
Expand All @@ -144,6 +145,7 @@ const getAlterCollectionsScriptDtos = ({
externalDefinitions,
inlineDeltaRelationships,
shouldIgnoreColumnComments = false,
shouldIgnoreTableComments = false,
}) => {
const entitiesData = collection.properties?.entities?.properties;
const createScriptsData = getItemProperties(entitiesData?.added);
Expand All @@ -168,7 +170,9 @@ const getAlterCollectionsScriptDtos = ({
.filter(collection => collection.compMod?.deleted)
.map(getDeleteCollectionScriptDto(app));

const modifyCollectionScriptDtos = modifyScriptsData.flatMap(getModifyCollectionScriptDtos({ dbVersion }));
const modifyCollectionScriptDtos = modifyScriptsData.flatMap(
getModifyCollectionScriptDtos({ dbVersion, shouldIgnoreTableComments }),
);
const modifyCollectionKeysScriptDtos = modifyScriptsData.flatMap(getModifyCollectionKeysScriptDtos({ dbVersion }));

const addColumnScriptDtos = createScriptsData
Expand Down Expand Up @@ -400,6 +404,8 @@ const getAlterScriptDtos = (data, app) => {
const inlineDeltaRelationships = getInlineRelationships({ collection, options: data.options });
const shouldIgnoreColumnComments =
data.options?.scriptGenerationOptions?.feActiveOptions?.columnComments === 'ignore';
const shouldIgnoreTableComments =
data.options?.scriptGenerationOptions?.feActiveOptions?.tableComments === 'ignore';
const containersScriptDtos = getAlterContainersScriptDtos({ collection });
const collectionsScriptDtos = getAlterCollectionsScriptDtos({
collection,
Expand All @@ -410,6 +416,7 @@ const getAlterScriptDtos = (data, app) => {
externalDefinitions,
inlineDeltaRelationships,
shouldIgnoreColumnComments,
shouldIgnoreTableComments,
});
const viewScriptDtos = getAlterViewScriptDtos(collection, app);
const modelDefinitionsScriptDtos = getAlterModelDefinitionsScriptDtos({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,13 @@ const getDeleteCollectionScriptDto = app => collection => {
* @return {(collection: AlterCollectionDto) => AlterScriptDto[]}
* */
const getModifyCollectionScriptDtos =
({ dbVersion }) =>
({ dbVersion, shouldIgnoreTableComments = false }) =>
collection => {
const modifyCheckConstraintScriptDtos = getModifyCheckConstraintScriptDtos(collection);
const modifyCommentScriptDtos = getModifyEntityCommentsScriptDtos(collection);
const modifyCommentScriptDtos = getModifyEntityCommentsScriptDtos({
collection,
shouldIgnoreTableComments,
});
return [...modifyCheckConstraintScriptDtos, ...modifyCommentScriptDtos].filter(Boolean);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,26 @@ const updateTableComment = (tableName, comment) => {
};

/**
* @param {AlterCollectionDto} collection
* @param {{ collection: AlterCollectionDto, shouldIgnoreTableComments?: boolean }} dto
* @return {AlterScriptDto}
*/
const getUpdatedCommentOnCollectionScriptDto = collection => {
const descriptionInfo = collection?.role.compMod?.description;
if (!descriptionInfo) {
const getUpdatedCommentOnCollectionScriptDto = ({ collection, shouldIgnoreTableComments = false } = {}) => {
if (shouldIgnoreTableComments) {
return undefined;
}

const { old: oldComment, new: newComment } = descriptionInfo;
const outerDescription = collection?.role.compMod?.description;
if (!outerDescription) {
return undefined;
}

const firstCompareDescription = collection?.role.role?.compMod?.description;
if (collection?.role.role && firstCompareDescription == null) {
return undefined;
}

const oldComment = firstCompareDescription?.old ?? outerDescription.old;
const newComment = outerDescription.new ?? firstCompareDescription?.new;
if (!newComment || newComment === oldComment) {
return undefined;
}
Expand Down Expand Up @@ -62,10 +72,14 @@ const dropTableComment = tableName => {
};

/**
* @param {AlterCollectionDto} collection
* @param {{ collection: AlterCollectionDto, shouldIgnoreTableComments?: boolean }} dto
* @return {AlterScriptDto}
*/
const getDeletedCommentOnCollectionScriptDto = collection => {
const getDeletedCommentOnCollectionScriptDto = ({ collection, shouldIgnoreTableComments = false } = {}) => {
if (shouldIgnoreTableComments) {
return undefined;
}

const descriptionInfo = collection?.role.compMod?.description;
if (!descriptionInfo) {
return undefined;
Expand All @@ -86,12 +100,18 @@ const getDeletedCommentOnCollectionScriptDto = collection => {
};

/**
* @param {AlterCollectionDto} collection
* @param {{ collection: AlterCollectionDto, shouldIgnoreTableComments?: boolean }} dto
* @return {Array<AlterScriptDto>}
* */
const getModifyEntityCommentsScriptDtos = collection => {
const updatedCommentScript = getUpdatedCommentOnCollectionScriptDto(collection);
const deletedCommentScript = getDeletedCommentOnCollectionScriptDto(collection);
*/
const getModifyEntityCommentsScriptDtos = ({ collection, shouldIgnoreTableComments = false } = {}) => {
const updatedCommentScript = getUpdatedCommentOnCollectionScriptDto({
collection,
shouldIgnoreTableComments,
});
const deletedCommentScript = getDeletedCommentOnCollectionScriptDto({
collection,
shouldIgnoreTableComments,
});

return [updatedCommentScript, deletedCommentScript].filter(Boolean);
};
Expand Down
Loading