34

I started to use Flyway in my current project for database migrations and I like it very much. I currently use Oracle in PROD- and Derby in TEST-Environment.

Pretty soon, I did run in the problem of database specific sql commands, e.g.

  • ALTER TABLE T1 MODIFY F1 VARCHAR(256); on Oracle vs
  • ALTER TABLE T1 ALTER F1 SET DATA TYPE VARCHAR(256); on Derby.

I can't see a way to write a "vendor neutral alter table modify column datatype" sql.

What's the best way to deal with this problem using Flyway?

2 Answers 2

42

You can use the flyway.locations property.

In test in would look like this:

flyway.locations=sql/common,sql/derby

and in prod:

flyway.locations=sql/common,sql/oracle

You could then have the common statements (V1__Create_table.sql) in common and different copies of the DB-specific statements (V2__Alter_table.sql) in the db-specific locations.

An even better solution, in my opinion, is to have the same DB in prod and test. Yes, you do lose a bit of performance, but on the other hand you also eliminate another difference (and potential source of errors) between the environments.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Axel for the fast reply!
Probably worth putting somewhere in the flyway FAQ?
Axel's solution from above works fine. I found one tiny issue to be aware of: I used flyway.locations=db/migration/common,db/migration/oracle and flyway.locations=db/migration/common,db/migration/derby and this messes up with the deprecated "baseDir" to one large merged "db/migration".
You are correct. This is unfortunate, but will be resolved by itself with 3.0 once all the deprecated stuff will be removed.
The fix is now checked in.
|
1

The differences in SQL between Oracle and some of these desktop databases is minor. Is it possible for a developer to insert custom code to do some light-weight dynamic stripping of the SQL at runtime based on the environment (e.g. remove tablespace designation)?

I prefer this approach to relying on each developer to manually keep two sets of SQL in sync.

2 Comments

You should ask this as a separate question. It's an interesting idea.
good idea Pei - created question: stackoverflow.com/questions/32121083/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.