-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathSchemaVersionVerifier.java
More file actions
41 lines (33 loc) · 1.54 KB
/
SchemaVersionVerifier.java
File metadata and controls
41 lines (33 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.faforever.api.db;
import com.faforever.api.config.ApplicationProfile;
import com.faforever.api.config.FafApiProperties;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Profile;
import org.springframework.core.PriorityOrdered;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import java.util.Objects;
@Component
@Profile(ApplicationProfile.PRODUCTION)
public class SchemaVersionVerifier implements PriorityOrdered, InitializingBean {
private final SchemaVersionRepository schemaVersionRepository;
private final FafApiProperties properties;
public SchemaVersionVerifier(SchemaVersionRepository schemaVersionRepository, FafApiProperties properties) {
this.schemaVersionRepository = schemaVersionRepository;
this.properties = properties;
}
@Override
public int getOrder() {
return HIGHEST_PRECEDENCE;
}
@Override
public void afterPropertiesSet() {
String requiredVersion = properties.getDatabase().getSchemaVersion();
String actualVersion = schemaVersionRepository.findMaxVersion()
.orElseThrow(() -> new IllegalStateException("No database version is available"));
Assert.state(Objects.equals(requiredVersion, actualVersion),
String.format("Database version is '%s' but this software requires '%s'. If you are sure that this version is " +
"compatible, you can override the expected version by setting the environment variable DATABASE_SCHEMA_VERSION.",
actualVersion, requiredVersion));
}
}