@@ -58,47 +58,70 @@ const getDefaultConstraintName = (wrapInQuotes) => (entityName) => {
5858 * @return {(collection: AlterCollectionDto) => Array<AlterScriptDto> }
5959 * */
6060const getAddCompositePkScripts = ( _ , ddlProvider ) => ( collection ) => {
61- const didPkChange = didCompositePkChange ( _ ) ( collection ) ;
62- if ( ! didPkChange ) {
63- return [ ]
64- }
65- const fullTableName = generateFullEntityName ( collection ) ;
66- const constraintName = getEntityNameFromCollection ( collection ) + '_pk' ;
67- const pkDto = collection ?. role ?. compMod ?. primaryKey || { } ;
68- const newPrimaryKeys = pkDto . new || [ ] ;
61+ // const didPkChange = didCompositePkChange(_)(collection);
62+ // if (!didPkChange) {
63+ // return []
64+ // }
65+ // const fullTableName = generateFullEntityName(collection);
66+ // const constraintName = getEntityNameFromCollection(collection) + '_pk';
67+ // const pkDto = collection?.role?.compMod?.primaryKey || {};
68+ // const newPrimaryKeys = pkDto.new || [];
69+ //
70+ // return newPrimaryKeys
71+ // .map((newPk) => {
72+ // /**
73+ // * @type {Array<AlterCollectionRoleCompModPKDto> }
74+ // * */
75+ // const compositePrimaryKey = newPk.compositePrimaryKey || [];
76+ // const guidsOfColumnsInPk = compositePrimaryKey.map((compositePkEntry) => compositePkEntry.keyId);
77+ // const columnsInPk = getPropertiesByGuids(_)(collection, guidsOfColumnsInPk);
78+ // const columnNamesForDDL = columnsInPk.map(column => prepareName(column.compMod.newField.name));
79+ // if (!columnNamesForDDL.length) {
80+ // return undefined;
81+ // }
82+ // return ddlProvider.addPkConstraint(fullTableName, constraintName, columnNamesForDDL);
83+ // })
84+ // .filter(Boolean)
85+ // .map(scriptLine => AlterScriptDto.getInstance([scriptLine], collection.isActivated, false))
86+ // .filter(Boolean);
6987
70- return newPrimaryKeys
71- . map ( ( newPk ) => {
72- /**
73- * @type {Array<AlterCollectionRoleCompModPKDto> }
74- * */
75- const compositePrimaryKey = newPk . compositePrimaryKey || [ ] ;
76- const guidsOfColumnsInPk = compositePrimaryKey . map ( ( compositePkEntry ) => compositePkEntry . keyId ) ;
77- const columnsInPk = getPropertiesByGuids ( _ ) ( collection , guidsOfColumnsInPk ) ;
78- const columnNamesForDDL = columnsInPk . map ( column => prepareName ( column . compMod . newField . name ) ) ;
79- if ( ! columnNamesForDDL . length ) {
80- return undefined ;
81- }
82- return ddlProvider . addPkConstraint ( fullTableName , constraintName , columnNamesForDDL ) ;
83- } )
84- . filter ( Boolean )
85- . map ( scriptLine => AlterScriptDto . getInstance ( [ scriptLine ] , collection . isActivated , false ) )
86- . filter ( Boolean ) ;
88+ return [ ] ;
8789}
8890
8991/**
9092 * @return {(collection: AlterCollectionDto) => Array<AlterScriptDto> }
9193 * */
9294const getDropCompositePkScripts = ( _ , ddlProvider ) => ( collection ) => {
95+ const {
96+ getFullCollectionName,
97+ getSchemaOfAlterCollection,
98+ getEntityName,
99+ wrapInQuotes
100+ } = require ( '../../../utils/general' ) ( _ ) ;
101+
93102 const didPkChange = didCompositePkChange ( _ ) ( collection ) ;
94103 if ( ! didPkChange ) {
95- return [ ]
104+ return [ ] ;
96105 }
97- const fullTableName = generateFullEntityName ( collection ) ;
106+
107+ const collectionSchema = getSchemaOfAlterCollection ( collection ) ;
108+ const fullTableName = getFullCollectionName ( collectionSchema ) ;
109+ const entityName = getEntityName ( collectionSchema ) ;
110+
98111 const pkDto = collection ?. role ?. compMod ?. primaryKey || { } ;
112+ /**
113+ * @type {AlterCollectionRoleCompModPKDto[] }
114+ * */
99115 const oldPrimaryKeys = pkDto . old || [ ] ;
116+
100117 return oldPrimaryKeys
101- . map ( oldPk => ddlProvider . dropPkConstraint ( fullTableName ) )
118+ . map ( ( oldPk ) => {
119+ let constraintName = getDefaultConstraintName ( wrapInQuotes ) ( entityName ) ;
120+ if ( oldPk . constraintName ) {
121+ constraintName = wrapInQuotes ( oldPk . constraintName ) ;
122+ }
123+ return ddlProvider . dropPkConstraint ( fullTableName , constraintName ) ;
124+ } )
102125 . map ( scriptLine => AlterScriptDto . getInstance ( [ scriptLine ] , collection . isActivated , true ) )
103126 . filter ( Boolean ) ;
104127}
@@ -108,11 +131,11 @@ const getDropCompositePkScripts = (_, ddlProvider) => (collection) => {
108131 * */
109132const getModifyCompositePkScripts = ( _ , ddlProvider ) => ( collection ) => {
110133 const dropCompositePkScripts = getDropCompositePkScripts ( _ , ddlProvider ) ( collection ) ;
111- const addCompositePkScripts = getAddCompositePkScripts ( _ , ddlProvider ) ( collection ) ;
134+ // const addCompositePkScripts = getAddCompositePkScripts(_, ddlProvider)(collection);
112135
113136 return [
114137 ...dropCompositePkScripts ,
115- ...addCompositePkScripts ,
138+ // ...addCompositePkScripts,
116139 ] . filter ( Boolean ) ;
117140}
118141
@@ -208,23 +231,23 @@ const getDropPkScript = (_, ddlProvider) => (collection) => {
208231 * */
209232const getModifyPkScripts = ( _ , ddlProvider ) => ( collection ) => {
210233 const dropPkScripts = getDropPkScript ( _ , ddlProvider ) ( collection ) ;
211- const addPkScripts = getAddPkScripts ( _ , ddlProvider ) ( collection ) ;
234+ // const addPkScripts = getAddPkScripts(_, ddlProvider)(collection);
212235
213236 return [
214237 ...dropPkScripts ,
215- ...addPkScripts ,
238+ // ...addPkScripts,
216239 ] . filter ( Boolean ) ;
217240}
218241
219242/**
220243 * @return {(collection: AlterCollectionDto) => Array<AlterScriptDto> }
221244 * */
222245const getModifyPkConstraintsScriptDtos = ( _ , ddlProvider ) => ( collection ) => {
223- // const modifyCompositePkScripts = getModifyCompositePkScripts(_, ddlProvider)(collection);
246+ const modifyCompositePkScripts = getModifyCompositePkScripts ( _ , ddlProvider ) ( collection ) ;
224247 const modifyPkScripts = getModifyPkScripts ( _ , ddlProvider ) ( collection ) ;
225248
226249 return [
227- // ...modifyCompositePkScripts,
250+ ...modifyCompositePkScripts ,
228251 ...modifyPkScripts ,
229252 ] . filter ( Boolean ) ;
230253}
0 commit comments