File tree 1 file changed +23
-2
lines changed
1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -22,8 +22,9 @@ import (
22
22
)
23
23
24
24
const (
25
- ExitSuccess = 0
26
- ExitFailure = 1
25
+ ExitSuccess = 0
26
+ ExitFailure = 1
27
+ expectedSchemaVersion = 2
27
28
)
28
29
29
30
func main () {
@@ -48,6 +49,10 @@ func run() int {
48
49
}
49
50
}
50
51
52
+ if err := checkDbSchema (context .Background (), db ); err != nil {
53
+ logger .Fatalf ("%+v" , err )
54
+ }
55
+
51
56
rc := cmd .Redis ()
52
57
{
53
58
logger .Info ("Connecting to Redis" )
@@ -241,3 +246,19 @@ func run() int {
241
246
cancelHactx ()
242
247
}
243
248
}
249
+
250
+ // checkDbSchema asserts the database schema of the expected version being present.
251
+ func checkDbSchema (ctx context.Context , db * icingadb.DB ) error {
252
+ var version uint16
253
+
254
+ err := db .QueryRowxContext (ctx , "SELECT version FROM icingadb_schema ORDER BY id DESC LIMIT 1" ).Scan (& version )
255
+ if err != nil {
256
+ return errors .Wrap (err , "can't check database schema version" )
257
+ }
258
+
259
+ if version != expectedSchemaVersion {
260
+ return errors .Errorf ("expected database schema v%d, got v%d" , expectedSchemaVersion , version )
261
+ }
262
+
263
+ return nil
264
+ }
You can’t perform that action at this time.
0 commit comments