Skip to content

Commit 3cc10af

Browse files
Fix/hck 4637 unlogged and cache statements are not re d from th (#93)
* RE: fix reverse cache and unlogged options for sequences * FE: fix error when alter sequence min value is more than restart value * RE: fix value type for sequences numeric options * FE: move up position of restart sequence option
1 parent e216629 commit 3cc10af

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

forward_engineering/ddlProvider/ddlHelpers/sequenceHelper.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module.exports = ({
5858
sequenceName,
5959
sequenceSchemaName
6060
);
61-
const modifiedSequence = _.omitBy(sequence, (value, key) => _.isEqual(value, oldSequence[key]));
61+
const modifiedSequence = getModifiedSequence({ sequence, oldSequence });
6262
const options = getSequenceOptions({ schemaName, sequence: modifiedSequence });
6363
const sequenceType = getAlterSequenceType({ sequence: modifiedSequence });
6464
const newName = modifiedSequence.sequenceName;
@@ -102,6 +102,7 @@ module.exports = ({
102102
{ getOption, key: 'dataType', clause: 'AS', },
103103
{ getOption, key: 'increment', clause: 'INCREMENT BY', },
104104
{ getOption, key: 'start', clause: 'START WITH', },
105+
{ getOption, key: 'restart', clause: 'RESTART WITH', },
105106
{ getOption, key: 'minValue', clause: 'MINVALUE', },
106107
{ getOption, key: 'maxValue', clause: 'MAXVALUE', },
107108
{ getOption, key: 'cache', clause: 'CACHE', },
@@ -225,6 +226,23 @@ module.exports = ({
225226
return '';
226227
};
227228

229+
/**
230+
* @param {{ sequence: Sequence, oldSequence: Sequence }}
231+
* @returns {Sequence}
232+
*/
233+
const getModifiedSequence = ({ sequence, oldSequence }) => {
234+
const modifiedSequence = _.omitBy(sequence, (value, key) => _.isEqual(value, oldSequence[key]));
235+
236+
if (sequence.minValue > oldSequence.minValue) {
237+
return {
238+
...modifiedSequence,
239+
restart: sequence.start,
240+
};
241+
}
242+
243+
return modifiedSequence;
244+
};
245+
228246
return {
229247
getSequencesScript,
230248
createSequenceScript,

forward_engineering/types/schemaSequenceTypes.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ class SequenceDto {
101101
*/
102102
cycle_option
103103

104+
/**
105+
* @type {number}
106+
*/
107+
cache_size
108+
109+
/**
110+
* @type {'t' | 'u' | 'p' | null}
111+
*/
112+
rel_persistance
113+
104114
/**
105115
* @type {string | null}
106116
*/

reverse_engineering/helpers/postgresHelpers/sequenceHelper.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ const getOwnedByColumn = ({ sequence }) => {
1919
const mapSequenceData = ({ sequence }) => {
2020
return {
2121
sequenceName: sequence.sequence_name,
22-
increment: sequence.increment,
23-
start: sequence.start_value,
22+
increment: Number(sequence.increment),
23+
start: Number(sequence.start_value),
2424
dataType: sequence.data_type,
25-
maxValue: sequence.maximum_value,
26-
minValue: sequence.minimum_value,
25+
maxValue: Number(sequence.maximum_value),
26+
minValue: Number(sequence.minimum_value),
27+
cache: Number(sequence.cache_size),
28+
temporary: sequence.rel_persistance === 't',
29+
unlogged: sequence.rel_persistance === 'u',
2730
cycle: sequence.cycle_option === 'YES',
2831
ownedByColumn: getOwnedByColumn({ sequence }),
2932
ownedByNone: !sequence.column_name,

reverse_engineering/helpers/queryConstants.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,21 @@ const queryConstants = {
396396
WHERE inher_parent.relnamespace = $1;`,
397397
GET_SEQUENCES: `
398398
SELECT DISTINCT ON (sequence_name)
399-
sequence_name,
400-
data_type,
401-
start_value,
402-
minimum_value,
403-
maximum_value,
404-
"increment",
405-
cycle_option,
399+
information_schema."sequences".sequence_name,
400+
information_schema."sequences".data_type,
401+
information_schema."sequences".start_value,
402+
information_schema."sequences".minimum_value,
403+
information_schema."sequences".maximum_value,
404+
information_schema."sequences"."increment",
405+
information_schema."sequences".cycle_option,
406+
pg_catalog.pg_sequences.cache_size,
407+
pg_class.relpersistence as rel_persistance,
406408
inner_pg_class.relname AS table_name,
407409
pg_attribute.attname AS column_name
408410
FROM information_schema."sequences"
409411
JOIN pg_class ON pg_class.relname = information_schema."sequences".sequence_name
410412
JOIN pg_depend ON pg_depend.objid = pg_class.oid
413+
LEFT JOIN pg_catalog.pg_sequences ON (pg_catalog.pg_sequences.schemaname, pg_catalog.pg_sequences.sequencename) = (information_schema."sequences".sequence_schema, information_schema."sequences".sequence_name)
411414
LEFT JOIN pg_class AS inner_pg_class ON pg_depend.refobjid = inner_pg_class.oid
412415
LEFT JOIN pg_attribute ON (pg_depend.refobjid, pg_depend.refobjsubid) = (pg_attribute.attrelid, pg_attribute.attnum)
413416
WHERE pg_class.relkind = 'S'

0 commit comments

Comments
 (0)