Skip to content

Commit f37ed02

Browse files
FINERACT-2468: Fix datatable operations in PostgreSQL non-public schemas
Use current_schema instead of hardcoded 'public' in getTableIndexes() and isTablePresent() methods to support multi-tenant PostgreSQL deployments where datatables reside in tenant-specific schemas. This fixes: - GET /datatables returning 404 for new datatables - Datatable save operations failing with 'Datatable not found' Root cause: Index metadata queries were looking in 'public' schema while table columns query correctly used current_schema, causing inconsistent behavior in GenericDataServiceImpl. Changes: - PostgreSQLQueryService.getTableIndexes(): Use current_schema - PostgreSQLQueryService.isTablePresent(): Use current_schema Testing: - All unit tests pass (93/93 in fineract-core) - Manual PostgreSQL verification confirms fix works correctly
1 parent ef12056 commit f37ed02

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

fineract-core/src/main/java/org/apache/fineract/infrastructure/core/service/database/PostgreSQLQueryService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ public boolean isSupported() {
4444
@Override
4545
public boolean isTablePresent(DataSource dataSource, String tableName) {
4646
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
47+
// Use current_schema for consistency with getTableColumns() and getTableIndexes().
48+
// This ensures tenant-specific schemas work correctly (FINERACT-2468).
4749
Integer result = jdbcTemplate.queryForObject(
48-
"SELECT COUNT(table_name) FROM information_schema.tables " + "WHERE table_schema = 'public' AND table_name = ?",
50+
"SELECT COUNT(table_name) FROM information_schema.tables " + "WHERE table_schema = current_schema AND table_name = ?",
4951
Integer.class, tableName);
5052
return Objects.equals(result, 1);
5153
}
@@ -67,7 +69,10 @@ public SqlRowSet getTableColumns(DataSource dataSource, String tableName) {
6769
@Override
6870
public List<IndexDetail> getTableIndexes(DataSource dataSource, String tableName) {
6971
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
70-
String sql = "SELECT indexname FROM pg_indexes WHERE schemaname = 'public' AND tablename = ?";
72+
// Use current_schema instead of hardcoded 'public' to support tenant-specific schemas.
73+
// This fixes datatable operations in multi-tenant PostgreSQL deployments where
74+
// datatables reside in non-public schemas (FINERACT-2468).
75+
String sql = "SELECT indexname FROM pg_indexes WHERE schemaname = current_schema AND tablename = ?";
7176
final SqlRowSet indexDefinitions = jdbcTemplate.queryForRowSet(sql, tableName); // NOSONAR
7277
if (indexDefinitions.next()) {
7378
return DatabaseIndexMapper.getIndexDetails(indexDefinitions);

0 commit comments

Comments
 (0)