mirror of
https://github.com/corda/corda.git
synced 2024-12-28 16:58:55 +00:00
Enable database integration tests against Postgres database (#169)
* For Postgres, if a schema name is provided then it's wrapped in double quotes before passing to Hibernate to preserve case-sensitivity, Liquibase does it out-of-box. * Sql setup scripts for PostgreSQL and datasource configuration.
This commit is contained in:
parent
e92ce3ad37
commit
f2186e7e30
@ -155,6 +155,8 @@ UNRELEASED
|
||||
|
||||
* Enterprise Corda only: node configuration property ``database.schema`` and documented existing database properties.
|
||||
|
||||
* Enterprise Corda only: Compatibility with PostgreSQL 9.6 database.
|
||||
|
||||
.. _changelog_v1:
|
||||
|
||||
Release 1.0
|
||||
|
@ -58,3 +58,25 @@ database {
|
||||
transactionIsolationLevel = "readCommitted"
|
||||
schema = [SCHEMA]
|
||||
}
|
||||
|
||||
PostgreSQL
|
||||
````````````````````````
|
||||
Corda supports PostgreSQL 9.6 database.
|
||||
The property ``database.schema`` is optional. The value of ``database.schema`` is automatically wrapped in double quotes
|
||||
to preserve case-sensitivity (e.g. `AliceCorp` becomes `"AliceCorp"`, without quotes PostgresSQL would treat the value as `alicecorp`).
|
||||
Corda ships with PostgreSQL JDBC Driver 42.1.4 out-of-the-box.
|
||||
|
||||
Example node configuration for PostgreSQL:
|
||||
|
||||
.. sourcecode:: none
|
||||
|
||||
dataSourceProperties = {
|
||||
dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
|
||||
dataSource.url = "jdbc:postgresql://[HOST]:[PORT]/postgres"
|
||||
dataSource.user = [USER]
|
||||
dataSource.password = [PASSWORD]
|
||||
}
|
||||
database = {
|
||||
transactionIsolationLevel = READ_COMMITTED
|
||||
schema = [SCHEMA]
|
||||
}
|
||||
|
@ -51,7 +51,13 @@ class HibernateConfiguration(
|
||||
.setProperty("hibernate.connection.isolation", databaseConfig.transactionIsolationLevel.jdbcValue.toString())
|
||||
|
||||
databaseConfig.schema?.apply {
|
||||
config.setProperty("hibernate.default_schema", databaseConfig.schema)
|
||||
//preserving case-sensitive schema name for PostgreSQL by wrapping in double quotes, schema without double quotes would be treated as case-insensitive (lower cases)
|
||||
val schemaName = if (jdbcUrl.contains(":postgresql:", ignoreCase = true) && !databaseConfig.schema.startsWith("\"")) {
|
||||
"\"" + databaseConfig.schema + "\""
|
||||
} else {
|
||||
databaseConfig.schema
|
||||
}
|
||||
config.setProperty("hibernate.default_schema", schemaName)
|
||||
}
|
||||
|
||||
schemas.forEach { schema ->
|
||||
@ -97,7 +103,7 @@ class HibernateConfiguration(
|
||||
applyBasicType(CordaWrapperBinaryType, CordaWrapperBinaryType.name)
|
||||
// When connecting to SqlServer (and only then) do we need to tell hibernate to use
|
||||
// nationalised (i.e. Unicode) strings by default
|
||||
val forceUnicodeForSqlServer = jdbcUrl.contains(":sqlserver:", ignoreCase = true);
|
||||
val forceUnicodeForSqlServer = jdbcUrl.contains(":sqlserver:", ignoreCase = true)
|
||||
enableGlobalNationalizedCharacterDataSupport(forceUnicodeForSqlServer)
|
||||
build()
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
DROP SCHEMA IF EXISTS "${schema}" CASCADE;
|
||||
DROP OWNED by "${schema}";
|
||||
DROP USER "${schema}";
|
@ -0,0 +1,10 @@
|
||||
DROP SCHEMA IF EXISTS "${schema}" CASCADE;
|
||||
DROP OWNED by "${schema}";
|
||||
DROP USER IF EXISTS "${schema}";
|
||||
CREATE USER "${schema}" WITH LOGIN password '1234';
|
||||
CREATE SCHEMA "${schema}";
|
||||
GRANT ALL ON SCHEMA "${schema}" TO "${schema}";
|
||||
GRANT ALL ON ALL tables IN SCHEMA "${schema}" TO "${schema}";
|
||||
ALTER DEFAULT privileges IN SCHEMA "${schema}" GRANT ALL ON tables TO "${schema}";
|
||||
GRANT ALL ON ALL sequences IN SCHEMA "${schema}" TO "${schema}";
|
||||
ALTER DEFAULT privileges IN SCHEMA "${schema}" GRANT ALL ON sequences TO "${schema}";
|
@ -0,0 +1,5 @@
|
||||
DROP SCHEMA IF EXISTS "${schema}" CASCADE;
|
||||
CREATE SCHEMA "${schema}";
|
||||
GRANT ALL ON SCHEMA "${schema}" TO "${schema}";
|
||||
ALTER DEFAULT privileges IN SCHEMA "${schema}" GRANT ALL ON tables TO "${schema}";
|
||||
ALTER DEFAULT privileges IN SCHEMA "${schema}" GRANT ALL ON sequences TO "${schema}";
|
@ -29,18 +29,20 @@ DROP TABLE IF EXISTS ${schema}.node_named_identities;
|
||||
DROP TABLE IF EXISTS ${schema}.children;
|
||||
DROP TABLE IF EXISTS ${schema}.parents;
|
||||
DROP TABLE IF EXISTS ${schema}.contract_cash_states;
|
||||
DROP TABLE IF EXISTS ${schema}.contract_cash_states_v1;
|
||||
DROP TABLE IF EXISTS ${schema}.messages;
|
||||
DROP TABLE IF EXISTS ${schema}.state_participants;
|
||||
DROP TABLE IF EXISTS ${schema}.cash_states_v2;
|
||||
DROP TABLE IF EXISTS ${schema}.cash_states_v3;
|
||||
DROP TABLE IF EXISTS ${schema}.cp_states_v1;
|
||||
DROP TABLE IF EXISTS ${schema}.cp_states_v2;
|
||||
DROP TABLE IF EXISTS ${schema}.dummy_deal_states;
|
||||
DROP TABLE IF EXISTS ${schema}.dummy_linear_states;
|
||||
DROP TABLE IF EXISTS ${schema}.dummy_linear_states_v2;
|
||||
DROP TABLE IF EXISTS ${schema}.node_mutual_exclusion;
|
||||
DROP SEQUENCE IF EXISTS ${schema}.hibernate_sequence;
|
||||
DROP TABLE IF EXISTS ${schema}.DATABASECHANGELOG;
|
||||
DROP TABLE IF EXISTS ${schema}.DATABASECHANGELOGLOCK;
|
||||
DROP SEQUENCE IF EXISTS ${schema}.hibernate_sequence;
|
||||
DROP USER IF EXISTS ${schema};
|
||||
DROP LOGIN ${schema};
|
||||
DROP SCHEMA IF EXISTS ${schema};
|
||||
|
@ -0,0 +1,10 @@
|
||||
dataSourceProperties = {
|
||||
dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
|
||||
dataSource.url = "jdbc:postgresql://[HOST]:[PORT]/postgres"
|
||||
dataSource.user = ${nodeOrganizationName}
|
||||
dataSource.password = "1234"
|
||||
}
|
||||
database = {
|
||||
transactionIsolationLevel = READ_COMMITTED
|
||||
schema = ${nodeOrganizationName}
|
||||
}
|
Loading…
Reference in New Issue
Block a user