Spring Boot + PostgreSQL: cannot find schema to create Camunda tables - postgresql

I am trying to create tables for camunda (7.14.0) at Spring Boot application start. I have manually created a PostgreSQL schema in advance with the name "camunda". When I run the Spring Boot application, it gives me an error:
ENGINE-03017 Could not perform operation 'create' on database schema for SQL Statement ...
and
org.postgresql.util.psqlexception: no schema has been selected to create in
My application.yml config:
camunda:
bpm:
database:
type: postgres
schema-update: create
schema-name: camunda
username: camunda
password: camunda
table-prefix: camunda.
How can I create camunda tables in a schema with a specific name?

Example config:
spring.datasource:
url: jdbc:postgresql://localhost:5432/postgres?autoReconnect=true
username: cam1
password: cam1
driver-class-name: org.postgresql.Driver
camunda:
bpm:
database:
schema-name: cam1
table-prefix: cam1.
Ensure the schema has been created and user used has been given the permissions on the target schema.
Full example for two Camunda instances using separate schemas: https://github.com/rob2universe/two-camunda-instances

Related

Unable to connect to the database. Configure the url, user and password

I have a spring boot app and I need flyway migration. After I configured in application.yml like this:
flyway:
driverClassName: org.postgresql.Driver
locations: classpath:src/main/resources/db/migration
url: jdbc:postgresql://localhost:5432/myDB
user: postgres
password: 123
schemas: public
enable: true
baseline-on-migrate: true
I got an error when tried to use flyway:migrate or flyway:repair: Unable to connect to the database. Configure the url, user and password!
What I'm doing wrong?!

running migration for multiple schema - typeorm/postgres

I have a schema based multitenancy setup in postgres.
Typeorm allows us to run migration using a single command:
typeorm migration:run -d db.connection.js
the connection is defined like this:
{
type: 'postgres',
host: process.env.DB_HOST,
port: Number(process.env.DB_PORT),
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
ssl: process.env.DB_SSL === 'true',
schema,
migrations: migrations || ['./**/*.migration.js'],
...options,
}
Now, I have 3 schema in my database: A, B and C, how do I run the migration for all 3 of them at once? This is a really big issue for me as manually triggering migration for each schema individually is time consuming and cumbersome. Does typeorm have a method to specify multiple schemas?

How to define schema name in #MappedEntity annotation for r2dbc

I have kotlin & Micronaut application connecting to postgresql using r2dbc for reactive approach
r2dbc:
datasources:
default:
schema-generate: NONE
dialect: POSTGRES
url: r2dbc:postgresql://localhost:5434/mydb
username: postgres
password: postgres
I have the table called Customer inside database mydb and schema myschema, but while using the #MappedEntity we can only define the table name. Since table is inside of myschema the application is throws entity does not exist
15:26:15.455 [reactor-tcp-nio-1] ERROR i.m.h.n.stream.HttpStreamsHandler - Error occurred writing stream response: relation "customer" does not exist
io.r2dbc.postgresql.ExceptionFactory$PostgresqlBadGrammarException: relation "customer" does not exist
how to define schema name in MappedEntity annotation ?
One way you can do it is, you can define the current schema in url using query parameter
url: r2dbc:postgresql://localhost:5434/mydb?currentSchema=myschema
You can use JPA’s ‘#Table’ as a workaround.

Getting this error when connecting mongodb in docker-compose with spring-boot application

"ctx":"conn18","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-1","speculative":false,"principalName":"user","authenticationDatabase":"user_db","remote":"172.20.0.8:51928","extraInfo":{},"error":"UserNotFound: Could not find user "user" for db "user_db""}}
where user is my username & user_db is the database name
Add the authSource=admin at the end of the uri in spring-boot application.yml file
spring:
data:
mongodb:
uri: mongodb://user:pass#localhost:27017/user_db?authSource=admin

using spring boot profiles with liquibase changeset context attribute to manage changset scope

I am trying to do a proof of concept application with spring boot and liquibase. I basically want to create a spring boot app that can manage liquibase changesets by utilizing the changeset attribute called context, so that changesets with no context can be applied to any spring boot profile, whereas changesets with specific context (e.g context="dev" ) will only be applied if spring boot profiles of that type, is active (e.g spring.profiles.active=dev).
In my app, i have the following spring profiles -> dev, prod (each specified correctly in the application yaml file with the relavant profile db credentials also specified under the profile). What do I need to do to make this work. below is my application.yaml
spring:
application:
name: liquibase-spring-jpa-postgres-example
liquibase:
change-log: db.changelog/db.changelog-master.xml
spring:
profiles: dev
datasource:
url: jdbc:postgresql://localhost:5432/dev
username: postgres
password: password
driver-class-name: org.postgresql.Driver
spring:
profiles: ci
datasource:
url: jdbc:postgresql://localhost:5432/ci
username: postgres
password: password
driver-class-name: org.postgresql.Driver
spring:
profiles: qa
datasource:
url: jdbc:postgresql://localhost:5432/qa
username: postgres
password: password
driver-class-name: org.postgresql.Driver
spring:
profiles: production
datasource:
url: jdbc:postgresql://localhost:5432/prod
username: postgres
password: password
driver-class-name: org.postgresql.Driver
and below is the current databaseChangeLog file (the second change set shouldn't run if my spring profile is prod).
<changeSet id="20161016_my_first_change" author="fike" context="dev, qa, ci, production">
<sql>
CREATE TABLE customer
(
id BIGSERIAL PRIMARY KEY,
firstname character varying NOT NULL,
lastname character varying NOT NULL
);
</sql>
<rollback>
drop table customer;
</rollback>
</changeSet>
<changeSet id="20161016_my_first_change2" author="krudland" context="dev">
<sql>
insert into customer (firstname, lastname) values ('Franklin','Ike');
</sql>
<rollback>
delete from customer where firstname = 'Franklin' and lastname = 'Ike';
</rollback>
</changeSet>
I basically need to be able to manage my liquibase context, using my spring profile. Is this possible?
You need to define 'liquibase.contexts' property into your yaml file. Something like below.
spring:
profiles: dev
datasource:
url: jdbc:postgresql://localhost:5432/dev
username: postgres
password: password
driver-class-name: org.postgresql.Driver
liquibase:
contexts: dev
After adding this the below change set will only execute when your local profile is 'dev' (i.e. spring-boot:run -Dspring.profiles.active=dev)
<changeSet id="20161016_my_first_change2" author="krudland" context="dev">
<sql>
insert into customer (firstname, lastname) values ('Franklin','Ike');
</sql>
<rollback>
delete from customer where firstname = 'Franklin' and lastname = 'Ike';
</rollback>
</changeSet>
The better way is to reference spring profile in liquibase context settings, starting from spring boot version 2 only thing you need to add to main application.yml or application.properties is:
spring.liquibase.contexts=${spring.profiles.active}
Your active spring profile will be used as active liquibase context.