1313 */
1414package io .zonky .test .db .postgres .embedded ;
1515
16- import java .sql .SQLException ;
17- import java .util .Arrays ;
18- import java .util .List ;
19- import java .util .Objects ;
20-
21- import javax .sql .DataSource ;
22-
2316import org .apache .commons .lang3 .reflect .MethodUtils ;
2417import org .flywaydb .core .Flyway ;
2518import org .flywaydb .core .api .configuration .FluentConfiguration ;
2619
27- // TODO: Detect missing migration files.
28- // cf. https://github.com/flyway/flyway/issues/1496
29- // There is also a related @Ignored test in otj-sql.
20+ import javax .sql .DataSource ;
21+ import java .sql .SQLException ;
22+ import java .util .Arrays ;
23+ import java .util .HashMap ;
24+ import java .util .List ;
25+ import java .util .Map ;
26+ import java .util .Objects ;
3027
3128public final class FlywayPreparer implements DatabasePreparer {
3229
3330 private final FluentConfiguration configuration ;
3431 private final List <String > locations ;
32+ private final Map <String , String > properties ;
3533
34+ /**
35+ * Creates a new instance of the preparer with the specified locations of migrations.
36+ */
3637 public static FlywayPreparer forClasspathLocation (String ... locations ) {
3738 FluentConfiguration config = Flyway .configure ().locations (locations );
38- return new FlywayPreparer (config , Arrays .asList (locations ));
39+ return new FlywayPreparer (config , Arrays .asList (locations ), null );
3940 }
4041
41- private FlywayPreparer (FluentConfiguration configuration , List <String > locations ) {
42+ /**
43+ * Creates a new instance of the preparer with the specified configuration properties.
44+ *
45+ * <p>Example of use:
46+ * <pre> {@code
47+ * FlywayPreparer preparer = FlywayPreparer.fromConfiguration(Map.of(
48+ * "flyway.locations", "db/migration",
49+ * "flyway.postgresql.transactional.lock", "false"));
50+ * }</pre>
51+ *
52+ * A list of all available configuration properties can be found <a href='https://flywaydb.org/documentation/configuration/configfile.html'>here</a>.
53+ */
54+ public static FlywayPreparer fromConfiguration (Map <String , String > configuration ) {
55+ FluentConfiguration config = Flyway .configure ().configuration (configuration );
56+ return new FlywayPreparer (config , null , new HashMap <>(configuration ));
57+ }
58+
59+ private FlywayPreparer (FluentConfiguration configuration , List <String > locations , Map <String , String > properties ) {
4260 this .configuration = configuration ;
4361 this .locations = locations ;
62+ this .properties = properties ;
4463 }
4564
4665 @ Override
@@ -55,15 +74,15 @@ public void prepare(DataSource ds) throws SQLException {
5574 }
5675
5776 @ Override
58- public boolean equals (Object obj ) {
59- if (! ( obj instanceof FlywayPreparer )) {
60- return false ;
61- }
62- return Objects .equals (locations , (( FlywayPreparer ) obj ). locations );
77+ public boolean equals (Object o ) {
78+ if (this == o ) return true ;
79+ if ( o == null || getClass () != o . getClass ()) return false ;
80+ FlywayPreparer that = ( FlywayPreparer ) o ;
81+ return Objects .equals (locations , that . locations ) && Objects . equals ( properties , that . properties );
6382 }
6483
6584 @ Override
6685 public int hashCode () {
67- return Objects .hashCode (locations );
86+ return Objects .hash (locations , properties );
6887 }
6988}
0 commit comments