Database
Metadata
Lecture equivalent | Duration |
---|---|
3 | 2h 15min |
At the end of this task, students
- have linked
spring-starter
to a MySQL database using JPA - have run 1 migration with Liquibase
Pre-requisites
In the lecture, we started to reproduce spring-starter#6.
Task
Do add the Scientist repository as H2 database to your project as you see in the pull request!
Guide
The transfer task follows this guide but with one key change ๐: We do not use a host-machine mysql server, we use a docker container mysql
.
Prepare the database
In the Environment Variables section of mysql
you find a way to replace the database from the guide with some values of your choice.
Data loss
Using a docker database that is not mounted to you host machine will result in data loss. But in my case and in this transfer task, this is actually the goal because some scientists get pre-loaded at every startup as you can see in pre-requisites.
Follow the guideline
Task
Follow the guide now but use your docker database!
If you did complete the pre-requisites then stop before the Create the @Entity Model part. If not, continue the guide until the end.
Migrations
In the lecture, you learned what migrations are. In case you forgot, read this.
It is finally time, to fease all you learned today into one smooth deliverable:
Task
Complete this tutorial to finish your journey on the database. But:
- Do not create new entities, use the existing ones!
- Do not use Lombok if you do not want another adventure again, just write plain code.
But Dominik, its in PostgreSQL?!
Yes, but you can also drive a Canyon and a Trek bike... These frameworks are capable of using another technology instead, switch it with your engineering capabilities OR learn something new by switching your spring-starter
to PostgreSQL!
Sample
The sample solution has two steps:
- Adding JPA and the MySQL setup - note that this uses volatile data which disappears at restart (except that docker compose caches it, which we circumvent in this part)
- Running a migration on our data (can be done against a persistent service or against the cached compose volume)