Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • Labrador Labrador
  • Subgroup information
    • Subgroup information
    • Activity
    • Labels
    • Members
  • Epics 8
    • Epics 8
    • List
    • Boards
    • Roadmap
  • Issues 313
    • Issues 313
    • List
    • Boards
    • Milestones
    • Iterations
  • Merge requests 26
    • Merge requests 26
  • Security and Compliance
    • Security and Compliance
    • Security dashboard
    • Vulnerability report
  • Packages and registries
    • Packages and registries
    • Package Registry
  • Analytics
    • Analytics
    • Insights
    • Issue
  • Wiki
    • Wiki
Collapse sidebar
  • EIPEIP
  • LabradorLabrador
  • Wiki
  • Migrations

Migrations · Changes

Page history
Update Migrations authored Feb 14, 2023 by Timur Oberhuber's avatar Timur Oberhuber
Hide whitespace changes
Inline Side-by-side
Migrations.md
View page @ e3a4b9ed
# Migrations
When an application is already deployed and changes to the database are necessary, a migration needs to be written. This can be done as follows. If you have never written a migration before, obtain `h2-1.3.176.jar` and `liquibase.zip` from another developer. Then add liquibase to your path and put the jar under `/usr/local/apps/h2`. When this is done, run the development branch with the following settings:
```
spring:
jpa:
hibernate:
ddl-auto: create
datasource:
url: jdbc:h2:file:./testdb-old;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=false;
username: sa
password:
```
Then run your branch, but change `testdb-old` to `testdb-new`. Afterwards, you can generate a changelog with the following script:
When an application is already deployed and changes to the database are necessary, a migration needs to be written. This can be done as follows.
### Setup Liquibase:
1. Install Liquibase (just from their website).
2. Copy the `liquibase.template.properties` file in the root directory (if it isn't available in your project, head to the TAM repository and copy it from there).
3. Paste the copy into the root directory and rename it to `liquibase.properties`.
4. Check the `build.gradle.kts` file and find the `h2Version` variable. In the `classpath` variable, replace `VERSION` with the version as it appears in the variable.
5. Check the following path in your file explorer: `$HOME\.gradle\caches\modules-2\files-2.1\com.h2database\h2\VERSION` and find the folder containing a `.jar` file. Replace `HASH` in the `classpath` variable with the name of this folder.
* If you can't find `modules-2` in the `.gradle/caches` folder, then check the [Gradle Docs](https://docs.gradle.org/current/userguide/directory_layout.html) and replace `modules-2` with the folder labeled `Shared caches (e.g. for artifacts of dependencies)`.
6. On a new line add the variable `changeSetAuthor` and set it equal to your GitLab username (usually your NetID).
Another option is to obtain `h2.jar` and `liquibase.zip` from another developer (or from the `.gradle` folder). Then add Liquibase to your path and put the jar under `/usr/local/apps/h2`.
### Create migrations:
1. Switch to the `dev` branch.
2. Make sure the `application.yaml` file has `url: jdbc:h2:file:./testdb-old;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=false;` in the `datasource` section.
3. Run the project normally, there should now be some `.db` files in the root directory.
4. Stop the project.
5. Switch back to your branch.
6. Make sure the `application.yaml` file has `url: jdbc:h2:file:./testdb-new;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=false;` in the `datasource` section.
7. Run the project normally.
8. Now run this command: `liquibase --changelogFile=new.yaml diff-changelog`, there should now be a file called `new.yaml` in the root directory.
9. If you encounter errors during this step, check the `liquibase.properties` file for instructions.
10. Now copy your changes from `changes.yaml` to the bottom of `migrations.yaml`. Double check whether the generated changelog makes sense. Sometimes, you might need to add default values or change column types.
11. Make sure to delete the `new.yaml` file before preforming more migrations.
Alternatively you can generate a changelog with the following script:
```
PROJ_DIR=$1
RESOURCES_DIR=$PROJ_DIR/src/main/resources
......@@ -27,6 +43,4 @@ liquibase \
--referenceUrl=jdbc:h2:$PROJ_DIR/testdb-new \
--referenceUsername=sa \
--referencePassword=
```
Finally, copy your changes from `changes.yaml` to the bottom of `migrations.yaml`. Double check whether the generated changelog makes sense. Sometimes, you might need to add default values or change column types.
```
\ No newline at end of file
Clone repository

Home
General Overview
Getting Started
    Setup
    Guidelines
Libraries, Core and Such
    LabraCore
    Librador
    Labradoor
Development
    Migrations
    Test Data