0

So, in my project I have used application.properties file. I have three questions here. 1) I provided spring datasource properties like below.

spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/abc
spring.datasource.username = 
spring.datasource.password =

Even without providing flyway properties i.e., flyway.url my application is able to run successfully. How is it possible? Flyway does not require it when spring properties are provided?

2) For other properties of flyway I use it works only like below

spring.flyway.table=version_history 

but it does not work for spring.flyway.defaultSchema=trial. No idea on this.

3) How to achieve migrations for multiple schemas. Any example?

TomStroemer
  • 1,390
  • 8
  • 28
Guest_123
  • 31
  • 1
  • 4

2 Answers2

0

migrating multiple schema can be achieved using a Datasource which has access to the various schema (ie has the necessary grants for all schemas). In the DB migration files the SQL statements can then refer to the different schema to insert/update/delete/etc..

The result is a single table (history) with all changes across all the schema.

Schema names do not need to be hardcoded in the SQL files, but you can conveniently use a placeholder (create table ${schemaname}.TABLE_NAME)

Beppe C
  • 11,256
  • 2
  • 19
  • 41
0

Answering the questions that you specified in your post:

(1) Flyway autowires the Datasource that you specified for spring and uses that for migrations. See: https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/reference/html/howto-database-initialization.html#howto-execute-flyway-database-migrations-on-startup

(2) If you are using spring-boot then this property (defaultSchema) did not exist prior to v2.3.x - that might be the problem that you were experiencing.

(3) The following article contains a few examples on how to achieve this in different use-cases: https://flywaydb.org/blog/multipleschemas

S. D.
  • 788
  • 5
  • 15