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

Merged
merged 1 commit into from Mar 14, 2018

Conversation

Projects
None yet
3 participants
@trevorsibanda
Copy link
Collaborator

trevorsibanda commented Mar 12, 2017

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 trevorsibanda:add-ddl-feature-createifnotexists-dropifexists branch 13 times, most recently from 99a5e81 to 07dd153 Mar 14, 2017

_ <- (as += (1, 1, "a11-conflict")).failed
_ <- as.schema.drop
} yield ()
}

This comment has been minimized.

@cvogt

cvogt Mar 16, 2017

Member

@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 trevorsibanda:add-ddl-feature-createifnotexists-dropifexists branch 7 times, most recently from ab37065 to ed69a2f Mar 17, 2017

@trevorsibanda trevorsibanda force-pushed the trevorsibanda:add-ddl-feature-createifnotexists-dropifexists branch from 891d929 to 4a45bae Mar 25, 2017

@@ -61,6 +67,8 @@ trait OracleProfile extends JdbcProfile {

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

This comment has been minimized.

@cvogt

cvogt Mar 26, 2017

Member

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

This comment has been minimized.

@cvogt

cvogt Mar 26, 2017

Member

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).

This comment has been minimized.

@trevorsibanda

trevorsibanda Mar 28, 2017

Author Collaborator

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

This comment has been minimized.

@cvogt

cvogt Mar 28, 2017

Member

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

This comment has been minimized.

Copy link
Member

cvogt commented Mar 26, 2017

really cool stuff :)!

@trevorsibanda trevorsibanda force-pushed the trevorsibanda:add-ddl-feature-createifnotexists-dropifexists branch 2 times, most recently from 6256e46 to a5f500b Mar 28, 2017

@@ -89,6 +97,8 @@ trait DerbyProfile extends JdbcProfile {
- JdbcCapabilities.booleanMetaData
- JdbcCapabilities.supportsByte
- RelationalCapabilities.repeat
- RelationalCapabilities.createIfNotExists
- RelationalCapabilities.dropIfExists

This comment has been minimized.

@cvogt

cvogt Apr 15, 2017

Member

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 trevorsibanda:add-ddl-feature-createifnotexists-dropifexists branch from a5f500b to 93e1507 Apr 15, 2017

@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 trevorsibanda:add-ddl-feature-createifnotexists-dropifexists branch from 93e1507 to a67a880 Aug 18, 2017

@trevorsibanda trevorsibanda force-pushed the trevorsibanda:add-ddl-feature-createifnotexists-dropifexists branch from a67a880 to 327e81c Aug 18, 2017

Implemented createIfNotExists and dropIfExists schema methods
  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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Collaborator Author

trevorsibanda commented Mar 7, 2018

@hvesalai Yes it is.

@hvesalai

This comment has been minimized.

Copy link
Member

hvesalai commented Mar 7, 2018

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

@hvesalai hvesalai merged commit e664007 into slick:master Mar 14, 2018

4 checks passed

ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
typesafe-cla-validator All users have signed the CLA
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment