Skip to content

Commit

Permalink
Move away from flyway for schema migration
Browse files Browse the repository at this point in the history
Updates some documentation so that the misk schema migrator plugin is
preferred

GitOrigin-RevId: d0cb6cf1d6a5348413371ffd0fba675d6131f1da
  • Loading branch information
staktrace authored and svc-squareup-copybara committed Jan 6, 2025
1 parent 490d595 commit ae41c15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
25 changes: 11 additions & 14 deletions misk-jooq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ a. Add the below lines to your build.gradle.kts

```
plugins {
alias(libs.plugins.flyway)
alias(libs.plugins.miskSchemaMigrator)
alias(libs.plugins.jooq)
}
val dbMigrations = "src/main/resources/db-migrations"
// We are using flyway here in order to run the migrations to create a schema.
// We are using the schema migrator plugin here in order to run the migrations to create a schema.
// Ensure the migration directory is not called `migrations`. There's more details as to why below.
flyway {
url = "jdbc:mysql://localhost:3500/misk-jooq-test-codegen"
user = "root"
miskSchemaMigrator {
database = "misk-jooq-test-codegen" // change this to your service name
username = "root"
password = "root"
schemas = arrayOf("jooq")
locations = arrayOf("filesystem:${project.projectDir}/${dbMigrations}")
sqlMigrationPrefix = "v"
host = "localhost"
port = 3500
migrationsDir.set(layout.projectDirectory.dir(dbMigrations))
}
// More details about the jooq plugin here - https://github.com/etiennestuder/gradle-jooq-plugin
jooq {
Expand Down Expand Up @@ -75,7 +75,7 @@ jooq {
// Needed to generate jooq test db classes
tasks.withType<nu.studer.gradle.jooq.JooqGenerate>().configureEach {
dependsOn("flywayMigrate")
dependsOn("migrateSchema")
// declare migration files as inputs on the jOOQ task and allow it to
// participate in build caching
Expand All @@ -95,7 +95,7 @@ sourceSets {
}
```

b. Have a look at `jooq-test-regenerate.sh`. Copy that into the root of your project and modify the database
b. Have a look at `jooq-test-regenerate.sh`. Copy that into the root of your project and modify the database
name and docker container name.

c. Run `jooq-test-regenerate.sh` to have your model generated for you and ready to use.
Expand Down Expand Up @@ -162,10 +162,7 @@ ctx.select()

## Future

1. The generation tool uses flyway to generate the schema. I would like to use misk-jdbc's
SchemaMigrationService built into a gradle plugin. That same plugin can also generate the
jooq classes.
Further, in order to use jooq we can't have migrations placed in a folder called `migrations`.
1. Further, in order to use jooq we can't have migrations placed in a folder called `migrations`.
The issue is jooq.jar ships with a directory called `migrations` with the some
[migrations](https://github.com/jOOQ/jOOQ/tree/main/jOOQ/src/main/resources/migrations)
we don't care about in it. When the service starts up it finds this folder as well and tries
Expand Down
4 changes: 2 additions & 2 deletions misk-schema-migrator-gradle-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ miskSchemaMigrator {
// If you want to integrate with JOOQ
// tasks.withType<nu.studer.gradle.jooq.JooqGenerate>().configureEach {
// dependsOn("migrateSchemas")
// dependsOn("migrateSchema")
// }
```
```

0 comments on commit ae41c15

Please sign in to comment.