Skip to content

Commit

Permalink
Merge pull request #362 from liquibase/DAT-18635
Browse files Browse the repository at this point in the history
DAT-18635: check of datasets on connect command added.
  • Loading branch information
SvampX authored Nov 26, 2024
2 parents 3d8acf2 + 3da6617 commit 2b64fff
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import liquibase.structure.DatabaseObject;
import liquibase.structure.core.*;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -358,4 +360,23 @@ private Set<String> getDefaultReservedWords() {

return reservedWords;
}

@Override
public void checkDatabaseConnection() throws DatabaseException {
BigQueryConnection connection = (BigQueryConnection) getConnection();
try {
String catalogName = getConnectionCatalogName();
String schemaName = getConnectionSchemaName();
ResultSet schemasAlikeUsed = connection.getMetaData().getSchemas(catalogName, schemaName);
while (schemasAlikeUsed.next()) {
if (schemasAlikeUsed.getString(1).equals(schemaName)) {
return;
}
}
throw new DatabaseException(String.format("Please specify existing dataset in connection url. " +
"Current connection points to '%s.%s'", catalogName, schemaName));
} catch (SQLException e) {
Scope.getCurrentScope().getLog(getClass()).info("Error checking database connection", e);
}
}
}

0 comments on commit 2b64fff

Please sign in to comment.