I am new to Java, trying to setup a first API.
I have a Springboot app which connects to a postgresql database on a docker container.
I do manage to access the database from the app, so the database in on and accessible as per my application.properties
:
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5433/portfolio
spring.datasource.username=postgres
spring.datasource.password=123456
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.hibernate.ddl-auto=none
When attempting to setup migrations with flyway
with the command:
mvn flyway:migrate
I get the error:
No database found to handle jdbc:postgresql://localhost:5433/portfolio
This is how the pom.xml
for flyway
looks like:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>10.7.1</version>
<configuration>
<sqlMigrationSeparator>__</sqlMigrationSeparator>
<locations>
<location>filesystem:src/main/resources/db/migration/portfolio</location>
</locations>
<url>jdbc:postgresql://localhost:5433/portfolio</url>
<user>postgres</user>
<password>123456</password>
</configuration>
<dependencies>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>10.7.1</version>
</dependency>
</dependencies>
</plugin>
EDIT - adding docker-compose as requested
version: "3.8"
volumes:
db:
services:
postgresdb:
container_name: postgres_container
image: postgres
restart: unless-stopped
env_file: ./.env
environment:
- POSTGRES_USER=$POSTGRESDB_USER
- POSTGRES_PASSWORD=$POSTGRESDB_ROOT_PASSWORD
- POSTGRES_DB=$POSTGRESDB_DATABASE
ports:
- $POSTGRESDB_LOCAL_PORT:$POSTGRESDB_DOCKER_PORT
volumes:
- db:/var/lib/postgres
pgadmin:
image: dpage/pgadmin4:latest
environment:
PGADMIN_DEFAULT_EMAIL: admin@localhost.com
PGADMIN_DEFAULT_PASSWORD: admin
PGADMIN_LISTEN_PORT: 5050
ports:
- '5050:5050'
.env file
POSTGRESDB_USER=postgres
POSTGRESDB_ROOT_PASSWORD=123456
POSTGRESDB_DATABASE=portfolio
POSTGRESDB_LOCAL_PORT=5433
POSTGRESDB_DOCKER_PORT=5432
The error says No database found to handle jdbc:postgresql
. This doesn't mean that the database is not accessible/running, but that Flyway can't handle the PostgreSQL database type. You should add this to the Maven Plugin dependencies:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
<version>11.3.4</version>
</dependency>
Please note: latest Flyway version is 11.3.4