The application server expects a PostgresQL database to run Flyway migrations. If it can't find one it'll retry forever until successful. This way it doesn't matter what is started first - the application or the database.
Run the local development database with docker. Replace values for POSTGRES_DB and POSTGRES_PASSWORD according to your settings.
docker run --name devdb -p 5432:5432 -e POSTGRES_DB=items -e POSTGRES_PASSWORD=12345 -d postgresConnect with psql:
psql -h localhost -U postgres -d itemsConnect with docker:
docker exec -it devdb psql -U postgres -d itemsTo run the application locally:
sbt runAfter you run the application Flyway will run the migrations.
By default the server is started at http://localhost:8080. Expects the database at localhost:5432 with database name items and user/password postgres/12345.
You can override the defaults with the following environment variables:
- DB_HOST
- DB_PORT
- DB_NAME
- DB_USER
- DB_PASSWORD
Run tests:
sbt test
The integration tests are using testcontainers to run dockerized PostgrSQL instance and Flyway to apply schema evolutions before running the tests.
Add new Item:
curl --request POST \
--url http://localhost:8080/items \
--header 'content-type: application/json' \
--data '{
"name":"BigMac",
"price": 10.0
}'Get all Items:
curl --request GET \
--url http://localhost:8080/itemsGet single Item:
curl --request GET \
--url http://localhost:8080/items/1Update Item:
curl --request PUT \
--url http://localhost:8080/items/1 \
--header 'content-type: application/json' \
--data '{
"name":"BigKing",
"price": 12.0
}'Detele Item:
curl --request DELETE \
--url http://localhost:8080/items/1Schema evolution is done using Flyway.
To add more evolutions add the new scripts to resources/db/migration.
Read more about Flyway here.
This project is configured with sbt-native-packager. To publish a docker image to your local docker repository run:
sbt docker:publishLocal
This will create an image with name kofola:<version>.