Added a version property for future-proofing
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
7aafa7eda5
commit
be254304a8
@ -2,6 +2,7 @@ package xyz.vallat.louis.database;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import xyz.vallat.louis.MovieQuoteBot;
|
||||||
import xyz.vallat.louis.codes.ExitCodes;
|
import xyz.vallat.louis.codes.ExitCodes;
|
||||||
import xyz.vallat.louis.env.EnvironmentVariables;
|
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 Logger logger = LoggerFactory.getLogger(DBManager.class.getCanonicalName());
|
||||||
private static final String CONNECTION_PREFIX = "postgresql";
|
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 USERNAME = System.getenv(EnvironmentVariables.DB_USERNAME.getValue());
|
||||||
private static final String PASSWORD = System.getenv(EnvironmentVariables.DB_PASSWORD.getValue());
|
private static final String PASSWORD = System.getenv(EnvironmentVariables.DB_PASSWORD.getValue());
|
||||||
private static final String DATABASE = System.getenv(EnvironmentVariables.DB_NAME.getValue());
|
private static final String DATABASE = System.getenv(EnvironmentVariables.DB_NAME.getValue());
|
||||||
@ -56,12 +58,17 @@ public final class DBManager {
|
|||||||
initializeSubtitle(connection);
|
initializeSubtitle(connection);
|
||||||
initializeSubtitleLine(connection);
|
initializeSubtitleLine(connection);
|
||||||
importLanguageIfNeeded(connection);
|
importLanguageIfNeeded(connection);
|
||||||
|
updateDatabaseIfNeeded();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
logger.error("An error happened while initializing the database. Reason: {}", e.getMessage());
|
logger.error("An error happened while initializing the database. Reason: {}", e.getMessage());
|
||||||
System.exit(ExitCodes.CANNOT_INITIALIZE_DB.getValue());
|
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 {
|
private static void initializeSubtitle(Connection connection) throws SQLException {
|
||||||
logger.debug("Creating subtitle table.");
|
logger.debug("Creating subtitle table.");
|
||||||
try (Statement stmt = connection.createStatement()) {
|
try (Statement stmt = connection.createStatement()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user