From 6efa1674273457338ece7cfab38c1ad27e5a88d8 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sat, 4 May 2019 13:59:12 +0200 Subject: [PATCH] adding Postgres configurations for dev-environment with sample-data --- README.md | 37 ++++++++++++++++--- gradle/profile_dev.gradle | 11 +++++- src/main/resources/config/application-dev.yml | 14 +------ .../resources/config/application-h2file.yml | 22 +++++++++++ .../resources/config/application-h2mem.yml | 22 +++++++++++ .../resources/config/application-pgsql.yml | 19 ++++++++++ .../config/liquibase/sample-data/assets.xml | 14 ++++++- .../liquibase/sample-data/customers.xml | 18 ++++++++- .../liquibase/sample-data/memberships.xml | 12 +++++- .../liquibase/sample-data/sepamandates.xml | 12 +++++- .../config/liquibase/sample-data/shares.xml | 12 +++++- 11 files changed, 168 insertions(+), 25 deletions(-) create mode 100644 src/main/resources/config/application-h2file.yml create mode 100644 src/main/resources/config/application-h2mem.yml create mode 100644 src/main/resources/config/application-pgsql.yml diff --git a/README.md b/README.md index 616276c9..3706ade7 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ -**Table of Contents** _generated with [DocToc](https://github.com/thlorenz/doctoc)_ - - [Setting up the Development Environment](#setting-up-the-development-environment) - [Frequent Tasks](#frequent-tasks) - [Building the Application with Test Execution](#building-the-application-with-test-execution) @@ -36,13 +34,42 @@ TODO: Instructions for setting up the dev environment from scratch. ### Starting the Application -Either simply: +To use an **H2 in-memory database** populated with sample-data. gw bootRun -or with a specific port: +To use an **H2 file-based database**, start the application with the h2file profile: - SERVER_PORT=8081 ./gradlew bootRun + gw bootRun -Ph2file + gw bootRun -Ph2file,sample-data # populated with sample data + +To use a **local Postgres database**, first prepare your environment: + + export HSADMINNG_DB_URL='jdbc:postgresql://localhost:5432/DBNAME' + export HSADMINNG_DB_USER='DBUSER' + export HSADMINNG_DB_PASS='DBPASS' + +Where `DBNAME`, `DBUSER` and `DBPASS` are replaced by your credentials. + +Then start the application with the pgsql profile: + + gw bootRun -Ppgsql + gw bootRun -Ppgsql,sample-data # populated with sample data + +To use a **remote Postgres database** on a hostsharing server, + + autossh -M 0 -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" \ + -f -N -L 55432:127.0.0.1:5432 "xyz00@xyz.hostsharing.net" + +Then prepare your environment, e.g. like this: + + export HSADMINNG_DB_URL='jdbc:postgresql://localhost:55432/xyz00_hsadminng' + export HSADMINNG_DB_USER='xyz00_hsadminng' + export HSADMINNG_DB_PASS='whatever' + +In all cases, you can also **specify the port** to used for the application via environment: + + SERVER_PORT=8081 gw bootRun ... ### Running JUnit tests with branch coverage diff --git a/gradle/profile_dev.gradle b/gradle/profile_dev.gradle index 096f2445..d19d8f37 100644 --- a/gradle/profile_dev.gradle +++ b/gradle/profile_dev.gradle @@ -8,7 +8,14 @@ dependencies { compile "com.h2database:h2" } -def profiles = 'dev' +def profiles = ""; +if (project.hasProperty('pgsql')) { + profiles += 'pgsql' +} else if (project.hasProperty('h2file')) { + profiles += 'h2file' +} else { + profiles += 'h2mem' +} if (project.hasProperty('no-liquibase')) { profiles += ',no-liquibase' } @@ -16,6 +23,8 @@ if (project.hasProperty('tls')) { profiles += ',tls' } +println 'activating profiles: ' + profiles + springBoot { buildInfo { properties { diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml index 8e53af01..2e045b77 100644 --- a/src/main/resources/config/application-dev.yml +++ b/src/main/resources/config/application-dev.yml @@ -36,22 +36,12 @@ spring: serialization: indent-output: true datasource: + # this is just a common configuration for the dev-profiles h2mem, h2file and pgsql type: com.zaxxer.hikari.HikariDataSource - # H2 in memory: - url: jdbc:h2:mem:hsadminng;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE - # H2 in file: - # url: jdbc:h2:~/.hsadminng.h2db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE - username: hsadminNg - password: hikari: poolName: Hikari auto-commit: false - h2: - console: - enabled: false jpa: - database-platform: io.github.jhipster.domain.util.FixedH2Dialect - database: H2 show-sql: true properties: hibernate.id.new_generator_mappings: true @@ -60,7 +50,7 @@ spring: hibernate.cache.use_query_cache: false hibernate.generate_statistics: true liquibase: - contexts: dev,sample-data + contexts: dev mail: host: localhost port: 25 diff --git a/src/main/resources/config/application-h2file.yml b/src/main/resources/config/application-h2file.yml new file mode 100644 index 00000000..bd53c6ff --- /dev/null +++ b/src/main/resources/config/application-h2file.yml @@ -0,0 +1,22 @@ +# Configuration for the dev-profile using a file-based H2 database. + +spring: + profiles: + active: h2,h2file + include: + - dev + - swagger + # Uncomment to activate TLS for the dev profile + #- tls + datasource: + url: url: jdbc:h2:~/.hsadminng.h2db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + username: hsadminNg + password: + h2: + console: + enabled: false + jpa: + database-platform: io.github.jhipster.domain.util.FixedH2Dialect + database: H2 + liquibase: + contexts: dev diff --git a/src/main/resources/config/application-h2mem.yml b/src/main/resources/config/application-h2mem.yml new file mode 100644 index 00000000..8762de24 --- /dev/null +++ b/src/main/resources/config/application-h2mem.yml @@ -0,0 +1,22 @@ +# Configuration for the dev-profile using an in-memory H2 database. + +spring: + profiles: + active: h2,h2mem + include: + - dev + - swagger + # Uncomment to activate TLS for the dev profile + #- tls + datasource: + url: jdbc:h2:mem:hsadminng;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + username: hsadminNg + password: + h2: + console: + enabled: false + jpa: + database-platform: io.github.jhipster.domain.util.FixedH2Dialect + database: H2 + liquibase: + contexts: dev,sample-data diff --git a/src/main/resources/config/application-pgsql.yml b/src/main/resources/config/application-pgsql.yml new file mode 100644 index 00000000..d4c07954 --- /dev/null +++ b/src/main/resources/config/application-pgsql.yml @@ -0,0 +1,19 @@ +# Configuration for the dev-profile using a Postgres database specified via environment. + +spring: + profiles: + active: dev,pgsql + include: + - dev + - swagger + # Uncomment to activate TLS for the dev profile + #- tls + datasource: + url: ${HSADMINNG_DB_URL} + username: ${HSADMINNG_DB_USER} + password: ${HSADMINNG_DB_PASS} + jpa: + database-platform: io.github.jhipster.domain.util.FixedPostgreSQL82Dialect + database: POSTGRESQL + liquibase: + contexts: dev diff --git a/src/main/resources/config/liquibase/sample-data/assets.xml b/src/main/resources/config/liquibase/sample-data/assets.xml index 10d5828f..7352b4ee 100644 --- a/src/main/resources/config/liquibase/sample-data/assets.xml +++ b/src/main/resources/config/liquibase/sample-data/assets.xml @@ -18,11 +18,21 @@ - - + + + + + UPDATE asset SET remark = replace(remark, '|', STRINGDECODE('\n')) + + UPDATE asset SET remark = replace(remark, '|', E'\n') + + DELETE FROM asset; diff --git a/src/main/resources/config/liquibase/sample-data/customers.xml b/src/main/resources/config/liquibase/sample-data/customers.xml index eb145b0d..a6e45e4b 100644 --- a/src/main/resources/config/liquibase/sample-data/customers.xml +++ b/src/main/resources/config/liquibase/sample-data/customers.xml @@ -19,8 +19,22 @@ - - UPDATE customer SET contractual_address = replace(contractual_address, '|', STRINGDECODE('\n')) + + + + + UPDATE customer SET contractual_address = replace(contractual_address, '|', STRINGDECODE('\n')); + UPDATE customer SET billing_address = replace(billing_address, '|', STRINGDECODE('\n')); + UPDATE customer SET remark = replace(remark, '|', STRINGDECODE('\n')); + + + + UPDATE customer SET contractual_address = replace(contractual_address, '|', '\n'); + UPDATE customer SET billing_address = replace(billing_address, '|', '\n'); + UPDATE customer SET remark = replace(remark, '|', E'\n'); diff --git a/src/main/resources/config/liquibase/sample-data/memberships.xml b/src/main/resources/config/liquibase/sample-data/memberships.xml index 97498a8f..e7d0936d 100644 --- a/src/main/resources/config/liquibase/sample-data/memberships.xml +++ b/src/main/resources/config/liquibase/sample-data/memberships.xml @@ -19,10 +19,20 @@ - + + + + UPDATE membership SET remark = replace(remark, '|', STRINGDECODE('\n')) + + UPDATE customer SET remark = replace(remark, '|', E'\n'); + + DELETE FROM membership; diff --git a/src/main/resources/config/liquibase/sample-data/sepamandates.xml b/src/main/resources/config/liquibase/sample-data/sepamandates.xml index 1e75c9ea..fa8ef3f7 100644 --- a/src/main/resources/config/liquibase/sample-data/sepamandates.xml +++ b/src/main/resources/config/liquibase/sample-data/sepamandates.xml @@ -19,10 +19,20 @@ - + + + + UPDATE sepa_mandate SET remark = replace(remark, '|', STRINGDECODE('\n')) + + UPDATE customer SET remark = replace(remark, '|', E'\n'); + + DELETE FROM sepa_mandate; diff --git a/src/main/resources/config/liquibase/sample-data/shares.xml b/src/main/resources/config/liquibase/sample-data/shares.xml index f8fa136f..19b221a3 100644 --- a/src/main/resources/config/liquibase/sample-data/shares.xml +++ b/src/main/resources/config/liquibase/sample-data/shares.xml @@ -19,10 +19,20 @@ - + + + + UPDATE share SET remark = replace(remark, '|', STRINGDECODE('\n')) + + UPDATE customer SET remark = replace(remark, '|', E'\n'); + + DELETE FROM share;