Repository: jhipster/generator-jhipster (ts)

Issue:
Feature Request: Add 'skip-liquibase' flag to 'import-jdl'
##### **Overview of the feature request**

When re-importing a JDL file, jhipster updates the xml files with the updated entities, but after the project has been already deployed those files should not be updated but new changelogs should be generated with `liquibase:diff`.

##### **Motivation for or Use Case**

It would be really helpful for projects that have been already deployed to production to avoid liquibase, specially if using the `--interactive` flag.

##### **Related issues or PR**

No similar feature available

-   [x] Checking this box is mandatory (this is just to show you read everything)

https://opencollective.com/generator-jhipster/donate


Pull request:
Add ability to skip database changelog generation
Both from `jhipster import-jdl` or from `jhipster entity`

I used `--skip-db-changelog` since it's a bit more generic than `--skip-liquibase` and we also support database changelog for Cassandra without using Liquibase

Fixes #10059

-   Please make sure the below checklist is followed for Pull Requests.

-   [x] [Travis tests](https://travis-ci.org/jhipster/generator-jhipster/pull_requests) are green
-   [x] Tests are added where necessary
-   [ ] Documentation is added/updated where necessary
-   [x] Coding Rules & Commit Guidelines as per our [CONTRIBUTING.md document](https://github.com/jhipster/generator-jhipster/blob/master/CONTRIBUTING.md) are followed

<!--
Please also reference the issue number in a commit message to [automatically close the related Github issue](https://help.github.com/articles/closing-issues-via-commit-messages/)

Note: It is also possible to add `[skip ci]` to your commit message to skip Travis tests
-->


Patch:
diff --git a/cli/commands.js b/cli/commands.js
index 4a36835e96..28e884ee89 100644
--- a/cli/commands.js
+++ b/cli/commands.js
@@ -99,6 +99,7 @@ const defaultCommands = {
     --ignore-application  # Ignores application generation                                         Default: false
     --ignore-deployments  # Ignores deployments generation                                         Default: false
     --skip-ui-grouping    # Disable the UI grouping behavior for entity client side code           Default: false
+    --skip-db-changelog   # Disable generation of database changelogs                              Default: false
     --inline              # Pass JDL content inline. Argument can be skipped when passing this
 
 Arguments:
diff --git a/cli/import-jdl.js b/cli/import-jdl.js
index 99c4c8d488..ec00849527 100644
--- a/cli/import-jdl.js
+++ b/cli/import-jdl.js
@@ -190,6 +190,7 @@ const generateEntityFiles = (generator, entity, inFolder, env, shouldTriggerInst
         'skip-server': entity.skipServer,
         'no-fluent-methods': entity.noFluentMethod,
         'skip-user-management': entity.skipUserManagement,
+        'skip-db-changelog': generator.options['skip-db-changelog'],
         'skip-ui-grouping': generator.options['skip-ui-grouping']
     };
     const command = `${CLI_NAME}:entity ${entity.name}`;
diff --git a/generators/client/templates/angular/src/main/webapp/app/shared/login/login.component.ts.ejs b/generators/client/templates/angular/src/main/webapp/app/shared/login/login.component.ts.ejs
index 75a4f27cbb..36a50391bf 100644
--- a/generators/client/templates/angular/src/main/webapp/app/shared/login/login.component.ts.ejs
+++ b/generators/client/templates/angular/src/main/webapp/app/shared/login/login.component.ts.ejs
@@ -71,7 +71,7 @@ export class <%=jhiPrefixCapitalized%>LoginModalComponent implements AfterViewIn
         }).then(() => {
             this.authenticationError = false;
             this.activeModal.dismiss('login success');
-            if (this.router.url === '/account/register' || this.router.url.startsWith('/account/activate') ||
+            if (this.router.url === '/account/register' || this.router.url.startsWith('/account/activate/') ||
 this.router.url.startsWith('/account/reset/')) {
                 this.router.navigate(['']);
             }
diff --git a/generators/entity-server/files.js b/generators/entity-server/files.js
index ca1b1c2269..a8d8e73559 100644
--- a/generators/entity-server/files.js
+++ b/generators/entity-server/files.js
@@ -41,7 +41,7 @@ faker.seed(42);
 const serverFiles = {
     db: [
         {
-            condition: generator => generator.databaseType === 'sql',
+            condition: generator => generator.databaseType === 'sql' && !generator.skipDbChangelog,
             path: SERVER_MAIN_RES_DIR,
             templates: [
                 {
@@ -65,6 +65,7 @@ const serverFiles = {
         {
             condition: generator =>
                 generator.databaseType === 'sql' &&
+                !generator.skipDbChangelog &&
                 (generator.fieldsContainOwnerManyToMany || generator.fieldsContainOwnerOneToOne || generator.fieldsContainManyToOne),
             path: SERVER_MAIN_RES_DIR,
             templates: [
@@ -78,17 +79,20 @@ const serverFiles = {
         },
         {
             condition: generator =>
-                generator.databaseType === 'sql' && (generator.fieldsContainImageBlob === true || generator.fieldsContainBlob === true),
+                generator.databaseType === 'sql' &&
+                !generator.skipDbChangelog &&
+                (generator.fieldsContainImageBlob === true || generator.fieldsContainBlob === true),
             path: SERVER_MAIN_RES_DIR,
             templates: [{ file: 'config/liquibase/fake-data/blob/hipster.png', method: 'copy', noEjs: true }]
         },
         {
-            condition: generator => generator.databaseType === 'sql' && generator.fieldsContainTextBlob === true,
+            condition: generator =>
+                generator.databaseType === 'sql' && !generator.skipDbChangelog && generator.fieldsContainTextBlob === true,
             path: SERVER_MAIN_RES_DIR,
             templates: [{ file: 'config/liquibase/fake-data/blob/hipster.txt', method: 'copy' }]
         },
         {
-            condition: generator => generator.databaseType === 'cassandra',
+            condition: generator => generator.databaseType === 'cassandra' && !generator.skipDbChangelog,
             path: SERVER_MAIN_RES_DIR,
             templates: [
                 {
diff --git a/generators/entity-server/templates/src/main/resources/config/liquibase/fake-data/table.csv.ejs b/generators/entity-server/templates/src/main/resources/config/liquibase/fake-data/table.csv.ejs
index 4b0fa9e81a..9c6790fd09 100644
--- a/generators/entity-server/templates/src/main/resources/config/liquibase/fake-data/table.csv.ejs
+++ b/generators/entity-server/templates/src/main/resources/config/liquibase/fake-data/table.csv.ejs
@@ -153,9 +153,7 @@ for (lineNb = 1; lineNb <= numberOfRows; lineNb++) {
         // Validation rules
         if (fields[idx].fieldValidate === true) {
             if (fields[idx].fieldValidateRules.includes('pattern')) {
-                const randExp = new this.randexp(fields[idx].fieldValidateRulesPattern)
-                randExp.max = 5;
-                data = `"${randExp.gen().replace(/"/g, '""')}"`;
+                data = `"${new this.randexp(fields[idx].fieldValidateRulesPattern).gen()}"`;
             }
 
             // manage String max length
diff --git a/generators/entity/index.js b/generators/entity/index.js
index 974f3f0f65..1426c7f75c 100644
--- a/generators/entity/index.js
+++ b/generators/entity/index.js
@@ -106,6 +106,13 @@ class EntityGenerator extends BaseBlueprintGenerator {
             defaults: false
         });
 
+        // This adds support for a `--skip-db-changelog` flag
+        this.option('skip-db-changelog', {
+            desc: 'Skip the generation of database changelog (liquibase for sql databases)',
+            type: Boolean,
+            defaults: false
+        });
+
         // This adds support for a `--db` flag
         this.option('db', {
             desc: 'Provide DB option for the application when using skip-server flag',
@@ -192,6 +199,7 @@ class EntityGenerator extends BaseBlueprintGenerator {
                 context.skipClient =
                     context.applicationType === 'microservice' || this.options['skip-client'] || configuration.get('skipClient');
                 context.skipServer = this.options['skip-server'] || configuration.get('skipServer');
+                context.skipDbChangelog = this.options['skip-db-changelog'] || configuration.get('skipDbChangelog');
 
                 context.angularAppName = this.getAngularAppName(context.baseName);
                 context.angularXAppName = this.getAngularXAppName(context.baseName);
diff --git a/generators/kubernetes/templates/deployment.yml.ejs b/generators/kubernetes/templates/deployment.yml.ejs
index 2861846419..cf7b898438 100644
--- a/generators/kubernetes/templates/deployment.yml.ejs
+++ b/generators/kubernetes/templates/deployment.yml.ejs
@@ -213,6 +213,6 @@ spec:
           failureThreshold: 6
         livenessProbe:
           httpGet:
-            path: <%= app.applicationType === 'microservice' && !app.serviceDiscoveryType ? `/services/${app.baseName.toLowerCase()}` : '' %>/management/info
+            path: <%= app.applicationType === 'microservice' && !app.serviceDiscoveryType ? `/services/${app.baseName.toLowerCase()}` : '' %>/management/health
             port: http
           initialDelaySeconds: 120


Test patch:
diff --git a/test/cli/import-jdl.spec.js b/test/cli/import-jdl.spec.js
index ad9ac64c33..f953768093 100644
--- a/test/cli/import-jdl.spec.js
+++ b/test/cli/import-jdl.spec.js
@@ -65,6 +65,7 @@ function testDocumentsRelationships() {
             'skip-install': true,
             'skip-server': undefined,
             'skip-ui-grouping': undefined,
+            'skip-db-changelog': undefined,
             'skip-user-management': undefined
         });
     });
@@ -138,6 +139,56 @@ describe('JHipster generator import jdl', () => {
         });
     });
 
+    describe('imports a JDL entity model from single file with --skip-db-changelog', () => {
+        beforeEach(done => {
+            testInTempDir(dir => {
+                fse.copySync(path.join(__dirname, '../templates/import-jdl'), dir);
+                importJdl(['jdl.jdl'], { 'skip-db-changelog': true, skipInstall: true }, env);
+                done();
+            });
+        });
+
+        it('creates entity json files', () => {
+            assert.file([
+                '.jhipster/Department.json',
+                '.jhipster/JobHistory.json',
+                '.jhipster/Job.json',
+                '.jhipster/Employee.json',
+                '.jhipster/Location.json',
+                '.jhipster/Task.json',
+                '.jhipster/Country.json',
+                '.jhipster/Region.json'
+            ]);
+        });
+        it('calls entity subgenerator', () => {
+            expect(subGenCallParams.count).to.equal(8);
+            expect(subGenCallParams.commands).to.eql([
+                'jhipster:entity Region',
+                'jhipster:entity Country',
+                'jhipster:entity Location',
+                'jhipster:entity Department',
+                'jhipster:entity Task',
+                'jhipster:entity Employee',
+                'jhipster:entity Job',
+                'jhipster:entity JobHistory'
+            ]);
+            expect(subGenCallParams.options[0]).to.eql({
+                regenerate: true,
+                force: false,
+                skipInstall: true,
+                'from-cli': true,
+                interactive: true,
+                'no-fluent-methods': undefined,
+                'skip-client': undefined,
+                'skip-install': true,
+                'skip-server': undefined,
+                'skip-ui-grouping': undefined,
+                'skip-db-changelog': true,
+                'skip-user-management': undefined
+            });
+        });
+    });
+
     describe('imports a JDL entity model from single file in interactive mode by default', () => {
         beforeEach(done => {
             testInTempDir(dir => {
@@ -181,6 +232,7 @@ describe('JHipster generator import jdl', () => {
                 'skip-install': true,
                 'skip-server': undefined,
                 'skip-ui-grouping': undefined,
+                'skip-db-changelog': undefined,
                 'skip-user-management': undefined
             });
         });
@@ -240,6 +292,7 @@ describe('JHipster generator import jdl', () => {
                 'skip-install': true,
                 'skip-server': undefined,
                 'skip-ui-grouping': undefined,
+                'skip-db-changelog': undefined,
                 'skip-user-management': undefined
             });
         });
@@ -272,6 +325,7 @@ describe('JHipster generator import jdl', () => {
                 'skip-install': true,
                 'skip-server': undefined,
                 'skip-ui-grouping': undefined,
+                'skip-db-changelog': undefined,
                 'skip-user-management': undefined
             });
         });
diff --git a/test/entity.spec.js b/test/entity.spec.js
index 5f445e3295..01b06c5121 100644
--- a/test/entity.spec.js
+++ b/test/entity.spec.js
@@ -621,6 +621,62 @@ describe('JHipster generator for entity', () => {
             });
         });
 
+        describe('with --skip-db-changelog', () => {
+            describe('SQL database', () => {
+                before(done => {
+                    helpers
+                        .run(require.resolve('../generators/entity'))
+                        .inTmpDir(dir => {
+                            fse.copySync(path.join(__dirname, '../test/templates/default-ng2'), dir);
+                            fse.copySync(
+                                path.join(__dirname, '../test/templates/export-jdl/.jhipster/Country.json'),
+                                path.join(dir, '.jhipster/Foo.json')
+                            );
+                        })
+                        .withArguments(['Foo'])
+                        .withOptions({ regenerate: true, force: true, skipDbChangelog: true })
+                        .on('end', done);
+                });
+
+                it('creates expected default files', () => {
+                    assert.file(expectedFiles.server);
+                    assert.file(expectedFiles.clientNg2);
+                    assert.file(expectedFiles.gatling);
+                });
+                it("doesn't creates database changelogs", () => {
+                    assert.noFile([
+                        `${constants.SERVER_MAIN_RES_DIR}config/liquibase/changelog/20160926101210_added_entity_Foo.xml`,
+                        `${constants.SERVER_MAIN_RES_DIR}config/liquibase/changelog/20160926101210_added_entity_constraints_Foo.xml`
+                    ]);
+                });
+            });
+
+            describe('Cassandra database', () => {
+                before(done => {
+                    helpers
+                        .run(require.resolve('../generators/entity'))
+                        .inTmpDir(dir => {
+                            fse.copySync(path.join(__dirname, '../test/templates/compose/05-cassandra'), dir);
+                            fse.copySync(
+                                path.join(__dirname, '../test/templates/export-jdl/.jhipster/Country.json'),
+                                path.join(dir, '.jhipster/Foo.json')
+                            );
+                        })
+                        .withArguments(['Foo'])
+                        .withOptions({ regenerate: true, force: true, skipDbChangelog: true })
+                        .on('end', done);
+                });
+
+                it('creates expected default files', () => {
+                    assert.file(expectedFiles.server);
+                    assert.file(expectedFiles.gatling);
+                });
+                it("doesn't creates database changelogs", () => {
+                    assert.noFile([`${constants.SERVER_MAIN_RES_DIR}config/cql/changelog/20160926101210_added_entity_Foo.cql`]);
+                });
+            });
+        });
+
         context('microservice', () => {
             describe('with dto, service, pagination', () => {
                 before(done => {