/
FluentConfiguration.java
951 lines (850 loc) · 37.1 KB
/
FluentConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
/*
* Copyright 2010-2018 Boxfuse GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flywaydb.core.api.configuration;
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.FlywayException;
import org.flywaydb.core.api.Location;
import org.flywaydb.core.api.MigrationVersion;
import org.flywaydb.core.api.callback.Callback;
import org.flywaydb.core.api.errorhandler.ErrorHandler;
import org.flywaydb.core.api.resolver.MigrationResolver;
import javax.sql.DataSource;
import java.io.File;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.Properties;
/**
* Fluent configuration for Flyway. This is the preferred means of configuring the Flyway API.
* <p>
* This configuration can be passed to Flyway using the <code>new Flyway(Configuration)</code> constructor.
* </p>
*/
public class FluentConfiguration implements Configuration {
private final ClassicConfiguration config;
/**
* Creates a new default configuration.
*/
public FluentConfiguration() {
config = new ClassicConfiguration();
}
/**
* Creates a new default configuration with this class loader.
*
* @param classLoader The ClassLoader to use for loading migrations, resolvers, etc from the classpath. (default: Thread.currentThread().getContextClassLoader() )
*/
public FluentConfiguration(ClassLoader classLoader) {
config = new ClassicConfiguration(classLoader);
}
/**
* Loads this configuration into a new Flyway instance.
*
* @return The new fully-configured Flyway instance.
*/
public Flyway load() {
return new Flyway(this);
}
/**
* Configure with the same values as this existing configuration.
*
* @param configuration The configuration to use.
*/
public FluentConfiguration configure(Configuration configuration) {
config.configure(configuration);
return this;
}
@Override
public Location[] getLocations() {
return config.getLocations();
}
@Override
public Charset getEncoding() {
return config.getEncoding();
}
@Override
public String[] getSchemas() {
return config.getSchemas();
}
@Override
public String getTable() {
return config.getTable();
}
@Override
public MigrationVersion getTarget() {
return config.getTarget();
}
@Override
public boolean isPlaceholderReplacement() {
return config.isPlaceholderReplacement();
}
@Override
public Map<String, String> getPlaceholders() {
return config.getPlaceholders();
}
@Override
public String getPlaceholderPrefix() {
return config.getPlaceholderPrefix();
}
@Override
public String getPlaceholderSuffix() {
return config.getPlaceholderSuffix();
}
@Override
public String getSqlMigrationPrefix() {
return config.getSqlMigrationPrefix();
}
@Override
public String getRepeatableSqlMigrationPrefix() {
return config.getRepeatableSqlMigrationPrefix();
}
@Override
public String getSqlMigrationSeparator() {
return config.getSqlMigrationSeparator();
}
@Override
public String[] getSqlMigrationSuffixes() {
return config.getSqlMigrationSuffixes();
}
@Override
public boolean isIgnoreMissingMigrations() {
return config.isIgnoreMissingMigrations();
}
@Override
public boolean isIgnoreIgnoredMigrations() {
return config.isIgnoreIgnoredMigrations();
}
@Override
public boolean isIgnorePendingMigrations() {
return config.isIgnorePendingMigrations();
}
@Override
public boolean isIgnoreFutureMigrations() {
return config.isIgnoreFutureMigrations();
}
@Override
public boolean isValidateOnMigrate() {
return config.isValidateOnMigrate();
}
@Override
public boolean isCleanOnValidationError() {
return config.isCleanOnValidationError();
}
@Override
public boolean isCleanDisabled() {
return config.isCleanDisabled();
}
@Override
public MigrationVersion getBaselineVersion() {
return config.getBaselineVersion();
}
@Override
public String getBaselineDescription() {
return config.getBaselineDescription();
}
@Override
public boolean isBaselineOnMigrate() {
return config.isBaselineOnMigrate();
}
@Override
public boolean isOutOfOrder() {
return config.isOutOfOrder();
}
@Override
public MigrationResolver[] getResolvers() {
return config.getResolvers();
}
@Override
public boolean isSkipDefaultResolvers() {
return config.isSkipDefaultResolvers();
}
@Override
public DataSource getDataSource() {
return config.getDataSource();
}
@Override
public ClassLoader getClassLoader() {
return config.getClassLoader();
}
@Override
public boolean isMixed() {
return config.isMixed();
}
@Override
public String getInstalledBy() {
return config.getInstalledBy();
}
@Override
public boolean isGroup() {
return config.isGroup();
}
@Override
public ErrorHandler[] getErrorHandlers() {
return config.getErrorHandlers();
}
@Override
public String[] getErrorOverrides() {
return config.getErrorOverrides();
}
@Override
public OutputStream getDryRunOutput() {
return config.getDryRunOutput();
}
@Override
public boolean isStream() {
return config.isStream();
}
@Override
public boolean isBatch() {
return config.isBatch();
}
@Override
public boolean isOracleSqlplus() {
return config.isOracleSqlplus();
}
@Override
public String getLicenseKey() {
return config.getLicenseKey();
}
/**
* Sets the stream where to output the SQL statements of a migration dry run. {@code null} to execute the SQL statements
* directly against the database. The stream when be closing when Flyway finishes writing the output.
* <p><i>Flyway Pro and Flyway Enterprise only</i></p>
*
* @param dryRunOutput The output file or {@code null} to execute the SQL statements directly against the database.
*/
public FluentConfiguration dryRunOutput(OutputStream dryRunOutput) {
config.setDryRunOutput(dryRunOutput);
return this;
}
/**
* Sets the file where to output the SQL statements of a migration dry run. {@code null} to execute the SQL statements
* directly against the database. If the file specified is in a non-existent directory, Flyway will create all
* directories and parent directories as needed.
* <p><i>Flyway Pro and Flyway Enterprise only</i></p>
*
* @param dryRunOutput The output file or {@code null} to execute the SQL statements directly against the database.
*/
public FluentConfiguration dryRunOutput(File dryRunOutput) {
config.setDryRunOutputAsFile(dryRunOutput);
return this;
}
/**
* Sets the file where to output the SQL statements of a migration dry run. {@code null} to execute the SQL statements
* directly against the database. If the file specified is in a non-existent directory, Flyway will create all
* directories and parent directories as needed.
* <p><i>Flyway Pro and Flyway Enterprise only</i></p>
*
* @param dryRunOutputFileName The name of the output file or {@code null} to execute the SQL statements directly
* against the database.
*/
public FluentConfiguration dryRunOutput(String dryRunOutputFileName) {
config.setDryRunOutputAsFileName(dryRunOutputFileName);
return this;
}
/**
* Handlers for errors and warnings that occur during a migration. This can be used to customize Flyway's behavior by for example
* throwing another runtime exception, outputting a warning or suppressing the error instead of throwing a FlywayException.
* ErrorHandlers are invoked in order until one reports to have successfully handled the errors or warnings.
* If none do, or if none are present, Flyway falls back to its default handling of errors and warnings.
* <p><i>Flyway Pro and Flyway Enterprise only</i></p>
*
* @param errorHandlers The ErrorHandlers or an empty array if the default internal handler should be used instead. (default: none)
* @deprecated ErrorHandlers have been deprecated and will be removed in Flyway 6.0 use statement-level callbacks instead.
*/
@Deprecated
public FluentConfiguration errorHandlers(ErrorHandler... errorHandlers) {
config.setErrorHandlers(errorHandlers);
return this;
}
/**
* Handlers for errors and warnings that occur during a migration. This can be used to customize Flyway's behavior by for example
* throwing another runtime exception, outputting a warning or suppressing the error instead of throwing a FlywayException.
* ErrorHandlers are invoked in order until one reports to have successfully handled the errors or warnings.
* If none do, or if none are present, Flyway falls back to its default handling of errors and warnings.
* <p><i>Flyway Pro and Flyway Enterprise only</i></p>
*
* @param errorHandlerClassNames The fully qualified class names of ErrorHandlers or an empty array if the default
* internal handler should be used instead. (default: none)
* @deprecated ErrorHandlers have been deprecated and will be removed in Flyway 6.0 use statement-level callbacks instead.
*/
@Deprecated
public FluentConfiguration errorHandlers(String... errorHandlerClassNames) {
config.setErrorHandlersAsClassNames(errorHandlerClassNames);
return this;
}
/**
* Rules for the built-in error handler that lets you override specific SQL states and errors codes from error
* to warning or from warning to error.
* <p>Each error override has the following format: {@code STATE:12345:W}.
* It is a 5 character SQL state, a colon, the SQL error code, a colon and finally the desired
* behavior that should override the initial one. The following behaviors are accepted: {@code W} to force a warning
* and {@code E} to force an error.</p>
* <p>For example, to force Oracle stored procedure compilation issues to produce
* errors instead of warnings, the following errorOverride can be used: {@code 99999:17110:E}</p>
* <p><i>Flyway Pro and Flyway Enterprise only</i></p>
*
* @param errorOverrides The ErrorOverrides or an empty array if none are defined. (default: none)
*/
public FluentConfiguration errorOverrides(String... errorOverrides) {
config.setErrorOverrides(errorOverrides);
return this;
}
/**
* Whether to group all pending migrations together in the same transaction when applying them (only recommended for databases with support for DDL transactions).
*
* @param group {@code true} if migrations should be grouped. {@code false} if they should be applied individually instead. (default: {@code false})
*/
public FluentConfiguration group(boolean group) {
config.setGroup(group);
return this;
}
/**
* The username that will be recorded in the schema history table as having applied the migration.
*
* @param installedBy The username or {@code null} for the current database user of the connection. (default: {@code null}).
*/
public FluentConfiguration installedBy(String installedBy) {
config.setInstalledBy(installedBy);
return this;
}
/**
* Whether to allow mixing transactional and non-transactional statements within the same migration.
*
* @param mixed {@code true} if mixed migrations should be allowed. {@code false} if an error should be thrown instead. (default: {@code false})
*/
public FluentConfiguration mixed(boolean mixed) {
config.setMixed(mixed);
return this;
}
/**
* Ignore missing migrations when reading the schema history table. These are migrations that were performed by an
* older deployment of the application that are no longer available in this version. For example: we have migrations
* available on the classpath with versions 1.0 and 3.0. The schema history table indicates that a migration with version 2.0
* (unknown to us) has also been applied. Instead of bombing out (fail fast) with an exception, a
* warning is logged and Flyway continues normally. This is useful for situations where one must be able to deploy
* a newer version of the application even though it doesn't contain migrations included with an older one anymore.
* Note that if the most recently applied migration is removed, Flyway has no way to know it is missing and will
* mark it as future instead.
*
* @param ignoreMissingMigrations {@code true} to continue normally and log a warning, {@code false} to fail fast with an exception.
* (default: {@code false})
*/
public FluentConfiguration ignoreMissingMigrations(boolean ignoreMissingMigrations) {
config.setIgnoreMissingMigrations(ignoreMissingMigrations);
return this;
}
/**
* Ignore ignored migrations when reading the schema history table. These are migrations that were added in between
* already migrated migrations in this version. For example: we have migrations available on the classpath with
* versions from 1.0 to 3.0. The schema history table indicates that version 1 was finished on 1.0.15, and the next
* one was 2.0.0. But with the next release a new migration was added to version 1: 1.0.16. Such scenario is ignored
* by migrate command, but by default is rejected by validate. When ignoreIgnoredMigrations is enabled, such case
* will not be reported by validate command. This is useful for situations where one must be able to deliver
* complete set of migrations in a delivery package for multiple versions of the product, and allows for further
* development of older versions.
*
* @param ignoreIgnoredMigrations {@code true} to continue normally, {@code false} to fail fast with an exception.
* (default: {@code false})
*/
public FluentConfiguration ignoreIgnoredMigrations(boolean ignoreIgnoredMigrations) {
config.setIgnoreIgnoredMigrations(ignoreIgnoredMigrations);
return this;
}
/**
* Ignore pending migrations when reading the schema history table. These are migrations that are available on the
* classpath but have not yet been performed by an application deployment. This can be useful for verifying
* that in-development migration changes don't contain any validation-breaking changes of migrations that have
* already been applied to a production environment, e.g. as part of a CI/CD process, without failing because of the
* existence of new migration versions.
*
* @param ignorePendingMigrations {@code true} to continue normally, {@code false} to fail fast with an exception.
* (default: {@code false})
*/
public FluentConfiguration ignorePendingMigrations(boolean ignorePendingMigrations) {
config.setIgnorePendingMigrations(ignorePendingMigrations);
return this;
}
/**
* Whether to ignore future migrations when reading the schema history table. These are migrations that were performed by a
* newer deployment of the application that are not yet available in this version. For example: we have migrations
* available on the classpath up to version 3.0. The schema history table indicates that a migration to version 4.0
* (unknown to us) has already been applied. Instead of bombing out (fail fast) with an exception, a
* warning is logged and Flyway continues normally. This is useful for situations where one must be able to redeploy
* an older version of the application after the database has been migrated by a newer one.
*
* @param ignoreFutureMigrations {@code true} to continue normally and log a warning, {@code false} to fail
* fast with an exception. (default: {@code true})
*/
public FluentConfiguration ignoreFutureMigrations(boolean ignoreFutureMigrations) {
config.setIgnoreFutureMigrations(ignoreFutureMigrations);
return this;
}
/**
* Whether to automatically call validate or not when running migrate.
*
* @param validateOnMigrate {@code true} if validate should be called. {@code false} if not. (default: {@code true})
*/
public FluentConfiguration validateOnMigrate(boolean validateOnMigrate) {
config.setValidateOnMigrate(validateOnMigrate);
return this;
}
/**
* Whether to automatically call clean or not when a validation error occurs.
* <p> This is exclusively intended as a convenience for development. Even tough we
* strongly recommend not to change migration scripts once they have been checked into SCM and run, this provides a
* way of dealing with this case in a smooth manner. The database will be wiped clean automatically, ensuring that
* the next migration will bring you back to the state checked into SCM.</p>
* <p><b>Warning ! Do not enable in production !</b></p>
*
* @param cleanOnValidationError {@code true} if clean should be called. {@code false} if not. (default: {@code false})
*/
public FluentConfiguration cleanOnValidationError(boolean cleanOnValidationError) {
config.setCleanOnValidationError(cleanOnValidationError);
return this;
}
/**
* Whether to disable clean.
* <p>This is especially useful for production environments where running clean can be quite a career limiting move.</p>
*
* @param cleanDisabled {@code true} to disabled clean. {@code false} to leave it enabled. (default: {@code false})
*/
public FluentConfiguration cleanDisabled(boolean cleanDisabled) {
config.setCleanDisabled(cleanDisabled);
return this;
}
/**
* Sets the locations to scan recursively for migrations.
* <p>The location type is determined by its prefix.
* Unprefixed locations or locations starting with {@code classpath:} point to a package on the classpath and may
* contain both sql and java-based migrations.
* Locations starting with {@code filesystem:} point to a directory on the filesystem and may only contain sql
* migrations.</p>
*
* @param locations Locations to scan recursively for migrations. (default: db/migration)
*/
public FluentConfiguration locations(String... locations) {
config.setLocationsAsStrings(locations);
return this;
}
/**
* Sets the locations to scan recursively for migrations.
* <p>The location type is determined by its prefix.
* Unprefixed locations or locations starting with {@code classpath:} point to a package on the classpath and may
* contain both sql and java-based migrations.
* Locations starting with {@code filesystem:} point to a directory on the filesystem and may only contain sql
* migrations.</p>
*
* @param locations Locations to scan recursively for migrations. (default: db/migration)
*/
public FluentConfiguration locations(Location... locations) {
config.setLocations(locations);
return this;
}
/**
* Sets the encoding of Sql migrations.
*
* @param encoding The encoding of Sql migrations. (default: UTF-8)
*/
public FluentConfiguration encoding(String encoding) {
config.setEncodingAsString(encoding);
return this;
}
/**
* Sets the encoding of Sql migrations.
*
* @param encoding The encoding of Sql migrations. (default: UTF-8)
*/
public FluentConfiguration encoding(Charset encoding) {
config.setEncoding(encoding);
return this;
}
/**
* Sets the schemas managed by Flyway. These schema names are case-sensitive. (default: The default schema for the datasource connection)
* <p>Consequences:</p>
* <ul>
* <li>The first schema in the list will be automatically set as the default one during the migration.</li>
* <li>The first schema in the list will also be the one containing the schema history table.</li>
* <li>The schemas will be cleaned in the order of this list.</li>
* </ul>
*
* @param schemas The schemas managed by Flyway. May not be {@code null}. Must contain at least one element.
*/
public FluentConfiguration schemas(String... schemas) {
config.setSchemas(schemas);
return this;
}
/**
* <p>Sets the name of the schema schema history table that will be used by Flyway.</p><p> By default (single-schema mode)
* the schema history table is placed in the default schema for the connection provided by the datasource. </p> <p> When
* the <i>flyway.schemas</i> property is set (multi-schema mode), the schema history table is placed in the first schema
* of the list. </p>
*
* @param table The name of the schema schema history table that will be used by flyway. (default: flyway_schema_history)
*/
public FluentConfiguration table(String table) {
config.setTable(table);
return this;
}
/**
* Sets the target version up to which Flyway should consider migrations. Migrations with a higher version number will
* be ignored.
*
* @param target The target version up to which Flyway should consider migrations. (default: the latest version)
*/
public FluentConfiguration target(MigrationVersion target) {
config.setTarget(target);
return this;
}
/**
* Sets the target version up to which Flyway should consider migrations.
* Migrations with a higher version number will be ignored.
*
* @param target The target version up to which Flyway should consider migrations.
* The special value {@code current} designates the current version of the schema. (default: the latest
* version)
*/
public FluentConfiguration target(String target) {
config.setTargetAsString(target);
return this;
}
/**
* Sets whether placeholders should be replaced.
*
* @param placeholderReplacement Whether placeholders should be replaced. (default: true)
*/
public FluentConfiguration placeholderReplacement(boolean placeholderReplacement) {
config.setPlaceholderReplacement(placeholderReplacement);
return this;
}
/**
* Sets the placeholders to replace in sql migration scripts.
*
* @param placeholders The map of <placeholder, replacementValue> to apply to sql migration scripts.
*/
public FluentConfiguration placeholders(Map<String, String> placeholders) {
config.setPlaceholders(placeholders);
return this;
}
/**
* Sets the prefix of every placeholder.
*
* @param placeholderPrefix The prefix of every placeholder. (default: ${ )
*/
public FluentConfiguration placeholderPrefix(String placeholderPrefix) {
config.setPlaceholderPrefix(placeholderPrefix);
return this;
}
/**
* Sets the suffix of every placeholder.
*
* @param placeholderSuffix The suffix of every placeholder. (default: } )
*/
public FluentConfiguration placeholderSuffix(String placeholderSuffix) {
config.setPlaceholderSuffix(placeholderSuffix);
return this;
}
/**
* Sets the file name prefix for sql migrations.
* <p>Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix ,
* which using the defaults translates to V1_1__My_description.sql</p>
*
* @param sqlMigrationPrefix The file name prefix for sql migrations (default: V)
*/
public FluentConfiguration sqlMigrationPrefix(String sqlMigrationPrefix) {
config.setSqlMigrationPrefix(sqlMigrationPrefix);
return this;
}
@Override
public String getUndoSqlMigrationPrefix() {
return config.getUndoSqlMigrationPrefix();
}
/**
* Sets the file name prefix for undo SQL migrations. (default: U)
* <p>Undo SQL migrations are responsible for undoing the effects of the versioned migration with the same version.</p>
* <p>They have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix ,
* which using the defaults translates to U1.1__My_description.sql</p>
* <p><i>Flyway Pro and Flyway Enterprise only</i></p>
*
* @param undoSqlMigrationPrefix The file name prefix for undo SQL migrations. (default: U)
*/
public FluentConfiguration undoSqlMigrationPrefix(String undoSqlMigrationPrefix) {
config.setUndoSqlMigrationPrefix(undoSqlMigrationPrefix);
return this;
}
/**
* Sets the file name prefix for repeatable sql migrations.
* <p>Repeatable sql migrations have the following file name structure: prefixSeparatorDESCRIPTIONsuffix ,
* which using the defaults translates to R__My_description.sql</p>
*
* @param repeatableSqlMigrationPrefix The file name prefix for repeatable sql migrations (default: R)
*/
public FluentConfiguration repeatableSqlMigrationPrefix(String repeatableSqlMigrationPrefix) {
config.setRepeatableSqlMigrationPrefix(repeatableSqlMigrationPrefix);
return this;
}
/**
* Sets the file name separator for sql migrations.
* <p>Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix ,
* which using the defaults translates to V1_1__My_description.sql</p>
*
* @param sqlMigrationSeparator The file name separator for sql migrations (default: __)
*/
public FluentConfiguration sqlMigrationSeparator(String sqlMigrationSeparator) {
config.setSqlMigrationSeparator(sqlMigrationSeparator);
return this;
}
/**
* The file name suffixes for SQL migrations. (default: .sql)
* <p>SQL migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix ,
* which using the defaults translates to V1_1__My_description.sql</p>
* <p>Multiple suffixes (like .sql,.pkg,.pkb) can be specified for easier compatibility with other tools such as
* editors with specific file associations.</p>
*
* @param sqlMigrationSuffixes The file name suffixes for SQL migrations.
*/
public FluentConfiguration sqlMigrationSuffixes(String... sqlMigrationSuffixes) {
config.setSqlMigrationSuffixes(sqlMigrationSuffixes);
return this;
}
/**
* Sets the datasource to use. Must have the necessary privileges to execute ddl.
*
* @param dataSource The datasource to use. Must have the necessary privileges to execute ddl.
*/
public FluentConfiguration dataSource(DataSource dataSource) {
config.setDataSource(dataSource);
return this;
}
/**
* Sets the datasource to use. Must have the necessary privileges to execute ddl.
* <p>To use a custom ClassLoader, setClassLoader() must be called prior to calling this method.</p>
*
* @param url The JDBC URL of the database.
* @param user The user of the database.
* @param password The password of the database.
* @param initSqls The (optional) sql statements to execute to initialize a connection immediately after obtaining it.
*/
public FluentConfiguration dataSource(String url, String user, String password, String... initSqls) {
config.setDataSource(url, user, password, initSqls);
return this;
}
/**
* Sets the version to tag an existing schema with when executing baseline.
*
* @param baselineVersion The version to tag an existing schema with when executing baseline. (default: 1)
*/
public FluentConfiguration baselineVersion(MigrationVersion baselineVersion) {
config.setBaselineVersion(baselineVersion);
return this;
}
/**
* Sets the version to tag an existing schema with when executing baseline.
*
* @param baselineVersion The version to tag an existing schema with when executing baseline. (default: 1)
*/
public FluentConfiguration baselineVersion(String baselineVersion) {
config.setBaselineVersion(MigrationVersion.fromVersion(baselineVersion));
return this;
}
/**
* Sets the description to tag an existing schema with when executing baseline.
*
* @param baselineDescription The description to tag an existing schema with when executing baseline. (default: << Flyway Baseline >>)
*/
public FluentConfiguration baselineDescription(String baselineDescription) {
config.setBaselineDescription(baselineDescription);
return this;
}
/**
* <p>
* Whether to automatically call baseline when migrate is executed against a non-empty schema with no schema history table.
* This schema will then be baselined with the {@code baselineVersion} before executing the migrations.
* Only migrations above {@code baselineVersion} will then be applied.
* </p>
* <p>
* This is useful for initial Flyway production deployments on projects with an existing DB.
* </p>
* <p>
* Be careful when enabling this as it removes the safety net that ensures
* Flyway does not migrate the wrong database in case of a configuration mistake!
* </p>
*
* @param baselineOnMigrate {@code true} if baseline should be called on migrate for non-empty schemas, {@code false} if not. (default: {@code false})
*/
public FluentConfiguration baselineOnMigrate(boolean baselineOnMigrate) {
config.setBaselineOnMigrate(baselineOnMigrate);
return this;
}
/**
* Allows migrations to be run "out of order".
* <p>If you already have versions 1 and 3 applied, and now a version 2 is found,
* it will be applied too instead of being ignored.</p>
*
* @param outOfOrder {@code true} if outOfOrder migrations should be applied, {@code false} if not. (default: {@code false})
*/
public FluentConfiguration outOfOrder(boolean outOfOrder) {
config.setOutOfOrder(outOfOrder);
return this;
}
/**
* Gets the callbacks for lifecycle notifications.
*
* @return The callbacks for lifecycle notifications. An empty array if none. (default: none)
*/
@Override
public Callback[] getCallbacks() {
return config.getCallbacks();
}
@Override
public boolean isSkipDefaultCallbacks() {
return config.isSkipDefaultCallbacks();
}
/**
* Set the callbacks for lifecycle notifications.
*
* @param callbacks The callbacks for lifecycle notifications. (default: none)
*/
public FluentConfiguration callbacks(Callback... callbacks) {
config.setCallbacks(callbacks);
return this;
}
/**
* Set the callbacks for lifecycle notifications.
*
* @param callbacks The fully qualified class names of the callbacks for lifecycle notifications. (default: none)
*/
public FluentConfiguration callbacks(String... callbacks) {
config.setCallbacksAsClassNames(callbacks);
return this;
}
/**
* Whether Flyway should skip the default callbacks. If true, only custom callbacks are used.
*
* @param skipDefaultCallbacks Whether default built-in callbacks should be skipped. <p>(default: false)</p>
*/
public FluentConfiguration skipDefaultCallbacks(boolean skipDefaultCallbacks) {
config.setSkipDefaultCallbacks(skipDefaultCallbacks);
return this;
}
/**
* Sets custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.
*
* @param resolvers The custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply. (default: empty list)
*/
public FluentConfiguration resolvers(MigrationResolver... resolvers) {
config.setResolvers(resolvers);
return this;
}
/**
* Sets custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply.
*
* @param resolvers The fully qualified class names of the custom MigrationResolvers to be used in addition to the built-in ones for resolving Migrations to apply. (default: empty list)
*/
public FluentConfiguration resolvers(String... resolvers) {
config.setResolversAsClassNames(resolvers);
return this;
}
/**
* Whether Flyway should skip the default resolvers. If true, only custom resolvers are used.
*
* @param skipDefaultResolvers Whether default built-in resolvers should be skipped. <p>(default: false)</p>
*/
public FluentConfiguration skipDefaultResolvers(boolean skipDefaultResolvers) {
config.setSkipDefaultResolvers(skipDefaultResolvers);
return this;
}
/**
* Whether to stream SQL migrations when executing them. Streaming doesn't load the entire migration in memory at
* once. Instead each statement is loaded individually. This is particularly useful for very large SQL migrations
* composed of multiple MB or even GB of reference data, as this dramatically reduces Flyway's memory consumption.
* <p><i>Flyway Pro and Flyway Enterprise only</i></p>
*
* @param stream {@code true} to stream SQL migrations. {@code false} to fully loaded them in memory instead. (default: {@code false})
*/
public FluentConfiguration stream(boolean stream) {
config.setStream(stream);
return this;
}
/**
* Whether to batch SQL statements when executing them. Batching can save up to 99 percent of network roundtrips by
* sending up to 100 statements at once over the network to the database, instead of sending each statement
* individually. This is particularly useful for very large SQL migrations composed of multiple MB or even GB of
* reference data, as this can dramatically reduce the network overhead. This is supported for INSERT, UPDATE,
* DELETE, MERGE and UPSERT statements. All other statements are automatically executed without batching.
* <p><i>Flyway Pro and Flyway Enterprise only</i></p>
*
* @param batch {@code true} to batch SQL statements. {@code false} to execute them individually instead. (default: {@code false})
*/
public FluentConfiguration batch(boolean batch) {
config.setBatch(batch);
return this;
}
/**
* Whether to Flyway's support for Oracle SQL*Plus commands should be activated.
* <p><i>Flyway Pro and Flyway Enterprise only</i></p>
*
* @param oracleSqlplus {@code true} to active SQL*Plus support. {@code false} to fail fast instead. (default: {@code false})
*/
public FluentConfiguration oracleSqlplus(boolean oracleSqlplus) {
config.setOracleSqlplus(oracleSqlplus);
return this;
}
/**
* Flyway's license key.
*
* <p><i>Flyway Pro and Flyway Enterprise only</i></p>
*
* @param licenseKey The license key.
*/
public FluentConfiguration licenseKey(String licenseKey) {
config.setLicenseKey(licenseKey);
return this;
}
/**
* Configures Flyway with these properties. This overwrites any existing configuration. Property names are
* documented in the flyway maven plugin.
* <p>To use a custom ClassLoader, setClassLoader() must be called prior to calling this method.</p>
*
* @param properties Properties used for configuration.
* @throws FlywayException when the configuration failed.
*/
@SuppressWarnings("ConstantConditions")
public FluentConfiguration configure(Properties properties) {
config.configure(properties);
return this;
}
/**
* Configures Flyway with these properties. This overwrites any existing configuration. Property names are
* documented in the flyway maven plugin.
* <p>To use a custom ClassLoader, it must be passed to the Flyway constructor prior to calling this method.</p>
*
* @param props Properties used for configuration.
* @throws FlywayException when the configuration failed.
*/
public FluentConfiguration configure(Map<String, String> props) {
config.configure(props);
return this;
}
/**
* Configures Flyway using FLYWAY_* environment variables.
*
* @throws FlywayException when the configuration failed.
*/
public FluentConfiguration envVars() {
config.configureUsingEnvVars();
return this;
}
}