Fix migrations

This commit is contained in:
2024-12-02 12:44:56 +01:00
parent 235bb78b69
commit b005b43201

View File

@@ -72,7 +72,7 @@ public abstract class BaseMigration implements MigrationModelInterface {
return UtilityDB.executeSimpleQuery(advancedDataSource.getConnection(), sql);
}
protected @NotNull <T>List<T> executeQueryDTO(String sql, Class<T> clazz) throws Exception {
protected @NotNull <T> List<T> executeQueryDTO(String sql, Class<T> clazz) throws Exception {
return UtilityDB.executeSimpleQueryDTO(advancedDataSource.getConnection(), sql, clazz);
}
@@ -163,7 +163,7 @@ public abstract class BaseMigration implements MigrationModelInterface {
return val != null && val == 1;
}
protected boolean existColumn( String tableName, String columnName ) throws SQLException, IOException {
protected boolean existColumn(String tableName, String columnName) throws SQLException, IOException {
return UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(advancedDataSource.getConnection(),
Query.format("SELECT CAST(COUNT(*) AS BIT)\n" +
"FROM sys.syscolumns\n" +
@@ -175,7 +175,7 @@ public abstract class BaseMigration implements MigrationModelInterface {
if (existColumn(tableName, oldColumnname)) {
String sql =
"exec sp_rename 'dbo." + tableName + "." + oldColumnname + "', " + newColumnName + ", 'COLUMN'";
executeStatement(sql);
executeStatement(sql);
}
}
@@ -213,8 +213,10 @@ public abstract class BaseMigration implements MigrationModelInterface {
}
protected void dropTable(String tableName) throws SQLException, IOException {
String dropSql = "DROP TABLE " + tableName;
executeStatement(dropSql);
if (existsTable(tableName)) {
String dropSql = "DROP TABLE " + tableName;
executeStatement(dropSql);
}
}
protected void createSetupQuery(String codQuery, String name, String query) throws SQLException, IOException {