Skip to content

Commit

Permalink
mssql test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Long Ma committed Jul 6, 2023
1 parent 806a628 commit 8d55781
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package ca.uhn.fhir.jpa.embedded;

import ca.uhn.fhir.jpa.migrate.DriverTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.MSSQLServerContainer;
import org.testcontainers.utility.DockerImageName;

Expand All @@ -34,6 +36,7 @@
* @see <a href="https://www.testcontainers.org/modules/databases/mssqlserver/">MS SQL Server TestContainer</a>
*/
public class MsSqlEmbeddedDatabase extends JpaEmbeddedDatabase {
private static final Logger ourLog = LoggerFactory.getLogger(MsSqlEmbeddedDatabase.class);

private final MSSQLServerContainer myContainer;

Expand Down Expand Up @@ -70,8 +73,18 @@ private void dropForeignKeys() {
private void dropRemainingConstraints() {
List<Map<String, Object>> queryResults = getJdbcTemplate().queryForList("SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS");
for(Map<String, Object> row : queryResults){
String tableName = row.get("TABLE_NAME").toString();
String constraintName = row.get("CONSTRAINT_NAME").toString();
Object tableNameEntry = row.get("TABLE_NAME");
if (tableNameEntry == null) {
ourLog.warn("Found a constraint with no table name: {}", row);
continue;
}
String tableName = tableNameEntry.toString();
Object constraintNameEntry = row.get("CONSTRAINT_NAME");
if (constraintNameEntry == null) {
ourLog.warn("Found a constraint with no constraint name: {}", row);
continue;
}
String constraintName = constraintNameEntry.toString();
getJdbcTemplate().execute(String.format("ALTER TABLE \"%s\" DROP CONSTRAINT \"%s\"", tableName, constraintName));
}
}
Expand Down

0 comments on commit 8d55781

Please sign in to comment.