File tree Expand file tree Collapse file tree 2 files changed +38
-6
lines changed Expand file tree Collapse file tree 2 files changed +38
-6
lines changed Original file line number Diff line number Diff line change 11const reApi = require ( '../reverse_engineering/api' ) ;
22const { createLogger } = require ( '../reverse_engineering/helpers/loggerHelper' ) ;
33const applyToInstanceHelper = require ( './applyToInstanceHelper' ) ;
4- const { commentDropStatements } = require ( './helpers/commentDropStatements' ) ;
5- const { DROP_STATEMENTS } = require ( './helpers/constants' ) ;
4+ const { commentDropStatements, doesScriptContainDropStatements} = require ( './helpers/commentDropStatements' ) ;
65
76module . exports = {
87 generateScript ( data , logger , callback , app ) {
@@ -105,7 +104,7 @@ module.exports = {
105104 const cb = ( error , script = '' ) =>
106105 callback (
107106 error ,
108- DROP_STATEMENTS . some ( statement => script . includes ( statement ) ) ,
107+ doesScriptContainDropStatements ( script ) ,
109108 ) ;
110109
111110 if ( data . level === 'container' ) {
Original file line number Diff line number Diff line change 11const { DROP_STATEMENTS } = require ( './constants' ) ;
22
3+ const isDropNotNullStatementRegex = / A L T E R T A B L E I F E X I S T S .+ A L T E R C O L U M N .+ D R O P N O T N U L L ; / ;
4+
5+ const isDropConstraintStatementRegex = / A L T E R T A B L E I F E X I S T S .+ D R O P C O N S T R A I N T I F E X I S T S .+ ; / ;
6+
7+ const dropCommentRegex = / C O M M E N T O N ( T A B L E | S C H E M A | V I E W | C O L U M N ) .+ I S N U L L ; / ;
8+
9+ /**
10+ * @param scriptLine {string}
11+ * @return {boolean }
12+ * */
13+ const shouldStatementBeCommentedOut = ( scriptLine ) => {
14+ const doesContainDropStatements = DROP_STATEMENTS . some ( statement => scriptLine . includes ( statement ) ) ;
15+ if ( doesContainDropStatements ) {
16+ return true ;
17+ }
18+
19+ return [
20+ isDropNotNullStatementRegex ,
21+ isDropConstraintStatementRegex ,
22+ dropCommentRegex ,
23+ ] . some ( regex => regex . test ( scriptLine ) ) ;
24+ }
25+
26+ /**
27+ * @param script {string}
28+ * @return {boolean }
29+ * */
30+ const doesScriptContainDropStatements = ( script ) => {
31+ return script . split ( '\n' )
32+ . some ( shouldStatementBeCommentedOut ) ;
33+ }
34+
35+
336const commentDropStatements = ( script = '' ) =>
437 script
538 . split ( '\n' )
639 . map ( line => {
7- if ( DROP_STATEMENTS . some ( statement => line . includes ( statement ) ) ) {
40+ if ( shouldStatementBeCommentedOut ( line ) ) {
841 return `-- ${ line } ` ;
9- } else {
10- return line ;
1142 }
43+ return line ;
1244 } )
1345 . join ( '\n' ) ;
1446
1547module . exports = {
1648 commentDropStatements,
49+ doesScriptContainDropStatements,
1750} ;
You can’t perform that action at this time.
0 commit comments