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.callback;
17
18 /**
19  * The Flyway lifecycle events that can be handled in callbacks.
20  */

21 public enum Event {
22     /**
23      * Fired before clean is executed. This event will be fired in a separate transaction from the actual clean operation.
24      */

25     BEFORE_CLEAN("beforeClean"),
26     /**
27      * Fired after clean has succeeded. This event will be fired in a separate transaction from the actual clean operation.
28      */

29     AFTER_CLEAN("afterClean"),
30     /**
31      * Fired after clean has failed. This event will be fired in a separate transaction from the actual clean operation.
32      */

33     AFTER_CLEAN_ERROR("afterCleanError"),
34
35     /**
36      * Fired before migrate is executed. This event will be fired in a separate transaction from the actual migrate operation.
37      */

38     BEFORE_MIGRATE("beforeMigrate"),
39     /**
40      * Fired before each individual migration is executed. This event will be fired within the same transaction (if any)
41      * as the migration and can be used for things like setting up connection parameters that are required by migrations.
42      */

43     BEFORE_EACH_MIGRATE("beforeEachMigrate"),
44     /**
45      * Fired before each individual statement in a migration is executed. This event will be fired within the same transaction (if any)
46      * as the migration and can be used for things like asserting a statement complies with policy (for example: no grant statements allowed).
47      * <p><i>Flyway Pro and Enterprise Edition only</i></p>
48      */

49     BEFORE_EACH_MIGRATE_STATEMENT("beforeEachMigrateStatement"),
50     /**
51      * Fired after each individual statement in a migration that succeeded. This event will be fired within the same transaction (if any)
52      * as the migration.
53      * <p><i>Flyway Pro and Enterprise Edition only</i></p>
54      */

55     AFTER_EACH_MIGRATE_STATEMENT("afterEachMigrateStatement"),
56     /**
57      * Fired after each individual statement in a migration that failed. This event will be fired within the same transaction (if any)
58      * as the migration.
59      * <p><i>Flyway Pro and Enterprise Edition only</i></p>
60      */

61     AFTER_EACH_MIGRATE_STATEMENT_ERROR("afterEachMigrateStatementError"),
62     /**
63      * Fired after each individual migration that succeeded. This event will be fired within the same transaction (if any)
64      * as the migration.
65      */

66     AFTER_EACH_MIGRATE("afterEachMigrate"),
67     /**
68      * Fired after each individual migration that failed. This event will be fired within the same transaction (if any)
69      * as the migration.
70      */

71     AFTER_EACH_MIGRATE_ERROR("afterEachMigrateError"),
72     /**
73      * Fired after migrate has succeeded. This event will be fired in a separate transaction from the actual migrate operation.
74      */

75     AFTER_MIGRATE("afterMigrate"),
76     /**
77      * Fired after migrate has failed. This event will be fired in a separate transaction from the actual migrate operation.
78      */

79     AFTER_MIGRATE_ERROR("afterMigrateError"),
80
81     /**
82      * Fired before undo is executed. This event will be fired in a separate transaction from the actual undo operation.
83      * <p><i>Flyway Pro and Enterprise Edition only</i></p>
84      */

85     BEFORE_UNDO("beforeUndo"),
86     /**
87      * Fired before each individual undo is executed. This event will be fired within the same transaction (if any)
88      * as the undo and can be used for things like setting up connection parameters that are required by undo.
89      * <p><i>Flyway Pro and Enterprise Edition only</i></p>
90      */

91     BEFORE_EACH_UNDO("beforeEachUndo"),
92     /**
93      * Fired before each individual statement in an undo migration is executed. This event will be fired within the same transaction (if any)
94      * as the migration and can be used for things like asserting a statement complies with policy (for example: no grant statements allowed).
95      * <p><i>Flyway Pro and Enterprise Edition only</i></p>
96      */

97     BEFORE_EACH_UNDO_STATEMENT("beforeEachUndoStatement"),
98     /**
99      * Fired after each individual statement in an undo migration that succeeded. This event will be fired within the same transaction (if any)
100      * as the migration.
101      * <p><i>Flyway Pro and Enterprise Edition only</i></p>
102      */

103     AFTER_EACH_UNDO_STATEMENT("afterEachUndoStatement"),
104     /**
105      * Fired after each individual statement in an undo migration that failed. This event will be fired within the same transaction (if any)
106      * as the migration.
107      * <p><i>Flyway Pro and Enterprise Edition only</i></p>
108      */

109     AFTER_EACH_UNDO_STATEMENT_ERROR("afterEachUndoStatementError"),
110     /**
111      * Fired after each individual undo that succeeded. This event will be fired within the same transaction (if any)
112      * as the undo.
113      * <p><i>Flyway Pro and Enterprise Edition only</i></p>
114      */

115     AFTER_EACH_UNDO("afterEachUndo"),
116     /**
117      * Fired after each individual undo that failed. This event will be fired within the same transaction (if any)
118      * as the undo.
119      * <p><i>Flyway Pro and Enterprise Edition only</i></p>
120      */

121     AFTER_EACH_UNDO_ERROR("afterEachUndoError"),
122     /**
123      * Fired after undo has succeeded. This event will be fired in a separate transaction from the actual undo operation.
124      * <p><i>Flyway Pro and Enterprise Edition only</i></p>
125      */

126     AFTER_UNDO("afterUndo"),
127     /**
128      * Fired after undo has failed. This event will be fired in a separate transaction from the actual undo operation.
129      * <p><i>Flyway Pro and Enterprise Edition only</i></p>
130      */

131     AFTER_UNDO_ERROR("afterUndoError"),
132
133     /**
134      * Fired before validate is executed. This event will be fired in a separate transaction from the actual validate operation.
135      */

136     BEFORE_VALIDATE("beforeValidate"),
137     /**
138      * Fired after validate has succeeded. This event will be fired in a separate transaction from the actual validate operation.
139      */

140     AFTER_VALIDATE("afterValidate"),
141     /**
142      * Fired after validate has failed. This event will be fired in a separate transaction from the actual validate operation.
143      */

144     AFTER_VALIDATE_ERROR("afterValidateError"),
145
146     /**
147      * Fired before baseline is executed. This event will be fired in a separate transaction from the actual baseline operation.
148      */

149     BEFORE_BASELINE("beforeBaseline"),
150     /**
151      * Fired after baseline has succeeded. This event will be fired in a separate transaction from the actual baseline operation.
152      */

153     AFTER_BASELINE("afterBaseline"),
154     /**
155      * Fired after baseline has failed. This event will be fired in a separate transaction from the actual baseline operation.
156      */

157     AFTER_BASELINE_ERROR("afterBaselineError"),
158
159     /**
160      * Fired before repair is executed. This event will be fired in a separate transaction from the actual repair operation.
161      */

162     BEFORE_REPAIR("beforeRepair"),
163     /**
164      * Fired after repair has succeeded. This event will be fired in a separate transaction from the actual repair operation.
165      */

166     AFTER_REPAIR("afterRepair"),
167     /**
168      * Fired after repair has failed. This event will be fired in a separate transaction from the actual repair operation.
169      */

170     AFTER_REPAIR_ERROR("afterRepairError"),
171
172     /**
173      * Fired before info is executed. This event will be fired in a separate transaction from the actual info operation.
174      */

175     BEFORE_INFO("beforeInfo"),
176     /**
177      * Fired after info has succeeded. This event will be fired in a separate transaction from the actual info operation.
178      */

179     AFTER_INFO("afterInfo"),
180     /**
181      * Fired after info has failed. This event will be fired in a separate transaction from the actual info operation.
182      */

183     AFTER_INFO_ERROR("afterInfoError");
184
185     private final String id;
186
187     Event(String id) {
188         this.id = id;
189     }
190
191     /**
192      * @return The id of an event. Examples: {@code beforeClean}, {@code afterEachMigrate}, ...
193      */

194     public String getId() {
195         return id;
196     }
197
198     /**
199      * Retrieves the event with this id.
200      * @param id The id.
201      * @return The event. {@code nullif not found.
202      */

203     public static Event fromId(String id) {
204         for (Event event : values()) {
205             if (event.id.equals(id)) {
206                 return event;
207             }
208         }
209         return null;
210     }
211
212     @Override
213     public String toString() {
214         return id;
215     }
216 }