Skip to content

Commit

Permalink
Merge pull request #10026 from mkurz/evo_schema_substition_fix
Browse files Browse the repository at this point in the history
Don't substitute string "${schema}" in evolution files
  • Loading branch information
mergify[bot] committed Feb 2, 2020
2 parents 7d860b7 + 07753cc commit 43861fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Expand Up @@ -218,7 +218,7 @@ class DatabaseEvolutions(database: Database, schema: String = "") {
script.statements.foreach { statement =>
logger.debug(s"Execute: $statement")
val start = System.currentTimeMillis()
execute(statement)
execute(statement, false)
logger.debug(s"Finished in ${System.currentTimeMillis() - start}ms")
}
logAfter(script)
Expand Down Expand Up @@ -340,10 +340,10 @@ class DatabaseEvolutions(database: Database, schema: String = "") {
}
}

private def execute(sql: String)(implicit c: Connection): Boolean = {
private def execute(sql: String, replaceSchema: Boolean = true)(implicit c: Connection): Boolean = {
val s = c.createStatement
try {
s.execute(applySchema(sql))
s.execute(if (replaceSchema) applySchema(sql) else sql)
} finally {
s.close()
}
Expand Down
Expand Up @@ -107,6 +107,15 @@ class EvolutionsSpec extends Specification {
resultSet.close()
}

trait CheckSchemaString { this: WithEvolutions =>
val scripts = evolutions.scripts(Seq(a1, a2, a3, a4))
evolutions.evolve(scripts, autocommit = true)
val resultSet = executeQuery("select name from test where id = 2")
resultSet.next must beTrue
resultSet.getString(1) must_== "some string with ${schema}"
resultSet.close()
}

"apply up scripts" in new UpScripts with WithEvolutions
"apply up scripts derby" in new UpScripts with WithDerbyEvolutions

Expand All @@ -127,6 +136,7 @@ class EvolutionsSpec extends Specification {
"reset the database to trigger creation of the play_evolutions table in the testschema derby" in new ResetDatabase
with WithDerbyEvolutionsSchema
"provide a helper for testing derby schema" in new ProvideHelperForTestingSchema with WithDerbyEvolutionsSchema
"not replace the string ${schema} in an evolutions script" in new CheckSchemaString with WithDerbyEvolutionsSchema
}

trait WithEvolutions extends After {
Expand Down Expand Up @@ -179,6 +189,12 @@ class EvolutionsSpec extends Specification {
"delete from test;"
)

val a4 = Evolution(
4,
"insert into test (id, name, age) values (2, 'some string with ${schema}', 87);",
"delete from test where id=2;"
)

val b1 = Evolution(
1,
"create table test (id bigint not null, content varchar(255));",
Expand Down

0 comments on commit 43861fd

Please sign in to comment.