Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public boolean isSupported() {
@Override
public boolean isTablePresent(DataSource dataSource, String tableName) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
// Use current_schema for consistency with getTableColumns() and getTableIndexes().
// This ensures tenant-specific schemas work correctly (FINERACT-2468).
Integer result = jdbcTemplate.queryForObject(
"SELECT COUNT(table_name) FROM information_schema.tables " + "WHERE table_schema = 'public' AND table_name = ?",
"SELECT COUNT(table_name) FROM information_schema.tables " + "WHERE table_schema = current_schema() AND table_name = ?",
Integer.class, tableName);
return Objects.equals(result, 1);
}
Expand All @@ -55,7 +57,7 @@ public SqlRowSet getTableColumns(DataSource dataSource, String tableName) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
String sql = "SELECT column_name, is_nullable, data_type,"
+ " coalesce(character_maximum_length, numeric_precision, datetime_precision) AS max_length, ordinal_position = 1 AS column_key"
+ " FROM information_schema.columns WHERE table_catalog = current_catalog AND table_schema = current_schema AND table_name = ? ORDER BY ordinal_position";
+ " FROM information_schema.columns WHERE table_catalog = current_catalog AND table_schema = current_schema() AND table_name = ? ORDER BY ordinal_position";
final SqlRowSet columnDefinitions = jdbcTemplate.queryForRowSet(sql, tableName); // NOSONAR
if (columnDefinitions.next()) {
return columnDefinitions;
Expand All @@ -67,7 +69,10 @@ public SqlRowSet getTableColumns(DataSource dataSource, String tableName) {
@Override
public List<IndexDetail> getTableIndexes(DataSource dataSource, String tableName) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
String sql = "SELECT indexname FROM pg_indexes WHERE schemaname = 'public' AND tablename = ?";
// Use current_schema instead of hardcoded 'public' to support tenant-specific schemas.
// This fixes datatable operations in multi-tenant PostgreSQL deployments where
// datatables reside in non-public schemas (FINERACT-2468).
String sql = "SELECT indexname FROM pg_indexes WHERE schemaname = current_schema() AND tablename = ?";
final SqlRowSet indexDefinitions = jdbcTemplate.queryForRowSet(sql, tableName); // NOSONAR
if (indexDefinitions.next()) {
return DatabaseIndexMapper.getIndexDetails(indexDefinitions);
Expand Down
Loading