1 /*
2  * Copyright 2010-2020 Redgate Software Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.flywaydb.core.api;
17
18 /**
19  * The state of a migration.
20  */

21 public enum MigrationState {
22     /**
23      * This migration has not been applied yet.
24      */

25     PENDING("Pending"truefalsefalse),
26
27     /**
28      * This migration has not been applied yet, and won't be applied because target is set to a lower version.
29      */

30     ABOVE_TARGET("Above Target"truefalsefalse),
31
32     /**
33      * This migration was not applied against this DB, because the schema history table was baselined with a higher version.
34      */

35     BELOW_BASELINE("Below Baseline"truefalsefalse),
36
37     /**
38      * This migration has baselined this DB.
39      */

40     BASELINE("Baseline"truetruefalse),
41
42     /**
43      * <p>This usually indicates a problem.</p>
44      * <p>
45      * This migration was not applied against this DB, because a migration with a higher version has already been
46      * applied. This probably means some checkins happened out of order.
47      * </p>
48      * <p>Fix by increasing the version number, run clean and migrate again or rerun migration with outOfOrder enabled.</p>
49      */

50     IGNORED("Ignored"truefalsefalse),
51
52     /**
53      * <p>This migration succeeded.</p>
54      * <p>
55      * This migration was applied against this DB, but it is not available locally.
56      * This usually results from multiple older migration files being consolidated into a single one.
57      * </p>
58      */

59     MISSING_SUCCESS("Missing"falsetruefalse),
60
61     /**
62      * <p>This migration failed.</p>
63      * <p>
64      * This migration was applied against this DB, but it is not available locally.
65      * This usually results from multiple older migration files being consolidated into a single one.
66      * </p>
67      * <p>This should rarely, if ever, occur in practice.</p>
68      */

69     MISSING_FAILED("Failed (Missing)"falsetruetrue),
70
71     /**
72      * This migration succeeded.
73      */

74     SUCCESS("Success"truetruefalse),
75
76     /**
77      * This versioned migration succeeded, but has since been undone.
78      */

79     UNDONE("Undone"truetruefalse),
80
81     /**
82      * This undo migration is ready to be applied if desired.
83      */

84     AVAILABLE("Available"truefalsefalse),
85
86     /**
87      * This migration failed.
88      */

89     FAILED("Failed"truetruetrue),
90
91     /**
92      * <p>This migration succeeded.</p>
93      * <p>
94      * This migration succeeded, but it was applied out of order.
95      * Rerunning the entire migration history might produce different results!
96      * </p>
97      */

98     OUT_OF_ORDER("Out of Order"truetruefalse),
99
100     /**
101      * <p>This migration succeeded.</p>
102      * <p>
103      * This migration has been applied against the DB, but it is not available locally.
104      * Its version is higher than the highest version available locally.
105      * It was most likely successfully installed by a future version of this deployable.
106      * </p>
107      */

108     FUTURE_SUCCESS("Future"falsetruefalse),
109
110     /**
111      * <p>This migration failed.</p>
112      * <p>
113      * This migration has been applied against the DB, but it is not available locally.
114      * Its version is higher than the highest version available locally.
115      * It most likely failed during the installation of a future version of this deployable.
116      * </p>
117      */

118     FUTURE_FAILED("Failed (Future)"falsetruetrue),
119
120     /**
121      * This is a repeatable migration that is outdated and should be re-applied.
122      */

123     OUTDATED("Outdated"truetruefalse),
124
125     /**
126      * This is a repeatable migration that is outdated and has already been superseded by a newer run.
127      */

128     SUPERSEDED("Superseded"truetruefalse);
129
130     /**
131      * The name suitable for display to the end-user.
132      */

133     private final String displayName;
134
135     /**
136      * Flag indicating if this migration is available on the classpath or not.
137      */

138     private final boolean resolved;
139
140     /**
141      * Flag indicating if this migration has been applied or not.
142      */

143     private final boolean applied;
144
145     /**
146      * Flag indicating if this migration has failed when it was applied or not.
147      */

148     private final boolean failed;
149
150     /**
151      * Creates a new MigrationState.
152      *
153      * @param displayName The name suitable for display to the end-user.
154      * @param resolved   Flag indicating if this migration is available on the classpath or not.
155      * @param applied     Flag indicating if this migration has been applied or not.
156      * @param failed      Flag indicating if this migration has failed when it was applied or not.
157      */

158     MigrationState(String displayName, boolean resolved, boolean applied, boolean failed) {
159         this.displayName = displayName;
160         this.resolved = resolved;
161         this.applied = applied;
162         this.failed = failed;
163     }
164
165     /**
166      * @return The name suitable for display to the end-user.
167      */

168     public String getDisplayName() {
169         return displayName;
170     }
171
172     /**
173      * @return Flag indicating if this migration has been applied or not.
174      */

175     public boolean isApplied() {
176         return applied;
177     }
178
179     /**
180      * @return Flag indicating if this migration has been resolved or not.
181      */

182     public boolean isResolved() {
183         return resolved;
184     }
185
186     /**
187      * @return Flag indicating if this migration has failed or not.
188      */

189     public boolean isFailed() {
190         return failed;
191     }
192 }