Skip to content

feat: implement internal resource filtering in createDbSchemaTrees - #477

Merged
dmitriy-kostianetskiy merged 9 commits into
mainfrom
feat/filter-out-internal-assets
Mar 25, 2026
Merged

dmitriy-kostianetskiy merged 9 commits into
mainfrom
feat/filter-out-internal-assets

Conversation

@dmitriy-kostianetskiy

@dmitriy-kostianetskiy dmitriy-kostianetskiy commented Mar 17, 2026 •

Copy link
Copy Markdown
Collaborator

Issue: #437

This pull request introduces comprehensive filtering logic to hide internal SQLRooms resources from the database schema tree and adds thorough tests to ensure this functionality. The main focus is to ensure that any databases or schemas prefixed with __sqlrooms_ are excluded from the UI, while still allowing user-created resources with other __ prefixes. The changes also include a basic test for tree structure creation.

Filtering internal resources:

  • Added the isInternalSqlRoomsResource function in schemaTree.ts to identify internal SQLRooms resources by their name prefix (__sqlrooms_).
  • Updated createDbSchemaTrees in schemaTree.ts to skip any databases or schemas identified as internal SQLRooms resources, ensuring they are not included in the schema tree.

Testing improvements:

  • Added a suite of tests in schemaTree.test.ts to verify filtering of internal SQLRooms databases and schemas, correct handling of user databases with __ prefix, mixed resource scenarios, and default database behavior.
  • Included a basic functionality test in schemaTree.test.ts to confirm that the schema tree is correctly constructed for standard cases.

Summary by CodeRabbit

  • New Features

    • Added optional filtering capability for database schema loading
  • Tests

    • Added validation tests for schema tree structure
  • Chores

    • Removed unused code and updated repository configuration

@coderabbitai

coderabbitai Bot commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds table schema loading filters to exclude __sqlrooms_ prefixed relations, extends the DuckDB slice configuration with an optional filter parameter, adds comprehensive tests for schema tree construction, and includes minor maintenance updates.

Changes

Cohort / File(s) Summary
Schema Filtering Feature
packages/duckdb/src/DuckDbSlice.ts, packages/duckdb/src/index.ts
Added createDefaultLoadTableSchemasFilter function to exclude tables starting with __sqlrooms_, extended CreateDuckDbSliceProps with optional loadTableSchemasFilter parameter, and updated loadTableSchemas() to conditionally include tables based on the filter.
Schema Tree Testing
packages/duckdb-core/src/schema-tree/__tests__/schemaTree.test.ts
New Jest test file validating createDbSchemaTrees functionality, verifying correct construction of database, schema, table, and column hierarchy nodes.
Maintenance
packages/cells/src/cellsSlice.ts, .gitignore
Removed empty async initialization action from cells slice state; added .worktrees/ directory to Git ignore patterns.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A filter hops through tables fair,
Excluding names with underscores to spare,
Schema trees now tested true,
New capabilities in each line, through and through! 🌳

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title claims to implement filtering in createDbSchemaTrees, but the actual primary changes are in DuckDbSlice.ts with the loadTableSchemasFilter mechanism; createDbSchemaTrees changes are not evident in the provided summary. Update title to reflect the primary implementation: 'feat: add loadTableSchemasFilter to DuckDbSlice for filtering internal resources' or similar, as the filter logic moved from schemaTree to DuckDbSlice.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/filter-out-internal-assets

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/duckdb-core/src/schema-tree/__tests__/schemaTree.test.ts (1)

8-315: Consider a small fixture builder to reduce test duplication.

A local makeTable(...) helper would make this suite easier to extend and maintain.

