Skip to content

Commit 6ef0d75

Browse files
feat(editor): show and qualify multi-schema table names
Add shared schemaNames helpers and wire the SQL editor / tables overview so object browser, autocomplete, generated SQL, and index lookup APIs use schema.table for non-default schemas. Co-authored-by: Venkat SF <venkatesh.sakamuri@stayflexi.com>
1 parent 471e17e commit 6ef0d75

8 files changed

Lines changed: 335 additions & 81 deletions

File tree

backend/src/main/java/com/dbaagent/controller/SchemaController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ public ResponseEntity<Map<String, Object>> executeQuery(
260260
}
261261
}
262262

263-
@GetMapping("/tables/{tableName}/indexes")
263+
// `{tableName:.+}` keeps schema-qualified ids (`crm.orders`) as one segment.
264+
@GetMapping("/tables/{tableName:.+}/indexes")
264265
public ResponseEntity<Map<String, Object>> getTableIndexes(
265266
@PathVariable String connectionId,
266267
@PathVariable String tableName) {
@@ -292,7 +293,7 @@ public ResponseEntity<Map<String, Object>> getTableIndexes(
292293
}
293294
}
294295

295-
@GetMapping("/tables/{tableName}/stats")
296+
@GetMapping("/tables/{tableName:.+}/stats")
296297
public ResponseEntity<Map<String, Object>> getTableStats(
297298
@PathVariable String connectionId,
298299
@PathVariable String tableName) {

backend/src/main/java/com/dbaagent/provider/mysql/MySQLIntrospectionProvider.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ public List<TableIndex> getTableIndexes(Connection connection, String database,
153153
List<TableIndex> indexes = new ArrayList<>();
154154
Map<String, TableIndex> indexMap = new HashMap<>();
155155

156+
String schemaName = database;
157+
String bareName = tableName;
158+
if (tableName != null) {
159+
int dot = tableName.lastIndexOf('.');
160+
if (dot > 0) {
161+
schemaName = tableName.substring(0, dot);
162+
bareName = tableName.substring(dot + 1);
163+
}
164+
}
165+
156166
String query = """
157167
SELECT INDEX_NAME, COLUMN_NAME, NON_UNIQUE, INDEX_TYPE, SEQ_IN_INDEX
158168
FROM INFORMATION_SCHEMA.STATISTICS
@@ -161,8 +171,8 @@ public List<TableIndex> getTableIndexes(Connection connection, String database,
161171
""";
162172

163173
try (PreparedStatement stmt = connection.prepareStatement(query)) {
164-
stmt.setString(1, database);
165-
stmt.setString(2, tableName);
174+
stmt.setString(1, schemaName);
175+
stmt.setString(2, bareName);
166176

167177
try (ResultSet rs = stmt.executeQuery()) {
168178
while (rs.next()) {

backend/src/main/java/com/dbaagent/provider/postgres/PostgresIntrospectionProvider.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,18 @@ public List<TableIndex> getTableIndexes(Connection connection, String database,
204204
List<TableIndex> indexes = new ArrayList<>();
205205
Map<String, TableIndex> indexMap = new HashMap<>();
206206

207+
// Accept bare `orders` or qualified `crm.orders` so multi-schema UIs
208+
// don't silently merge indexes from every schema that shares the name.
209+
String schemaName = null;
210+
String bareName = tableName;
211+
if (tableName != null) {
212+
int dot = tableName.lastIndexOf('.');
213+
if (dot > 0) {
214+
schemaName = tableName.substring(0, dot);
215+
bareName = tableName.substring(dot + 1);
216+
}
217+
}
218+
207219
String query = """
208220
SELECT
209221
i.relname AS index_name,
@@ -212,16 +224,21 @@ public List<TableIndex> getTableIndexes(Connection connection, String database,
212224
ix.indisprimary AS is_primary,
213225
am.amname AS index_type
214226
FROM pg_class t
227+
JOIN pg_namespace n ON n.oid = t.relnamespace
215228
JOIN pg_index ix ON t.oid = ix.indrelid
216229
JOIN pg_class i ON i.oid = ix.indexrelid
217230
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey)
218231
JOIN pg_am am ON i.relam = am.oid
219-
WHERE t.relname = ?
232+
WHERE t.relkind IN ('r', 'p', 'm', 'v')
233+
AND t.relname = ?
234+
AND (?::text IS NULL OR n.nspname = ?)
220235
ORDER BY i.relname, a.attnum
221236
""";
222237

223238
try (PreparedStatement stmt = connection.prepareStatement(query)) {
224-
stmt.setString(1, tableName);
239+
stmt.setString(1, bareName);
240+
stmt.setString(2, schemaName);
241+
stmt.setString(3, schemaName);
225242

226243
try (ResultSet rs = stmt.executeQuery()) {
227244
while (rs.next()) {

0 commit comments

Comments
 (0)