File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed
reverse_engineering/helpers Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change 1+ const reorganizePrimaryKeys = ( attributes , entityLevel ) => {
2+ if ( entityLevel . primaryKey ?. [ 0 ] ?. compositePrimaryKey ?. length !== 1 ) {
3+ return { attributes, entityLevel } ;
4+ }
5+
6+ const primaryKey = entityLevel . primaryKey [ 0 ] ;
7+ const primaryKeyAttributeName = primaryKey . compositePrimaryKey [ 0 ] ;
8+ const attributesWithPk = attributes . map ( attribute => {
9+ if ( attribute . name !== primaryKeyAttributeName ) {
10+ return attribute ;
11+ }
12+
13+ return setPrimaryKeyData ( attribute , primaryKey ) ;
14+ } ) ;
15+
16+ const filteredEntityLevel = { ...entityLevel , primaryKey : [ ] } ;
17+
18+ return { attributes : attributesWithPk , entityLevel : filteredEntityLevel } ;
19+ } ;
20+
21+ const setPrimaryKeyData = ( attribute , primaryKey ) => {
22+ return {
23+ ...attribute ,
24+ primaryKey : true ,
25+ primaryKeyOptions : [
26+ {
27+ constraintName : primaryKey . constraintName ,
28+ indexInclude : primaryKey . include ,
29+ indexStorageParameters : primaryKey . indexStorageParameters ,
30+ indexTablespace : primaryKey . indexTablespace ,
31+ indexComment : primaryKey . indexComment ,
32+ } ,
33+ ] ,
34+ } ;
35+ } ;
36+
37+ module . exports = { reorganizePrimaryKeys } ;
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ const {
4545} = require ( './postgresHelpers/viewHelper' ) ;
4646const { setDependencies : setDependenciesInTriggerHelper , getTriggers } = require ( './postgresHelpers/triggerHelper' ) ;
4747const queryConstants = require ( './queryConstants' ) ;
48+ const { reorganizePrimaryKeys } = require ( './postgresHelpers/reorganizePrimaryKeys' ) ;
4849
4950let currentSshTunnel = null ;
5051let _ = null ;
@@ -304,10 +305,12 @@ module.exports = {
304305 targetAttributes = setSubtypeFromSampledJsonValues ( targetAttributes , documents ) ;
305306 }
306307
308+ const { attributes, entityLevel : updatedEntityLevel } = reorganizePrimaryKeys ( targetAttributes , entityLevel ) ;
309+
307310 return {
308311 name : tableName ,
309- entityLevel,
310- jsonSchema : getJsonSchema ( targetAttributes ) ,
312+ entityLevel : updatedEntityLevel ,
313+ jsonSchema : getJsonSchema ( attributes ) ,
311314 documents,
312315 relationships,
313316 } ;
You can’t perform that action at this time.
0 commit comments