-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: added column DEFAULT prop handler * fix: drop DEFAULT statement params * fix: bump pg version * fix: adjusted statements with fail-safe check IF EXISTS * fix: handle _fasly_ values properly * fix: handle drop statement for empty values * fix: appropriately generate drop statement * chore: simplify
- Loading branch information
1 parent
76c6383
commit 4a60513
Showing
24 changed files
with
460 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
forward_engineering/alterScript/alterScriptHelpers/columnHelpers/defaultValueHelper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const { toPairs } = require('lodash'); | ||
const { AlterScriptDto } = require('../../types/AlterScriptDto'); | ||
const { getFullTableName, wrapInQuotes, wrapInSingleQuotes } = require('../../../utils/general'); | ||
|
||
/** | ||
* @param { ({ ddlProvider: Object, collection: Object }) } | ||
* @returns { Array<AlterScriptDto> } | ||
* */ | ||
const getUpdatedDefaultColumnValueScriptDtos = ({ ddlProvider, collection }) => | ||
toPairs(collection.properties) | ||
.filter(([_name, jsonSchema]) => { | ||
const newDefault = jsonSchema.default; | ||
const oldName = jsonSchema.compMod.oldField.name; | ||
const oldDefault = collection.role.properties[oldName]?.default; | ||
return newDefault !== undefined && (!oldDefault || newDefault !== oldDefault); | ||
}) | ||
.map(([columnName, jsonSchema]) => { | ||
const newDefaultValue = jsonSchema.default; | ||
const scriptGenerationConfig = { | ||
tableName: getFullTableName(collection), | ||
columnName: wrapInQuotes(columnName), | ||
defaultValue: wrapInSingleQuotes({ name: newDefaultValue }), | ||
}; | ||
return ddlProvider.updateColumnDefaultValue(scriptGenerationConfig); | ||
}) | ||
.map(script => AlterScriptDto.getInstance([script], true, false)) | ||
.filter(Boolean); | ||
|
||
/** | ||
* @param { ({ ddlProvider: Object, collection: Object }) } | ||
* @returns { Array<AlterScriptDto> } | ||
* */ | ||
const getDeletedDefaultColumnValueScriptDtos = ({ ddlProvider, collection }) => | ||
toPairs(collection.properties) | ||
.filter(([_name, jsonSchema]) => { | ||
const newDefault = jsonSchema.default; | ||
const oldName = jsonSchema.compMod.oldField.name; | ||
const oldDefault = collection.role.properties[oldName]?.default; | ||
const hasPrevValue = oldDefault !== undefined; | ||
const hasNewValue = newDefault !== undefined; | ||
return hasPrevValue && !hasNewValue; | ||
}) | ||
.map(([columnName]) => { | ||
const scriptGenerationConfig = { | ||
tableName: getFullTableName(collection), | ||
columnName: wrapInQuotes(columnName), | ||
}; | ||
return ddlProvider.dropColumnDefaultValue(scriptGenerationConfig); | ||
}) | ||
.map(script => AlterScriptDto.getInstance([script], true, true)) | ||
.filter(Boolean); | ||
|
||
/** | ||
* @param { ({ ddlProvider: Object, collection: Object }) } | ||
* @returns { Array<AlterScriptDto> } | ||
* */ | ||
const getModifiedDefaultColumnValueScriptDtos = ({ ddlProvider, collection }) => { | ||
const updatedDefaultValuesScriptDtos = getUpdatedDefaultColumnValueScriptDtos({ ddlProvider, collection }); | ||
const dropDefaultValuesScriptDtos = getDeletedDefaultColumnValueScriptDtos({ ddlProvider, collection }); | ||
return [...updatedDefaultValuesScriptDtos, ...dropDefaultValuesScriptDtos]; | ||
}; | ||
|
||
module.exports = { | ||
getModifiedDefaultColumnValueScriptDtos, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.