diff --git a/src/main/java/xyz/vallat/louis/database/DBManager.java b/src/main/java/xyz/vallat/louis/database/DBManager.java index 60e63b9..6616abd 100644 --- a/src/main/java/xyz/vallat/louis/database/DBManager.java +++ b/src/main/java/xyz/vallat/louis/database/DBManager.java @@ -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()) {