Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quoting of table names and fk in ALTER TABLE for MySQL
Closes #1471: Drop / dropStatements for MySQL are not escaping reserved words (like "order")
- Loading branch information
1 parent
3a50a33
commit 1f49326
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
slick-testkit/src/test/scala/slick/test/lifted/MySQLDDLTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package slick.test.lifted | ||
|
||
import org.junit.Test | ||
import org.junit.Assert._ | ||
|
||
/** Test case for the MySQL SQL DDL overrides */ | ||
class MysqlDDLTest { | ||
import slick.jdbc.MySQLProfile.api._ | ||
|
||
@Test def testTablenameEscaped { | ||
class T(tag: Tag) extends Table[Int](tag, "mytable") { | ||
def id = column[Int]("id", O.PrimaryKey) | ||
|
||
def * = id | ||
} | ||
val ts = TableQuery[T] | ||
|
||
class T2(tag: Tag) extends Table[Int](tag, "mytable2") { | ||
def id = column[Int]("id", O.PrimaryKey) | ||
|
||
def testFk = column[Int]("test_fk") | ||
def fk = foreignKey("t_test_fk", testFk, ts)(_.id) | ||
|
||
def * = id | ||
} | ||
val ts2 = TableQuery[T2] | ||
|
||
val s1 = ts2.schema.createStatements.toList | ||
assertTrue("DDL (create) must contain any SQL statements", s1.nonEmpty) | ||
s1.foreach(s => assertTrue("DDL (create) uses escaped table name: " + s, s contains "`mytable2`")) | ||
assertTrue("Fk name must be escaped", s1.exists(_.contains("`t_test_fk`"))) | ||
|
||
val s2 = ts2.schema.dropStatements.toList | ||
s2.foreach(s => assertTrue("DDL (drop) uses escaped table name: " + s, s contains "`mytable2`")) | ||
assertTrue("Fk name must be escaped", s2.exists(_.contains("`t_test_fk`"))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters