Skip to content

Commit

Permalink
fix flywayMigrate gradle task
Browse files Browse the repository at this point in the history
  • Loading branch information
fennifith committed Dec 8, 2024
1 parent 495cdec commit 743645e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ S3_KEY_ID=playful
S3_KEY_SECRET=programming
S3_BUCKET=hoof-storage

POSTGRES_USER=unicorn
POSTGRES_USER=postgres
POSTGRES_PASSWORD=unicorn
POSTGRES_URL="postgresql://localhost:5432/postgres"
29 changes: 6 additions & 23 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ plugins {
alias(libs.plugins.ktor)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.sqldelight)
alias(libs.plugins.flyway)
}

group = "com.playfulprogramming"
Expand Down Expand Up @@ -39,6 +38,12 @@ tasks.run.configure {
environment.putAll(env)
}

tasks.create("runFlywayMigrate", JavaExec::class) {
environment.putAll(env)
classpath = sourceSets.main.get().runtimeClasspath
mainClass = "com.playfulprogramming.cms.FlywayMigrate"
}

val flywayMigrationDir = layout.buildDirectory.dir("resources/main/migrations")

sqldelight {
Expand All @@ -52,28 +57,6 @@ sqldelight {
}
}

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath(libs.postgres.get().toString())
classpath(libs.flyway.postgres.get().toString())
}
}

flyway {
url = "jdbc:${env["POSTGRES_URL"]}"
user = env["POSTGRES_USER"]
password = env["POSTGRES_PASSWORD"]
locations = arrayOf("filesystem:${flywayMigrationDir.get()}")
}

tasks.flywayMigrate.configure {
// SQLDelight needs to actually generate the migration files
// before Flyway can use them
dependsOn("generateMainDatabaseMigrations")
}
tasks.processResources.configure {
dependsOn("generateMainDatabaseMigrations")
}
Expand Down
1 change: 0 additions & 1 deletion api/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,3 @@ kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
ktor = { id = "io.ktor.plugin", version.ref = "ktor" }
sqldelight = { id = "app.cash.sqldelight", version.ref = "sqldelight" }
flyway = { id = "org.flywaydb.flyway", version.ref = "flyway" }
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ object FlywayMigrate {

private val logger = LoggerFactory.getLogger(this::class.java)

@JvmStatic
fun main(argv: Array<String>) {
run()
}

fun run() {
logger.info("Running FlywayMigrate...")

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:
- .env
environment:
S3_ENDPOINT: http://minio:9000
POSTGRES_URL: postgresql://pgsql:5432/unicorn
POSTGRES_URL: postgresql://pgsql:5432/postgres
depends_on:
- minio
- pgsql
Expand All @@ -44,7 +44,7 @@ services:
env_file:
- .env
environment:
POSTGRES_URL: postgresql://pgsql:5432/unicorn
POSTGRES_URL: postgresql://pgsql:5432/postgres
ports:
- "8080:8080"
depends_on:
Expand Down

0 comments on commit 743645e

Please sign in to comment.