Skip to content

Commit

Permalink
HCK-9173: comment out inactive schema statement in script (#125)
Browse files Browse the repository at this point in the history
* HCK-9173: comment out inactive schema statement in script

* fix: comment out if isActivated is not FALSE

* fix undefined
  • Loading branch information
AlikRakhmonov authored Dec 19, 2024
1 parent 536c12e commit 84708a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions forward_engineering/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = (baseProvider, options, app) => {
const terminator = getTerminator(options);

return {
createSchema({ schemaName, databaseName, ifNotExist, comment }) {
createSchema({ schemaName, databaseName, ifNotExist, comment, isActivated = true }) {
const schemaTerminator = ifNotExist ? ';' : terminator;

const schemaComment = comment
Expand All @@ -56,11 +56,14 @@ module.exports = (baseProvider, options, app) => {
})
: '';

let schemaStatement = assignTemplates(templates.createSchema, {
name: schemaName,
terminator: schemaTerminator,
comment: schemaComment ? `\n\n${schemaComment}` : '',
});
let schemaStatement = commentIfDeactivated(
assignTemplates(templates.createSchema, {
name: schemaName,
terminator: schemaTerminator,
comment: schemaComment ? `\n\n${schemaComment}` : '',
}),
{ isActivated },
);

if (!databaseName) {
return ifNotExist
Expand Down Expand Up @@ -500,6 +503,7 @@ module.exports = (baseProvider, options, app) => {
databaseName: containerData.databaseName,
ifNotExist: containerData.ifNotExist,
comment: containerData.role?.description ?? containerData.description,
isActivated: containerData.isActivated,
};
},

Expand Down
2 changes: 1 addition & 1 deletion forward_engineering/helpers/commentIfDeactivated.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const BEFORE_DEACTIVATED_STATEMENT = '-- ';
const REG_FOR_MULTYLINE_COMMENT = /(\n\/\*\n[\s\S]*?\n\s\*\/\n)|((\n\/\*\n[\s\S]*?\n\s\*\/)$)/gi;

const commentIfDeactivated = (statement, data, isPartOfLine) => {
if (data?.hasOwnProperty('isActivated') && !data.isActivated) {
if (data.isActivated === false) {
if (isPartOfLine) {
return '/* ' + statement + ' */';
} else if (statement.includes('\n')) {
Expand Down

0 comments on commit 84708a9

Please sign in to comment.