diff --git a/persistence/play-jdbc-evolutions/src/main/scala/play/api/db/evolutions/EvolutionsApi.scala b/persistence/play-jdbc-evolutions/src/main/scala/play/api/db/evolutions/EvolutionsApi.scala index df3cc757a11..7d44e2e1dc8 100644 --- a/persistence/play-jdbc-evolutions/src/main/scala/play/api/db/evolutions/EvolutionsApi.scala +++ b/persistence/play-jdbc-evolutions/src/main/scala/play/api/db/evolutions/EvolutionsApi.scala @@ -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) @@ -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() } diff --git a/persistence/play-jdbc-evolutions/src/test/scala/play/api/db/evolutions/EvolutionsSpec.scala b/persistence/play-jdbc-evolutions/src/test/scala/play/api/db/evolutions/EvolutionsSpec.scala index db172ab4349..389aa884c91 100644 --- a/persistence/play-jdbc-evolutions/src/test/scala/play/api/db/evolutions/EvolutionsSpec.scala +++ b/persistence/play-jdbc-evolutions/src/test/scala/play/api/db/evolutions/EvolutionsSpec.scala @@ -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 @@ -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 { @@ -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));",