Added a version property for future-proofing

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2020-10-28 17:11:46 +01:00
parent 7aafa7eda5
commit be254304a8

View File

@ -2,6 +2,7 @@ package xyz.vallat.louis.database;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.vallat.louis.MovieQuoteBot;
import xyz.vallat.louis.codes.ExitCodes;
import xyz.vallat.louis.env.EnvironmentVariables;
@ -20,6 +21,7 @@ public final class DBManager {
private static final Logger logger = LoggerFactory.getLogger(DBManager.class.getCanonicalName());
private static final String CONNECTION_PREFIX = "postgresql";
private static final String VERSION_PROPERTY = "version";
private static final String USERNAME = System.getenv(EnvironmentVariables.DB_USERNAME.getValue());
private static final String PASSWORD = System.getenv(EnvironmentVariables.DB_PASSWORD.getValue());
private static final String DATABASE = System.getenv(EnvironmentVariables.DB_NAME.getValue());
@ -56,12 +58,17 @@ public final class DBManager {
initializeSubtitle(connection);
initializeSubtitleLine(connection);
importLanguageIfNeeded(connection);
updateDatabaseIfNeeded();
} catch (SQLException e) {
logger.error("An error happened while initializing the database. Reason: {}", e.getMessage());
System.exit(ExitCodes.CANNOT_INITIALIZE_DB.getValue());
}
}
private static void updateDatabaseIfNeeded() {
PropertyManager.saveProperty(VERSION_PROPERTY, MovieQuoteBot.VERSION);
}
private static void initializeSubtitle(Connection connection) throws SQLException {
logger.debug("Creating subtitle table.");
try (Statement stmt = connection.createStatement()) {