Refactor sketch
+const makeTable = ({
+  database,
+  schema,
+  tableName,
+  columns = [{name: 'id', type: 'INTEGER'}],
+}: {
+  database?: string;
+  schema: string;
+  tableName: string;
+  columns?: {name: string; type: string}[];
+}): DataTable => ({
+  table: {
+    database,
+    schema,
+    table: tableName,
+    toString: () => [database, schema, tableName].filter(Boolean).join('.'),
+  },
+  isView: false,
+  database,
+  schema,
+  tableName,
+  columns,
+});
-{
-  table: {
-    database: 'main',
-    schema: 'public',
-    table: 'users',
-    toString: () => 'main.public.users',
-  },
-  isView: false,
-  database: 'main',
-  schema: 'public',
-  tableName: 'users',
-  columns: [{name: 'id', type: 'INTEGER'}, {name: 'name', type: 'VARCHAR'}],
-},
+makeTable({
+  database: 'main',
+  schema: 'public',
+  tableName: 'users',
+  columns: [{name: 'id', type: 'INTEGER'}, {name: 'name', type: 'VARCHAR'}],
+}),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/duckdb-core/src/schema-tree/__tests__/schemaTree.test.ts` around
lines 8 - 315, Tests repeat identical DataTable fixtures; introduce a local
helper (e.g., makeTable) in schemaTree.test.ts to build DataTable objects to
reduce duplication. Add a function named makeTable(database?, schema, tableName,
columns?, isView?) that returns the same shape used in the tests (including the
nested table object with toString), then replace the repeated literal objects in
each it(...) case with calls to makeTable('__sqlrooms_ephemeral','main','temp',
[{name:'id',type:'INTEGER'}]) etc.; update all tests that construct tables
(including cases for default DB where database is omitted) to use makeTable so
fixtures are concise and consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/duckdb-core/src/schema-tree/__tests__/schemaTree.test.ts`:
- Around line 8-315: Tests repeat identical DataTable fixtures; introduce a
local helper (e.g., makeTable) in schemaTree.test.ts to build DataTable objects
to reduce duplication. Add a function named makeTable(database?, schema,
tableName, columns?, isView?) that returns the same shape used in the tests
(including the nested table object with toString), then replace the repeated
literal objects in each it(...) case with calls to
makeTable('__sqlrooms_ephemeral','main','temp', [{name:'id',type:'INTEGER'}])
etc.; update all tests that construct tables (including cases for default DB
where database is omitted) to use makeTable so fixtures are concise and
consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: efbc3599-0305-49be-b0b0-7d5a9cdb54ea

📥 Commits

Reviewing files that changed from the base of the PR and between 0d16adb and ac1a24e.

📒 Files selected for processing (2)
  • packages/duckdb-core/src/schema-tree/__tests__/schemaTree.test.ts
  • packages/duckdb-core/src/schema-tree/schemaTree.ts

@ilyabo ilyabo left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not filter just in schemaTree, but implement it on the level of DuckDbSlice loadTableSchemas. It already accepts a filter prop. What I would suggest to do is adding an optional loadTableSchemasFilter?: (table: QualifiedTableName) => boolean prop to CreateDuckDbSliceProps and applying it in loadTableSchemas. Then we can pass the __sqlrooms filter in the CLI app.

Or maybe the default can filter all __sqlrooms* schemas and databases out.

@dmitriy-kostianetskiy

Copy link
Copy Markdown
Collaborator Author

I think we should not filter just in schemaTree, but implement it on the level of DuckDbSlice loadTableSchemas. It already accepts a filter prop. What I would suggest to do is adding an optional loadTableSchemasFilter?: (table: QualifiedTableName) => boolean prop to CreateDuckDbSliceProps and applying it in loadTableSchemas. Then we can pass the __sqlrooms filter in the CLI app.

Or maybe the default can filter all __sqlrooms* schemas and databases out.

Agreed, I would filter all __sqlrooms* schemas and databases out.

@dmitriy-kostianetskiy

Copy link
Copy Markdown
Collaborator Author

I think we should not filter just in schemaTree, but implement it on the level of DuckDbSlice loadTableSchemas. It already accepts a filter prop. What I would suggest to do is adding an optional loadTableSchemasFilter?: (table: QualifiedTableName) => boolean prop to CreateDuckDbSliceProps and applying it in loadTableSchemas. Then we can pass the __sqlrooms filter in the CLI app.
Or maybe the default can filter all __sqlrooms* schemas and databases out.

Agreed, I would filter all __sqlrooms* schemas and databases out.

@copilot can you implement this suggestion

Copilot AI commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

@dmitriy-kostianetskiy I've opened a new pull request, #481, to work on those changes. Once the pull request is ready, I'll request review from you.

