Skip to content

Commit

Permalink
Turn on gradle caching for JooqGenerate
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 59bfc81c5f828d6d644afa5057d6b5e661d7c81b
  • Loading branch information
staktrace authored and svc-squareup-copybara committed Oct 3, 2024
1 parent 9588fb2 commit 8efcbeb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
14 changes: 11 additions & 3 deletions misk-jooq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ plugins {
alias(libs.plugins.flyway)
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.
// 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"
password = "root"
schemas = arrayOf("jooq")
locations = arrayOf("filesystem:${project.projectDir}/src/main/resources/db-migrations")
locations = arrayOf("filesystem:${project.projectDir}/${dbMigrations}")
sqlMigrationPrefix = "v"
}
// More details about the jooq plugin here - https://github.com/etiennestuder/gradle-jooq-plugin
Expand Down Expand Up @@ -73,8 +74,15 @@ jooq {
}
// Needed to generate jooq test db classes
tasks.named("generateJooq") {
tasks.withType<nu.studer.gradle.jooq.JooqGenerate>().configureEach {
dependsOn("flywayMigrate")
// declare migration files as inputs on the jOOQ task and allow it to
// participate in build caching
inputs.files(fileTree(layout.projectDirectory.dir(dbMigrations)))
.withPropertyName("migrations")
.withPathSensitivity(PathSensitivity.RELATIVE)
allInputsDeclared.set(true)
}
// Needed to generate jooq test db classes
Expand Down Expand Up @@ -162,4 +170,4 @@ ctx.select()
[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
to run those migrations. Renaming misk service migrations to somethinq like `db-migrations` works.

13 changes: 11 additions & 2 deletions misk-jooq/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ dependencies {
jooqGenerator(libs.mysql)
}

val dbMigrations = "src/test/resources/db-migrations"

// Needed to generate jooq test db classes
flyway {
url = "jdbc:mysql://localhost:3500/misk-jooq-test-codegen"
user = "root"
password = "root"
schemas = arrayOf("jooq")
locations = arrayOf("filesystem:${project.projectDir}/src/test/resources/db-migrations")
locations = arrayOf("filesystem:${project.projectDir}/${dbMigrations}")
sqlMigrationPrefix = "v"
}
// Needed to generate jooq test db classes
Expand Down Expand Up @@ -83,8 +85,15 @@ jooq {
}

// Needed to generate jooq test db classes
tasks.named("generateJooq") {
tasks.withType<nu.studer.gradle.jooq.JooqGenerate>().configureEach {
dependsOn("flywayMigrate")

// declare migration files as inputs on the jOOQ task and allow it to
// participate in build caching
inputs.files(fileTree(layout.projectDirectory.dir(dbMigrations)))
.withPropertyName("migrations")
.withPathSensitivity(PathSensitivity.RELATIVE)
allInputsDeclared.set(true)
}

// Needed to generate jooq test db classes
Expand Down

0 comments on commit 8efcbeb

Please sign in to comment.