Try Flyway DB version control with Docker PostgreSQL in 3 steps

Step 1: Spin up Docker PostgreSQL

Start up with basic docker-compose.yml to spin up Postgres

my-postgres:
image: postgres
ports:
5555:5432
environment:
POSTGRES_USER: example
POSTGRES_PASSWORD: example
docker-compose up

Step 2: Flyway config

Flyway need to know where is the database and user to login so you going to add url , user and pass to it.

flyway.url=jdbc:postgresql://localhost:5555/example
flyway.user=example
flyway.password=example
flyway.locations=filesystem:./
flyway info
Flyway Community Edition 7.7.0 by Redgate
Database: jdbc:postgresql://localhost:5555/example (PostgreSQL 13.2)
...

Step 3: Flyway first migration

Then you create a ‘migration’ file in sql

-- filename: V1__create-accounts.sql
CREATE TABLE accounts (
user_id serial PRIMARY KEY,
username VARCHAR ( 50 ) UNIQUE NOT NULL,
password VARCHAR ( 50 ) NOT NULL,
email VARCHAR ( 255 ) UNIQUE NOT NULL,
created_on TIMESTAMP NOT NULL,
last_login TIMESTAMP
);
flyway migrate
example=# \dt
public | accounts | table | example
public | flyway_schema_history | table | example

Unfortunately …

when I run flyway undo

ERROR: Flyway Teams Edition upgrade required: undo is not supported by Flyway Community Edition.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store