-
Notifications
You must be signed in to change notification settings - Fork 10
Feature/hck 4561 bbva sequences definition for postgresql re and #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
serhii-filonenko
merged 7 commits into
main
from
Feature/HCK-4561--bbva-sequences-definition-for-postgresql-re-and
Feb 22, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e79ea5e
container-level-config: add sequences tab
serhii-filonenko eb04eb3
RE: add generating script for sequences
serhii-filonenko a3169ce
container-level-config: add owner field limit for sequence
serhii-filonenko b5fe17f
RE: remove redundant formatting for sequence options
serhii-filonenko ac9d3fa
container-level-config: fix default value for sequence cycle property
serhii-filonenko d7c9ee6
RE: fix getting options for sequence statement
serhii-filonenko 1345f30
RE: fix missed arguments wrapping
serhii-filonenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
174 changes: 174 additions & 0 deletions
174
forward_engineering/ddlProvider/ddlHelpers/sequenceHelper.js
This file contains hidden or 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,174 @@ | ||
| /** | ||
| * @typedef {'bigint' | 'integer' | 'smallint'} DataType | ||
| * | ||
| * @typedef {{ | ||
| * cache?: number; | ||
| * cycle: boolean; | ||
| * dataType: DataType; | ||
| * ifNotExist: boolean; | ||
| * increment?: number; | ||
| * maxValue?: number; | ||
| * minValue?: number; | ||
| * ownedByColumn: object[]; | ||
| * ownedByNone: boolean; | ||
| * sequenceName: string; | ||
| * start?: number; | ||
| * temporary: boolean; | ||
| * unlogged: boolean; | ||
| * }} Sequence | ||
| * | ||
| * @typedef {{ | ||
| * key: keyof Sequence; | ||
| * clause: string; | ||
| * getOption: ({ sequence: Sequence, config: OptionConfig }) => {} | ||
| * }} OptionConfig | ||
| */ | ||
|
|
||
| module.exports = ({ | ||
| _, | ||
| templates, | ||
| assignTemplates, | ||
| getNamePrefixedWithSchemaName, | ||
| }) => { | ||
| /** | ||
| * @param {string} schemaName | ||
| * @param {Sequence[]} sequences | ||
| * @returns {string} | ||
| */ | ||
| const getSequencesScript = (schemaName, sequences) => { | ||
| return _.map(sequences, (sequence) => { | ||
| const name = getNamePrefixedWithSchemaName( | ||
| sequence.sequenceName, | ||
| schemaName | ||
| ); | ||
| const ifNotExists = getIfNotExists(sequence); | ||
| const sequenceType = getSequenceType(sequence); | ||
| const options = getSequenceOptions(sequence); | ||
| return assignTemplates(templates.createSequence, { | ||
| name, | ||
| ifNotExists, | ||
| sequenceType, | ||
| options, | ||
| }); | ||
| }).join('\n'); | ||
| }; | ||
|
|
||
| /** | ||
| * @param {Sequence} sequence | ||
| * @returns {string} | ||
| */ | ||
| const getSequenceOptions = (sequence) => { | ||
| /** | ||
| * @type {Array<OptionConfig>} | ||
| */ | ||
| const optionConfigs = [ | ||
| { getOption, key: 'dataType', clause: 'AS', }, | ||
| { getOption, key: 'increment', clause: 'INCREMENT', }, | ||
| { getOption, key: 'start', clause: 'START WITH', }, | ||
| { getOption, key: 'minValue', clause: 'MINVALUE', }, | ||
| { getOption, key: 'maxValue', clause: 'MAXVALUE', }, | ||
| { getOption, key: 'cache', clause: 'CACHE', }, | ||
| { getOption: getCycle, key: 'cycle' }, | ||
| { getOption: getOwnedBy, key: 'ownedByColumn' }, | ||
| ]; | ||
|
|
||
| const options = optionConfigs | ||
| .map((config) => wrapOption(config.getOption({ sequence, config }))) | ||
| .filter(Boolean) | ||
| .join(''); | ||
|
|
||
| return options ? wrapOptionsBlock(options) : options; | ||
| }; | ||
|
|
||
| /** | ||
| * @param {{ sequence: Sequence; config: OptionConfig }} param0 | ||
| * @returns {string} | ||
| */ | ||
| const getOption = ({ sequence, config }) => { | ||
| const value = sequence[config.key]; | ||
| return value || value === 0 ? `${config.clause} ${value}` : ''; | ||
serhii-filonenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| /** | ||
| * @param {string} option | ||
| * @returns {string} | ||
| */ | ||
| const wrapOption = (option) => { | ||
| return option ? `\t${option}\n` : ''; | ||
| }; | ||
|
|
||
| /** | ||
| * @param {string} option | ||
| * @returns {string} | ||
| */ | ||
| const wrapOptionsBlock = (option) => { | ||
| return '\n' + option.replace(/\n$/, ''); | ||
| }; | ||
|
|
||
| /** | ||
| * @param {Sequence} sequence | ||
| * @returns {string} | ||
| */ | ||
| const getIfNotExists = (sequence) => { | ||
| return sequence.ifNotExist ? ' IF NOT EXISTS' : ''; | ||
| }; | ||
|
|
||
| /** | ||
| * @param {Sequence} sequence | ||
| * @returns {string} | ||
| */ | ||
| const getSequenceType = (sequence) => { | ||
| if (sequence.temporary) { | ||
| return ' TEMPORARY'; | ||
| } | ||
|
|
||
| if (sequence.unlogged) { | ||
| return ' UNLOGGED'; | ||
| } | ||
|
|
||
| return ''; | ||
| }; | ||
|
|
||
| /** | ||
| * @param {{ sequence: Sequence }} param0 | ||
| * @returns {string} | ||
| */ | ||
| const getCycle = ({ sequence }) => { | ||
| if (sequence.cycle === true) { | ||
chulanovskyi-bs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return 'CYCLE'; | ||
| } | ||
|
|
||
| if (sequence.cycle === false) { | ||
| return 'NO CYCLE'; | ||
| } | ||
|
|
||
| return ''; | ||
| }; | ||
|
|
||
| /** | ||
| * @param {{ sequence: Sequence }} param0 | ||
| * @returns {string} | ||
| */ | ||
| const getOwnedBy = ({ sequence }) => { | ||
| if (sequence.ownedByNone) { | ||
| return 'OWNED BY NONE'; | ||
| } | ||
|
|
||
| const ownedColumn = sequence.ownedByColumn?.[0]; | ||
chulanovskyi-bs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (ownedColumn) { | ||
| const [tableName, columnName] = ownedColumn.name?.split('.') || []; | ||
| const ownedColumnName = getNamePrefixedWithSchemaName( | ||
| columnName, | ||
| tableName | ||
| ); | ||
| return `OWNED BY ${ownedColumnName}`; | ||
| } | ||
|
|
||
| return ''; | ||
| }; | ||
|
|
||
| return { | ||
| getSequencesScript, | ||
| }; | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.