001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.autoconfigure.flyway;
018
019import java.nio.charset.Charset;
020import java.nio.charset.StandardCharsets;
021import java.util.ArrayList;
022import java.util.Collections;
023import java.util.HashMap;
024import java.util.List;
025import java.util.Map;
026
027import org.springframework.boot.context.properties.ConfigurationProperties;
028
029/**
030 * Configuration properties for Flyway database migrations.
031 *
032 * @author Dave Syer
033 * @author EddĂș MelĂ©ndez
034 * @author Stephane Nicoll
035 * @since 1.1.0
036 */
037@ConfigurationProperties(prefix = "spring.flyway")
038public class FlywayProperties {
039
040        /**
041         * Whether to enable flyway.
042         */
043        private boolean enabled = true;
044
045        /**
046         * Whether to check that migration scripts location exists.
047         */
048        private boolean checkLocation = true;
049
050        /**
051         * Locations of migrations scripts. Can contain the special "{vendor}" placeholder to
052         * use vendor-specific locations.
053         */
054        private List<String> locations = new ArrayList<>(
055                        Collections.singletonList("classpath:db/migration"));
056
057        /**
058         * Encoding of SQL migrations.
059         */
060        private Charset encoding = StandardCharsets.UTF_8;
061
062        /**
063         * Maximum number of retries when attempting to connect to the database.
064         */
065        private int connectRetries;
066
067        /**
068         * Scheme names managed by Flyway (case-sensitive).
069         */
070        private List<String> schemas = new ArrayList<>();
071
072        /**
073         * Name of the schema schema history table that will be used by Flyway.
074         */
075        private String table = "flyway_schema_history";
076
077        /**
078         * Description to tag an existing schema with when applying a baseline.
079         */
080        private String baselineDescription = "<< Flyway Baseline >>";
081
082        /**
083         * Version to tag an existing schema with when executing baseline.
084         */
085        private String baselineVersion = "1";
086
087        /**
088         * Username recorded in the schema history table as having applied the migration.
089         */
090        private String installedBy;
091
092        /**
093         * Placeholders and their replacements to apply to sql migration scripts.
094         */
095        private Map<String, String> placeholders = new HashMap<>();
096
097        /**
098         * Prefix of placeholders in migration scripts.
099         */
100        private String placeholderPrefix = "${";
101
102        /**
103         * Suffix of placeholders in migration scripts.
104         */
105        private String placeholderSuffix = "}";
106
107        /**
108         * Perform placeholder replacement in migration scripts.
109         */
110        private boolean placeholderReplacement = true;
111
112        /**
113         * File name prefix for SQL migrations.
114         */
115        private String sqlMigrationPrefix = "V";
116
117        /**
118         * File name suffix for SQL migrations.
119         */
120        private List<String> sqlMigrationSuffixes = new ArrayList<>(
121                        Collections.singleton(".sql"));
122
123        /**
124         * File name separator for SQL migrations.
125         */
126        private String sqlMigrationSeparator = "__";
127
128        /**
129         * File name prefix for repeatable SQL migrations.
130         */
131        private String repeatableSqlMigrationPrefix = "R";
132
133        /**
134         * Target version up to which migrations should be considered.
135         */
136        private String target;
137
138        /**
139         * JDBC url of the database to migrate. If not set, the primary configured data source
140         * is used.
141         */
142        private String url;
143
144        /**
145         * Login user of the database to migrate.
146         */
147        private String user;
148
149        /**
150         * Login password of the database to migrate.
151         */
152        private String password;
153
154        /**
155         * SQL statements to execute to initialize a connection immediately after obtaining
156         * it.
157         */
158        private List<String> initSqls = new ArrayList<>();
159
160        /**
161         * Whether to automatically call baseline when migrating a non-empty schema.
162         */
163        private boolean baselineOnMigrate;
164
165        /**
166         * Whether to disable cleaning of the database.
167         */
168        private boolean cleanDisabled;
169
170        /**
171         * Whether to automatically call clean when a validation error occurs.
172         */
173        private boolean cleanOnValidationError;
174
175        /**
176         * Whether to group all pending migrations together in the same transaction when
177         * applying them.
178         */
179        private boolean group;
180
181        /**
182         * Whether to ignore missing migrations when reading the schema history table.
183         */
184        private boolean ignoreMissingMigrations;
185
186        /**
187         * Whether to ignore ignored migrations when reading the schema history table.
188         */
189        private boolean ignoreIgnoredMigrations;
190
191        /**
192         * Whether to ignore pending migrations when reading the schema history table.
193         */
194        private boolean ignorePendingMigrations;
195
196        /**
197         * Whether to ignore future migrations when reading the schema history table.
198         */
199        private boolean ignoreFutureMigrations = true;
200
201        /**
202         * Whether to allow mixing transactional and non-transactional statements within the
203         * same migration.
204         */
205        private boolean mixed;
206
207        /**
208         * Whether to allow migrations to be run out of order.
209         */
210        private boolean outOfOrder;
211
212        /**
213         * Whether to skip default callbacks. If true, only custom callbacks are used.
214         */
215        private boolean skipDefaultCallbacks;
216
217        /**
218         * Whether to skip default resolvers. If true, only custom resolvers are used.
219         */
220        private boolean skipDefaultResolvers;
221
222        /**
223         * Whether to automatically call validate when performing a migration.
224         */
225        private boolean validateOnMigrate = true;
226
227        public boolean isEnabled() {
228                return this.enabled;
229        }
230
231        public void setEnabled(boolean enabled) {
232                this.enabled = enabled;
233        }
234
235        public boolean isCheckLocation() {
236                return this.checkLocation;
237        }
238
239        public void setCheckLocation(boolean checkLocation) {
240                this.checkLocation = checkLocation;
241        }
242
243        public List<String> getLocations() {
244                return this.locations;
245        }
246
247        public void setLocations(List<String> locations) {
248                this.locations = locations;
249        }
250
251        public Charset getEncoding() {
252                return this.encoding;
253        }
254
255        public void setEncoding(Charset encoding) {
256                this.encoding = encoding;
257        }
258
259        public int getConnectRetries() {
260                return this.connectRetries;
261        }
262
263        public void setConnectRetries(int connectRetries) {
264                this.connectRetries = connectRetries;
265        }
266
267        public List<String> getSchemas() {
268                return this.schemas;
269        }
270
271        public void setSchemas(List<String> schemas) {
272                this.schemas = schemas;
273        }
274
275        public String getTable() {
276                return this.table;
277        }
278
279        public void setTable(String table) {
280                this.table = table;
281        }
282
283        public String getBaselineDescription() {
284                return this.baselineDescription;
285        }
286
287        public void setBaselineDescription(String baselineDescription) {
288                this.baselineDescription = baselineDescription;
289        }
290
291        public String getBaselineVersion() {
292                return this.baselineVersion;
293        }
294
295        public void setBaselineVersion(String baselineVersion) {
296                this.baselineVersion = baselineVersion;
297        }
298
299        public String getInstalledBy() {
300                return this.installedBy;
301        }
302
303        public void setInstalledBy(String installedBy) {
304                this.installedBy = installedBy;
305        }
306
307        public Map<String, String> getPlaceholders() {
308                return this.placeholders;
309        }
310
311        public void setPlaceholders(Map<String, String> placeholders) {
312                this.placeholders = placeholders;
313        }
314
315        public String getPlaceholderPrefix() {
316                return this.placeholderPrefix;
317        }
318
319        public void setPlaceholderPrefix(String placeholderPrefix) {
320                this.placeholderPrefix = placeholderPrefix;
321        }
322
323        public String getPlaceholderSuffix() {
324                return this.placeholderSuffix;
325        }
326
327        public void setPlaceholderSuffix(String placeholderSuffix) {
328                this.placeholderSuffix = placeholderSuffix;
329        }
330
331        public boolean isPlaceholderReplacement() {
332                return this.placeholderReplacement;
333        }
334
335        public void setPlaceholderReplacement(boolean placeholderReplacement) {
336                this.placeholderReplacement = placeholderReplacement;
337        }
338
339        public String getSqlMigrationPrefix() {
340                return this.sqlMigrationPrefix;
341        }
342
343        public void setSqlMigrationPrefix(String sqlMigrationPrefix) {
344                this.sqlMigrationPrefix = sqlMigrationPrefix;
345        }
346
347        public List<String> getSqlMigrationSuffixes() {
348                return this.sqlMigrationSuffixes;
349        }
350
351        public void setSqlMigrationSuffixes(List<String> sqlMigrationSuffixes) {
352                this.sqlMigrationSuffixes = sqlMigrationSuffixes;
353        }
354
355        public String getSqlMigrationSeparator() {
356                return this.sqlMigrationSeparator;
357        }
358
359        public void setSqlMigrationSeparator(String sqlMigrationSeparator) {
360                this.sqlMigrationSeparator = sqlMigrationSeparator;
361        }
362
363        public String getRepeatableSqlMigrationPrefix() {
364                return this.repeatableSqlMigrationPrefix;
365        }
366
367        public void setRepeatableSqlMigrationPrefix(String repeatableSqlMigrationPrefix) {
368                this.repeatableSqlMigrationPrefix = repeatableSqlMigrationPrefix;
369        }
370
371        public String getTarget() {
372                return this.target;
373        }
374
375        public void setTarget(String target) {
376                this.target = target;
377        }
378
379        public boolean isCreateDataSource() {
380                return this.url != null || this.user != null;
381        }
382
383        public String getUrl() {
384                return this.url;
385        }
386
387        public void setUrl(String url) {
388                this.url = url;
389        }
390
391        public String getUser() {
392                return this.user;
393        }
394
395        public void setUser(String user) {
396                this.user = user;
397        }
398
399        public String getPassword() {
400                return (this.password != null) ? this.password : "";
401        }
402
403        public void setPassword(String password) {
404                this.password = password;
405        }
406
407        public List<String> getInitSqls() {
408                return this.initSqls;
409        }
410
411        public void setInitSqls(List<String> initSqls) {
412                this.initSqls = initSqls;
413        }
414
415        public boolean isBaselineOnMigrate() {
416                return this.baselineOnMigrate;
417        }
418
419        public void setBaselineOnMigrate(boolean baselineOnMigrate) {
420                this.baselineOnMigrate = baselineOnMigrate;
421        }
422
423        public boolean isCleanDisabled() {
424                return this.cleanDisabled;
425        }
426
427        public void setCleanDisabled(boolean cleanDisabled) {
428                this.cleanDisabled = cleanDisabled;
429        }
430
431        public boolean isCleanOnValidationError() {
432                return this.cleanOnValidationError;
433        }
434
435        public void setCleanOnValidationError(boolean cleanOnValidationError) {
436                this.cleanOnValidationError = cleanOnValidationError;
437        }
438
439        public boolean isGroup() {
440                return this.group;
441        }
442
443        public void setGroup(boolean group) {
444                this.group = group;
445        }
446
447        public boolean isIgnoreMissingMigrations() {
448                return this.ignoreMissingMigrations;
449        }
450
451        public void setIgnoreMissingMigrations(boolean ignoreMissingMigrations) {
452                this.ignoreMissingMigrations = ignoreMissingMigrations;
453        }
454
455        public boolean isIgnoreIgnoredMigrations() {
456                return this.ignoreIgnoredMigrations;
457        }
458
459        public void setIgnoreIgnoredMigrations(boolean ignoreIgnoredMigrations) {
460                this.ignoreIgnoredMigrations = ignoreIgnoredMigrations;
461        }
462
463        public boolean isIgnorePendingMigrations() {
464                return this.ignorePendingMigrations;
465        }
466
467        public void setIgnorePendingMigrations(boolean ignorePendingMigrations) {
468                this.ignorePendingMigrations = ignorePendingMigrations;
469        }
470
471        public boolean isIgnoreFutureMigrations() {
472                return this.ignoreFutureMigrations;
473        }
474
475        public void setIgnoreFutureMigrations(boolean ignoreFutureMigrations) {
476                this.ignoreFutureMigrations = ignoreFutureMigrations;
477        }
478
479        public boolean isMixed() {
480                return this.mixed;
481        }
482
483        public void setMixed(boolean mixed) {
484                this.mixed = mixed;
485        }
486
487        public boolean isOutOfOrder() {
488                return this.outOfOrder;
489        }
490
491        public void setOutOfOrder(boolean outOfOrder) {
492                this.outOfOrder = outOfOrder;
493        }
494
495        public boolean isSkipDefaultCallbacks() {
496                return this.skipDefaultCallbacks;
497        }
498
499        public void setSkipDefaultCallbacks(boolean skipDefaultCallbacks) {
500                this.skipDefaultCallbacks = skipDefaultCallbacks;
501        }
502
503        public boolean isSkipDefaultResolvers() {
504                return this.skipDefaultResolvers;
505        }
506
507        public void setSkipDefaultResolvers(boolean skipDefaultResolvers) {
508                this.skipDefaultResolvers = skipDefaultResolvers;
509        }
510
511        public boolean isValidateOnMigrate() {
512                return this.validateOnMigrate;
513        }
514
515        public void setValidateOnMigrate(boolean validateOnMigrate) {
516                this.validateOnMigrate = validateOnMigrate;
517        }
518
519}