Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed MySQLProfile drop SQL commands to use qualified schema+table names #1898

Closed

Conversation

NicolasRouquette
Copy link

Fixes #1897

@hvesalai hvesalai added this to the 3.3 milestone Apr 23, 2018
@hvesalai
Copy link
Member

@NicolasRouquette Could you also add a test case that failes without the change and then works with it.

@djx314
Copy link
Contributor

djx314 commented Apr 23, 2018

@NicolasRouquette What will happen if I jsut define the tablename and I didn‘t defined the schema name? I have to avoid to define schema in my codegen script in my code. And what will it happen?

@NicolasRouquette
Copy link
Author

@djx314 The fix ensures that SQL statements produced for dropping foreign keys use the same qualified name mechanism as that used for producing other kinds of SQL statements (e.g., create/drop table). So, if you use unqualified table names without a schema name, then all SQL statements should be correspondingly unqualified table names as before. The fix does not change this behavior.

@NicolasRouquette
Copy link
Author

@hvesalai I'm converting my example (https://github.com/NicolasRouquette/MySQLSlickTest) into a new unit test: com.typesafe.slick.testkit.tests.MySQLQualifiedExtraTests (in response to #1898 ) and com.typesafe.slick.testkit.tests.MySQLUnqualifiedExtraTests (to confirm that fixing #1898 will not affect @djx314 ).

- Reverted the fix for slick#1898 to force MySQLQualifiedExtraTests to fail
- Updated ForeignKeyTest to drop schema tables
  (if run on MySQL, it would be MySQLUnqualifiedExtraTests)
- Removed duplicate drop in ForeignKeyTest
@NicolasRouquette
Copy link
Author

@hvesalai The test could be much simpler than I though.

I am refactoring ForeignKeyTest as an abstract class with two variants:

abstract class ForeignKeyTest(schema: Option[String]) extends AsyncTest[RelationalTestDB] {
  import tdb.profile.api._

  def testSimple = {
    class Categories(tag: Tag) extends Table[(Int, String)](tag, schema,"categories") {
    ...
    }
 ...
}

class QualifiedForeignKeyTest extends ForeignKeyTest(Some("slick_test"))

class UnqualifiedForeignKeyTest extends ForeignKeyTest(None)

Hopefully, this will work to demonstrate the bug.

@hvesalai
Copy link
Member

hvesalai commented Apr 23, 2018

Looks, good, but now you pushed the revert of the fix also... can you rebase and rework (see documentation of git rebase -i) the four commits so there are only two:

  • commit 1: tests that demonstrate the bug
  • commit 2: the fix

You can then force push the result to replace the commits now in this PR with these two.

@NicolasRouquette
Copy link
Author

@hvesalai I'll rewrite the history after I manage to get the qualified tests to fail as intended.

I have problems creating SQL statements for create/drop schema.


  def createSchemaIfQualified(): DBIO[Unit] = schema.fold[DBIO[Unit]] {
    SuccessAction(())
  } { s =>
    // It should be possible to write instead: sql"create schema `${s}`;"
    // Unfortunately, this results in: "create schema `?`;"
    val action = SQLActionBuilder(s"create schema `${s}`;", SetParameter.SetUnit)
    DBIO.seq(action.as[Unit])
  }

  def dropSchemaIfQualified(): DBIO[Unit] = schema.fold[DBIO[Unit]] {
    SuccessAction(())
  } { s =>
    // It should be possible to write instead: sql"drop schema `${s}`;"
    // Unfortunately, this results in: "drop schema `?`;"
    val action = SQLActionBuilder(s"drop schema `${s}`;", SetParameter.SetUnit)
    DBIO.seq(action.as[Unit])
  }

How should it be written so that it produces SQL statements like this: create schema `mysql_test`; ?

@hvesalai
Copy link
Member

Why can't use use sql interpolation or StaticQuery.updateNA

@NicolasRouquette
Copy link
Author

All the QualifiedForeignKey tests fail. Looking at the test failures, there is no common syntax for creating a database (aka schema) that will work across all implementations. It seems that slick would have to add support for this and specify in an implementation specific profile the corresponding syntax for the SQL statement(s) to produce.

@hvesalai
Copy link
Member

@NicolasRouquette there are some test cases failing now. Do you have time to check it out and try to fix the code.

@hvesalai
Copy link
Member

@NicolasRouquette I'm going throught the PRs that I will include in the next 3.3. release. Do you think this could make it, i.e. can it be fixed?

@NicolasRouquette
Copy link
Author

@hvesalai Sorry for the delay in responding.

The fix is really simple; unfortunately, making a test that demonstrates the problem is more difficult because this seems to be the first time that there is a test involving "create/drop schema/table"
and these SQL statements clearly vary across implementations.

I'm not sure how to proceed.

@hvesalai
Copy link
Member

hvesalai commented Oct 8, 2018

@NicolasRouquette do you think this can be closed in favor of #1928 by @smootoo

@hvesalai hvesalai modified the milestones: 3.3, Future fix release Jan 29, 2019
@hvesalai
Copy link
Member

This might now be obsolete.

@smootoo
Copy link
Contributor

smootoo commented Jan 29, 2019

Agreed. I think this can be closed now, so I'm going to close it. Please re-open, if required.

@smootoo smootoo closed this Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants