17
17
18
18
import lombok .RequiredArgsConstructor ;
19
19
import lombok .extern .slf4j .Slf4j ;
20
- import org .springframework .boot .info .BuildProperties ;
21
20
import org .springframework .context .annotation .Profile ;
22
21
import org .springframework .jdbc .core .JdbcTemplate ;
23
22
import org .springframework .stereotype .Service ;
31
30
@ RequiredArgsConstructor
32
31
public class DefaultDatabaseSchemaSettingsService implements DatabaseSchemaSettingsService {
33
32
34
- private static final String CURRENT_PRODUCT = "CE" ;
35
33
// This list should include all versions that are compatible for the upgrade.
36
34
// The compatibility cycle usually breaks when we have some scripts written in Java that may not work after new release.
37
35
private static final List <String > SUPPORTED_VERSIONS_FOR_UPGRADE = List .of ("2.2.0" );
38
36
39
- private final BuildProperties buildProperties ;
37
+ private final ProjectInfo projectInfo ;
40
38
private final JdbcTemplate jdbcTemplate ;
41
39
42
40
private String packageSchemaVersion ;
@@ -50,8 +48,8 @@ public void validateSchemaSettings() {
50
48
}
51
49
52
50
String product = getProductFromDb ();
53
- if (!CURRENT_PRODUCT .equals (product )) {
54
- onSchemaSettingsError (String .format ("Upgrade failed: can't upgrade TBMQ %s database using TBMQ %s." , product , CURRENT_PRODUCT ));
51
+ if (!projectInfo . getProductType () .equals (product )) {
52
+ onSchemaSettingsError (String .format ("Upgrade failed: can't upgrade TBMQ %s database using TBMQ %s." , product , projectInfo . getProductType () ));
55
53
}
56
54
57
55
String dbSchemaVersion = getDbSchemaVersion ();
@@ -69,7 +67,7 @@ public void validateSchemaSettings() {
69
67
public void createSchemaSettings () {
70
68
Long schemaVersion = getSchemaVersionFromDb ();
71
69
if (schemaVersion == null ) {
72
- jdbcTemplate .execute ("INSERT INTO tb_schema_settings (schema_version, product) VALUES (" + getPackageSchemaVersionForDb () + ", '" + CURRENT_PRODUCT + "')" );
70
+ jdbcTemplate .execute ("INSERT INTO tb_schema_settings (schema_version, product) VALUES (" + getPackageSchemaVersionForDb () + ", '" + projectInfo . getProductType () + "')" );
73
71
}
74
72
}
75
73
@@ -81,7 +79,7 @@ public void updateSchemaVersion() {
81
79
@ Override
82
80
public String getPackageSchemaVersion () {
83
81
if (packageSchemaVersion == null ) {
84
- packageSchemaVersion = buildProperties . getVersion (). replaceAll ( "[^ \\ d.]" , "" );
82
+ packageSchemaVersion = projectInfo . getProjectVersion ( );
85
83
}
86
84
return packageSchemaVersion ;
87
85
}
0 commit comments