adding Postgres configurations for dev-environment with sample-data

This commit is contained in:
Michael Hoennig 2019-05-04 13:59:12 +02:00
parent 24e76e03d1
commit 6efa167427
11 changed files with 168 additions and 25 deletions

View File

@ -3,8 +3,6 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** _generated with [DocToc](https://github.com/thlorenz/doctoc)_
- [Setting up the Development Environment](#setting-up-the-development-environment) - [Setting up the Development Environment](#setting-up-the-development-environment)
- [Frequent Tasks](#frequent-tasks) - [Frequent Tasks](#frequent-tasks)
- [Building the Application with Test Execution](#building-the-application-with-test-execution) - [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 ### Starting the Application
Either simply: To use an **H2 in-memory database** populated with sample-data.
gw bootRun 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 ### Running JUnit tests with branch coverage

View File

@ -8,7 +8,14 @@ dependencies {
compile "com.h2database:h2" 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')) { if (project.hasProperty('no-liquibase')) {
profiles += ',no-liquibase' profiles += ',no-liquibase'
} }
@ -16,6 +23,8 @@ if (project.hasProperty('tls')) {
profiles += ',tls' profiles += ',tls'
} }
println 'activating profiles: ' + profiles
springBoot { springBoot {
buildInfo { buildInfo {
properties { properties {

View File

@ -36,22 +36,12 @@ spring:
serialization: serialization:
indent-output: true indent-output: true
datasource: datasource:
# this is just a common configuration for the dev-profiles h2mem, h2file and pgsql
type: com.zaxxer.hikari.HikariDataSource 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: hikari:
poolName: Hikari poolName: Hikari
auto-commit: false auto-commit: false
h2:
console:
enabled: false
jpa: jpa:
database-platform: io.github.jhipster.domain.util.FixedH2Dialect
database: H2
show-sql: true show-sql: true
properties: properties:
hibernate.id.new_generator_mappings: true hibernate.id.new_generator_mappings: true
@ -60,7 +50,7 @@ spring:
hibernate.cache.use_query_cache: false hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true hibernate.generate_statistics: true
liquibase: liquibase:
contexts: dev,sample-data contexts: dev
mail: mail:
host: localhost host: localhost
port: 25 port: 25

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -18,11 +18,21 @@
</loadData> </loadData>
</changeSet> </changeSet>
<changeSet id="20190502111400-2" author="mhoennig" context="sample-data"> <changeSet id="20190502111400-2" author="mhoennig" context="sample-data,">
<sql>
<!-- I've tried extracting this to a stored procedure, but a compatible call
is only possible with PostgresSQL 11.x, otherwise the call syntax
between H2 and PostgresSQL would be different which defeated the point.
-->
<sql dbms="h2">
UPDATE asset SET remark = replace(remark, '|', STRINGDECODE('\n')) UPDATE asset SET remark = replace(remark, '|', STRINGDECODE('\n'))
</sql> </sql>
<sql dbms="postgresql">
UPDATE asset SET remark = replace(remark, '|', E'\n')
</sql>
<rollback> <rollback>
DELETE FROM asset; DELETE FROM asset;
</rollback> </rollback>

View File

@ -19,8 +19,22 @@
</changeSet> </changeSet>
<changeSet id="20190403083736-3" author="mhoennig" context="sample-data"> <changeSet id="20190403083736-3" author="mhoennig" context="sample-data">
<sql>
UPDATE customer SET contractual_address = replace(contractual_address, '|', STRINGDECODE('\n')) <!-- I've tried extracting this to a stored procedure, but a compatible call
is only possible with PostgresSQL 11.x, otherwise the call syntax
between H2 and PostgresSQL would be different which defeated the point.
-->
<sql dbms="h2">
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'));
</sql>
<sql dbms="postgresql">
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');
</sql> </sql>
<rollback> <rollback>

View File

@ -19,10 +19,20 @@
</changeSet> </changeSet>
<changeSet id="20190502100700-2" author="mhoennig" context="sample-data"> <changeSet id="20190502100700-2" author="mhoennig" context="sample-data">
<sql>
<!-- I've tried extracting this to a stored procedure, but a compatible call
is only possible with PostgresSQL 11.x, otherwise the call syntax
between H2 and PostgresSQL would be different which defeated the point.
-->
<sql dbms="h2">
UPDATE membership SET remark = replace(remark, '|', STRINGDECODE('\n')) UPDATE membership SET remark = replace(remark, '|', STRINGDECODE('\n'))
</sql> </sql>
<sql dbms="postgresql">
UPDATE customer SET remark = replace(remark, '|', E'\n');
</sql>
<rollback> <rollback>
DELETE FROM membership; DELETE FROM membership;
</rollback> </rollback>

View File

@ -19,10 +19,20 @@
</changeSet> </changeSet>
<changeSet id="20190503152800-2" author="mhoennig" context="sample-data"> <changeSet id="20190503152800-2" author="mhoennig" context="sample-data">
<sql>
<!-- I've tried extracting this to a stored procedure, but a compatible call
is only possible with PostgresSQL 11.x, otherwise the call syntax
between H2 and PostgresSQL would be different which defeated the point.
-->
<sql dbms="h2">
UPDATE sepa_mandate SET remark = replace(remark, '|', STRINGDECODE('\n')) UPDATE sepa_mandate SET remark = replace(remark, '|', STRINGDECODE('\n'))
</sql> </sql>
<sql dbms="postgresql">
UPDATE customer SET remark = replace(remark, '|', E'\n');
</sql>
<rollback> <rollback>
DELETE FROM sepa_mandate; DELETE FROM sepa_mandate;
</rollback> </rollback>

View File

@ -19,10 +19,20 @@
</changeSet> </changeSet>
<changeSet id="20190502111400-2" author="mhoennig" context="sample-data"> <changeSet id="20190502111400-2" author="mhoennig" context="sample-data">
<sql>
<!-- I've tried extracting this to a stored procedure, but a compatible call
is only possible with PostgresSQL 11.x, otherwise the call syntax
between H2 and PostgresSQL would be different which defeated the point.
-->
<sql dbms="h2">
UPDATE share SET remark = replace(remark, '|', STRINGDECODE('\n')) UPDATE share SET remark = replace(remark, '|', STRINGDECODE('\n'))
</sql> </sql>
<sql dbms="postgresql">
UPDATE customer SET remark = replace(remark, '|', E'\n');
</sql>
<rollback> <rollback>
DELETE FROM share; DELETE FROM share;
</rollback> </rollback>