Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way for "database specific" sql scripts with Flyway

Tags:

flyway

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?

like image 317
Peti Avatar asked Nov 28 '12 16:11

Peti


People also ask

Does Flyway support multiple databases?

During development you need a fast, automated way to build multiple copies of a database on any development or test server, with each database at the right version.

What databases are supported in Flyway?

Supported databases are Oracle, SQL Server (including Amazon RDS and Azure SQL Database), Azure Synapse (Formerly Data Warehouse), DB2, MySQL (including Amazon RDS, Azure Database & Google Cloud SQL), Aurora MySQL, MariaDB, Percona XtraDB Cluster, TestContainers, PostgreSQL (including Amazon RDS, Azure Database, Google ...

Which is better Flyway or Liquibase?

While both tools are based on Martin Fowler's Evolutionary Database, there are many differences in what these tools offer. Here's where Liquibase and Flyway differ. The bottom line is that Liquibase is more powerful and flexible — covering more database change and deployment use cases than Flyway.


1 Answers

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.

like image 173
Axel Fontaine Avatar answered Oct 06 '22 00:10

Axel Fontaine