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

Add schema feature createIfNotExists and dropIfExists #1704

Conversation

trevorsibanda
Copy link
Contributor

Addresses points discussed in #93

Adds methods createIfNotExists and dropIfExists

val ts = TableQuery[T]
val ts2 = TableQuery[S]
ts.schema.createIfNotExists
ts.schema.dropIfExists
(ts.schema ++ ts2.schema).createIfNotExists

Issues now

  • Some dbms don't support IF NOT EXISTS either in create, drop or both statements. (DB2, Derby, Sqlserver - cause of failing tests).
  • Consecutive calls to createIfNotExists fail if the table definition has a foreign key.

@trevorsibanda trevorsibanda force-pushed the add-ddl-feature-createifnotexists-dropifexists branch 13 times, most recently from 99a5e81 to 07dd153 Compare March 15, 2017 13:34
_ <- (as += (1, 1, "a11-conflict")).failed
_ <- as.schema.drop
} yield ()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trevorsibanda maybe you can split this test into multiple smaller ones, so it will be easier to narrow down where stuff goes wrong? Unfortunately both future and DBIO kill the usefulness of stacktraces

@trevorsibanda trevorsibanda force-pushed the add-ddl-feature-createifnotexists-dropifexists branch 7 times, most recently from ab37065 to ed69a2f Compare March 21, 2017 08:45
@trevorsibanda trevorsibanda force-pushed the add-ddl-feature-createifnotexists-dropifexists branch from 891d929 to 4a45bae Compare March 25, 2017 07:37
@@ -61,6 +67,8 @@ trait OracleProfile extends JdbcProfile {

override protected def computeCapabilities: Set[Capability] = (super.computeCapabilities
- RelationalCapabilities.foreignKeyActions
- RelationalCapabilities.createIfNotExists
- RelationalCapabilities.dropIfExists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused. It looks like you added this feature to Oracle, but this says Oracle doesn't support this. Is this a mistake?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The - here means you are removing these capabilities from the set of supported capabilities for this driver, which seems to be inaccurate. (Same for the other drivers, where you implemented the feature).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cvogt Thanks... I should change that and also update the others, only DerbyProfile should have these removed since it uses a client side implementation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think client side implementation is fine. The flags just identify if Slick is able to do this using whatever method. So I don't think we need to remove them. In fact it sounds like we can get rid of them. Back then I only suggested them as an alternative in case it was impossible to do with one of the drivers.

@cvogt
Copy link
Member

cvogt commented Mar 26, 2017

really cool stuff :)!

@trevorsibanda trevorsibanda force-pushed the add-ddl-feature-createifnotexists-dropifexists branch 2 times, most recently from 6256e46 to a5f500b Compare March 28, 2017 12:47
@@ -89,6 +97,8 @@ trait DerbyProfile extends JdbcProfile {
- JdbcCapabilities.booleanMetaData
- JdbcCapabilities.supportsByte
- RelationalCapabilities.repeat
- RelationalCapabilities.createIfNotExists
- RelationalCapabilities.dropIfExists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does removing the capabilities here make sense? Looks like you added support below, so now the driver actually has this capability. No?

@trevorsibanda trevorsibanda force-pushed the add-ddl-feature-createifnotexists-dropifexists branch from a5f500b to 93e1507 Compare April 15, 2017 19:17
@trevorsibanda trevorsibanda changed the title WIP: Add schema feature createIfNotExists and dropIfExists Add schema feature createIfNotExists and dropIfExists Apr 19, 2017
@trevorsibanda trevorsibanda force-pushed the add-ddl-feature-createifnotexists-dropifexists branch from 93e1507 to a67a880 Compare August 18, 2017 10:51
@trevorsibanda trevorsibanda force-pushed the add-ddl-feature-createifnotexists-dropifexists branch from a67a880 to 327e81c Compare August 18, 2017 11:16
  Added IF (NOT) EXISTS support for SQLServer
  Added IF (NOT) EXISTS support for IBM DB2
  Added IF (NOT) EXISTS support for Oracle
  Added IF (NOT) EXISTS emulation for Derby
  Added test cases for createIfNotExists and dropIfExists
@hvesalai hvesalai added this to the Next feature release milestone Feb 28, 2018
@hvesalai
Copy link
Member

hvesalai commented Mar 7, 2018

@trevorsibanda is this ready for merge?

@hvesalai hvesalai modified the milestones: Future feature release, 3.3 Mar 7, 2018
@trevorsibanda
Copy link
Contributor Author

@hvesalai Yes it is.

@hvesalai
Copy link
Member

hvesalai commented Mar 7, 2018

I think this is great. It resolves my feature request from 2013 #93

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

3 participants