Comment thread packages/duckdb/src/DuckDbSlice.ts Outdated
@@ -487,6 +488,17 @@ export function createDuckDbSlice({
filter?: SchemaAndDatabase & {table?: string},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like Copilot didn't follow the instructions carefully

What I would suggest to do is adding an optional loadTableSchemasFilter?: (table: QualifiedTableName) => boolean prop to CreateDuckDbSliceProps and applying it in loadTableSchemas. Then we can pass the __sqlrooms filter in the CLI app.
Or maybe the default can filter all __sqlrooms* schemas and databases out.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the idea was to filter out all __sqlrooms* schemas by default, which this change effectively does at the sql level.

do you want me to pass it via filter parameter? If yes I have to two points to clarify:

  1. Current implementation is very effective sql-level include filter. We can add a function like you described, however it won't be part of SQL query anymore, but predicate for javascript .filter. If you think this is fine, I can refactor it this way.
  2. More conceptually, why would we need to that in the first place? What are the use cases for that sort of flexible filtering?

@dmitriy-kostianetskiy
dmitriy-kostianetskiy force-pushed the feat/filter-out-internal-assets branch from 264b44b to f8d88b6 Compare March 20, 2026 12:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
packages/duckdb/src/DuckDbSlice.ts (1)

32-44: ⚠️ Potential issue | 🟠 Major

Widen the default hidden-resource prefix to __sqlrooms*.

The review thread on this PR asked for all __sqlrooms* schemas/databases to be hidden by default. __sqlrooms_ only catches the underscored form, so __sqlrooms and __sqlroomsFoo still slip through. Please broaden the prefix check and align the public docstring with that rule.

Suggested patch
-const INTERNAL_SQLROOMS_PREFIX = '__sqlrooms_';
+const INTERNAL_SQLROOMS_PREFIX = '__sqlrooms';

 /**
- * Default filter to exclude internal SQLRooms tables, schemas, and databases
+ * Default filter to exclude internal SQLRooms schemas and databases
  */
 export const createDefaultLoadTableSchemasFilter = (
   table: QualifiedTableName,
 ): boolean => {
@@
   /**
    * Optional filter function to control which tables are included when loading schemas.
-   * By default, filters out tables/schemas/databases starting with '__sqlrooms_'.
+   * By default, filters out schemas/databases starting with '__sqlrooms'.
    * Pass `null` to disable filtering and show all tables.

Also applies to: 306-313

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/duckdb/src/DuckDbSlice.ts` around lines 32 - 44, The default
hidden-resource prefix constant INTERNAL_SQLROOMS_PREFIX and the filter
createDefaultLoadTableSchemasFilter should be broadened from '__sqlrooms_' to
'__sqlrooms' and the docstring updated accordingly; change
INTERNAL_SQLROOMS_PREFIX = '__sqlrooms' and ensure
createDefaultLoadTableSchemasFilter still uses startsWith on table.database and
table.schema (QualifiedTableName) so any name beginning with '__sqlrooms' (e.g.
'__sqlrooms', '__sqlroomsFoo', '__sqlrooms_bar') is excluded by default, and
update the comment above the function to state it hides all '__sqlrooms*'
schemas/databases.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/duckdb/src/DuckDbSlice.ts`:
- Around line 600-606: loadTableSchemas' visibility filter
(loadTableSchemasFilter) can hide exact lookups and make addTable and
checkTableExists fail after a successful write; update loadTableSchemas to
accept an optional bypass flag (e.g., bypassFilter: boolean = false) or a
separate internal path (e.g., loadTableSchemaByName) that ignores
loadTableSchemasFilter when performing exact/qualified lookups, and then call
that bypass from addTable and checkTableExists (or pass bypassFilter=true) so
dataTable.table exact matches are not filtered out; ensure default behavior
still applies for normal listing calls.

---

Duplicate comments:
In `@packages/duckdb/src/DuckDbSlice.ts`:
- Around line 32-44: The default hidden-resource prefix constant
INTERNAL_SQLROOMS_PREFIX and the filter createDefaultLoadTableSchemasFilter
should be broadened from '__sqlrooms_' to '__sqlrooms' and the docstring updated
accordingly; change INTERNAL_SQLROOMS_PREFIX = '__sqlrooms' and ensure
createDefaultLoadTableSchemasFilter still uses startsWith on table.database and
table.schema (QualifiedTableName) so any name beginning with '__sqlrooms' (e.g.
'__sqlrooms', '__sqlroomsFoo', '__sqlrooms_bar') is excluded by default, and
update the comment above the function to state it hides all '__sqlrooms*'
schemas/databases.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8aede73f-32e2-4990-bc9d-edb7408b06d3

📥 Commits

Reviewing files that changed from the base of the PR and between ac1a24e and f8d88b6.

📒 Files selected for processing (4)
  • packages/cells/src/cellsSlice.ts
  • packages/duckdb-core/src/schema-tree/__tests__/schemaTree.test.ts
  • packages/duckdb/src/DuckDbSlice.ts
  • packages/duckdb/src/index.ts
💤 Files with no reviewable changes (1)
  • packages/cells/src/cellsSlice.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/duckdb-core/src/schema-tree/tests/schemaTree.test.ts

Comment thread packages/duckdb/src/DuckDbSlice.ts Outdated
@dmitriy-kostianetskiy
dmitriy-kostianetskiy merged commit a5f4220 into main Mar 25, 2026
3 checks passed
@dmitriy-kostianetskiy
dmitriy-kostianetskiy deleted the feat/filter-out-internal-assets branch March 25, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants