16
16
17
17
package org .springframework .boot .actuate .endpoint ;
18
18
19
- import java .util .ArrayList ;
20
- import java .util .Collections ;
21
19
import java .util .Date ;
20
+ import java .util .HashMap ;
22
21
import java .util .List ;
23
22
import java .util .Map ;
23
+ import java .util .stream .Collectors ;
24
+ import java .util .stream .Stream ;
24
25
25
26
import org .flywaydb .core .Flyway ;
26
27
import org .flywaydb .core .api .MigrationInfo ;
40
41
* @since 1.3.0
41
42
*/
42
43
@ ConfigurationProperties (prefix = "endpoints.flyway" )
43
- public class FlywayEndpoint extends AbstractEndpoint <List < FlywayReport >> {
44
+ public class FlywayEndpoint extends AbstractEndpoint <Map < String , FlywayReport >> {
44
45
45
46
private final Map <String , Flyway > flyways ;
46
47
47
- public FlywayEndpoint (Flyway flyway ) {
48
- this (Collections .singletonMap ("default" , flyway ));
49
- }
50
-
51
48
public FlywayEndpoint (Map <String , Flyway > flyways ) {
52
49
super ("flyway" );
53
50
Assert .notEmpty (flyways , "Flyways must be specified" );
54
51
this .flyways = flyways ;
55
52
}
56
53
57
54
@ Override
58
- public List < FlywayReport > invoke () {
59
- List < FlywayReport > reports = new ArrayList <>();
55
+ public Map < String , FlywayReport > invoke () {
56
+ Map < String , FlywayReport > reports = new HashMap <>();
60
57
for (Map .Entry <String , Flyway > entry : this .flyways .entrySet ()) {
61
- List <FlywayMigration > migrations = new ArrayList <>();
62
- for (MigrationInfo info : entry .getValue ().info ().all ()) {
63
- migrations .add (new FlywayMigration (info ));
64
- }
65
- reports .add (new FlywayReport (entry .getKey (), migrations ));
58
+ reports .put (entry .getKey (),
59
+ new FlywayReport (Stream .of (entry .getValue ().info ().all ())
60
+ .map (FlywayMigration ::new ).collect (Collectors .toList ())));
66
61
}
67
62
return reports ;
68
63
}
69
64
70
65
/**
71
- * Flyway report for one datasource .
66
+ * Report for one {@link Flyway} instance .
72
67
*/
73
68
public static class FlywayReport {
74
69
75
- private final String name ;
76
70
private final List <FlywayMigration > migrations ;
77
71
78
- public FlywayReport (String name , List <FlywayMigration > migrations ) {
79
- this .name = name ;
72
+ public FlywayReport (List <FlywayMigration > migrations ) {
80
73
this .migrations = migrations ;
81
74
}
82
75
83
- public String getName () {
84
- return this .name ;
85
- }
86
-
87
76
public List <FlywayMigration > getMigrations () {
88
77
return this .migrations ;
89
78
}
90
79
91
80
}
92
81
93
82
/**
94
- * Migration properties .
83
+ * Details of a migration performed by Flyway .
95
84
*/
96
85
public static class FlywayMigration {
97
86
@@ -107,8 +96,12 @@ public static class FlywayMigration {
107
96
108
97
private final MigrationState state ;
109
98
99
+ private final String installedBy ;
100
+
110
101
private final Date installedOn ;
111
102
103
+ private final Integer installedRank ;
104
+
112
105
private final Integer executionTime ;
113
106
114
107
public FlywayMigration (MigrationInfo info ) {
@@ -118,7 +111,9 @@ public FlywayMigration(MigrationInfo info) {
118
111
this .description = info .getDescription ();
119
112
this .script = info .getScript ();
120
113
this .state = info .getState ();
114
+ this .installedBy = info .getInstalledBy ();
121
115
this .installedOn = info .getInstalledOn ();
116
+ this .installedRank = info .getInstalledRank ();
122
117
this .executionTime = info .getExecutionTime ();
123
118
}
124
119
@@ -150,10 +145,18 @@ public MigrationState getState() {
150
145
return this .state ;
151
146
}
152
147
148
+ public String getInstalledBy () {
149
+ return this .installedBy ;
150
+ }
151
+
153
152
public Date getInstalledOn () {
154
153
return this .installedOn ;
155
154
}
156
155
156
+ public Integer getInstalledRank () {
157
+ return this .installedRank ;
158
+ }
159
+
157
160
public Integer getExecutionTime () {
158
161
return this .executionTime ;
159
162
}
0 commit comments