Skip to content

feat(tree-entity): support configuring closure table schema - #10743

Closed
andimattes wants to merge 6 commits into
typeorm:masterfrom
andimattes:closure-table-schema
Closed

andimattes wants to merge 6 commits into
typeorm:masterfrom
andimattes:closure-table-schema

Conversation

@andimattes

@andimattes andimattes commented Feb 28, 2024 •

Copy link
Copy Markdown

Description of change

Adds closureTableSchema to ClosureTreeOptions to define the schema of the closure table.

Added tests & documentation

Based on #10716

Closes: #10263

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run format to apply prettier formatting
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change
  • The new commits follow conventions explained in CONTRIBUTING.md

Adds the option 'closureTableSchema' to define the schema of the closure table.

closes: typeorm#10263

@gioboa gioboa 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.

Thanks @andimattes for your help.
I added this PR to our release board

@gioboa gioboa mentioned this pull request Jan 21, 2025
7 tasks
@gioboa gioboa added the size-m label Jan 24, 2025

@gioboa gioboa 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.

@andimattes Can I ask you to solve the conflicts please?

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jan 14, 2026 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Latest suggestions up to e7fcd9b

CategorySuggestion                                                                                                                                    Impact
Possible issue
Preserve correct default schema behavior

Modify the closure table schema resolution to fall back to the parent entity's
schema if closureTableSchema is not explicitly provided.

src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts [28-43]

 const entityMetadata = new EntityMetadata({
     parentClosureEntityMetadata: parentClosureEntityMetadata,
     connection: this.dataSource,
     args: {
         target: "",
         name:
             parentClosureEntityMetadata.treeOptions &&
             parentClosureEntityMetadata.treeOptions.closureTableName
                 ? parentClosureEntityMetadata.treeOptions
                       .closureTableName
                 : parentClosureEntityMetadata.tableNameWithoutPrefix,
         type: "closure-junction",
-        schema: parentClosureEntityMetadata.treeOptions
-            ?.closureTableSchema,
+        schema:
+            parentClosureEntityMetadata.treeOptions?.closureTableSchema &&
+            parentClosureEntityMetadata.treeOptions.closureTableSchema.trim() !== ""
+                ? parentClosureEntityMetadata.treeOptions.closureTableSchema
+                : parentClosureEntityMetadata.schema,
     },
 })

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies a logic flaw where not providing closureTableSchema would result in the closure table being created in the default schema instead of inheriting the parent entity's schema, which is unexpected and incorrect behavior.

Medium
Prevent flaky assertions and leaks

Refactor the test to prevent connection leaks by releasing the queryRunner in a
finally block and make the table name assertion more robust across different
database drivers.

test/github-issues/10263/issue-10263.test.ts [23-37]

 it("should create the closure table in the specified schema", () =>
     Promise.all(
         dataSources.map(async (connection) => {
             const queryRunner = connection.createQueryRunner()
-            const table = (await queryRunner.getTable(
-                "test_schema.category_xyz_closure",
-            ))!
-            expect(table.database).to.not.be.undefined
-            expect(table.schema).to.be.equal("test_schema")
-            expect(table.name).to.be.equal(
-                "test_schema.category_xyz_closure",
-            )
-            await queryRunner.release()
+            try {
+                const table = (await queryRunner.getTable(
+                    "test_schema.category_xyz_closure",
+                ))!
+                expect(table.database).to.not.be.undefined
+                expect(table.schema).to.be.equal("test_schema")
+                expect(table.name).to.be.equal("category_xyz_closure")
+            } finally {
+                await queryRunner.release()
+            }
         }),
     ))
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly improves the test's robustness by adding a try...finally block to prevent connection leaks and by making the assertion on table.name more generic, which is good practice for cross-driver compatibility.

Medium
  • Update

Previous suggestions

Suggestions up to commit bf125a8
CategorySuggestion                                                                                                                                    Impact
Possible issue
Add fallback to parent schema

Modify the closure table schema logic to fall back to the parent entity's schema
if closureTableSchema is not explicitly defined in the tree options.

src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts [39-40]

 schema: parentClosureEntityMetadata.treeOptions
-    ?.closureTableSchema,
+    ?.closureTableSchema ?? parentClosureEntityMetadata.schema,
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that the closure table schema should default to the parent entity's schema if not explicitly provided, which is a sensible improvement for consistency and user experience.

Medium
Suggestions up to commit 13cb8f4
CategorySuggestion                                                                                                                                    Impact
Possible issue
Add fallback to parent schema

Fallback to the parent entity's schema for the closure table when
closureTableSchema is not explicitly provided.

src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts [39-40]

 schema: parentClosureEntityMetadata.treeOptions
-    ?.closureTableSchema,
+    ?.closureTableSchema ?? parentClosureEntityMetadata.schema,
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly proposes to use the parent entity's schema as a fallback, which is a sensible default behavior that improves the new feature's robustness and user experience.

Medium
Suggestions up to commit a9632d5
CategorySuggestion                                                                                                                                    Impact
Possible issue
Add missing await for Promise.all

Add a missing await before Promise.all in the test case to ensure assertions are
executed before the test completes.

test/github-issues/10263/issue-10263.ts [34-46]

 it("should have correctly named ancestor and descendant columns", async () => {
-    Promise.all(
+    await Promise.all(
         dataSources.map(async (connection) => {
             const queryRunner = connection.createQueryRunner();
             const table = await queryRunner.getTable("test_schema.category_xyz_closure");
             const ancestorColumn = table?.columns.find(column => column.name === "ancestor_xyz_id");
             const descendantColumn = table?.columns.find(column => column.name === "descendant_xyz_id");
             expect(ancestorColumn).to.exist;
             expect(descendantColumn).to.exist;
             await queryRunner.release();
         }),
     )
 });
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a critical bug in the test case where a missing await for Promise.all would cause the test to always pass, rendering it ineffective.

High
General
Add null check for table

Replace the non-null assertion on the table variable with an explicit
expect(table).to.not.be.undefined check to improve test clarity and safety.

test/github-issues/10263/issue-10263.ts [25-28]

-const table = (await queryRunner.getTable("test_schema.category_xyz_closure"))!
-expect(table.database).to.not.be.undefined
-expect(table.schema).to.be.equal("test_schema")
-expect(table.name).to.be.equal("test_schema.category_xyz_closure")
+const table = await queryRunner.getTable("test_schema.category_xyz_closure")
+expect(table).to.not.be.undefined
+expect(table!.database).to.not.be.undefined
+expect(table!.schema).to.be.equal("test_schema")
+expect(table!.name).to.be.equal("test_schema.category_xyz_closure")
Suggestion importance[1-10]: 5

__

Why: The suggestion correctly points out the risk of using a non-null assertion (!). However, the proposed change is functionally equivalent to the existing code and does not significantly improve robustness, as a failing test is the intended outcome if the table is not found.

Low

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jan 14, 2026 •

Copy link
Copy Markdown

Code Review by Qodo (Alpha)

(Review updated until commit bf125a8)

🐞 Bugs (0) 📘 Rule Violations (0) 📎 Requirement Gaps (0) 💡 Suggestions (0)

Grey Divider

Great, No Issues Found!

Qodo reviewed your code and found no material issues that require review

Grey Divider


Previous review results

Results up to commit 13cb8f4


🐞 Bugs (0) 📘 Rule Violations (0) 📎 Requirement Gaps (0) 💡 Suggestions (0)

Grey Divider

Great, No Issues Found!

Qodo reviewed your code and found no material issues that require review Grey Divider
Results up to commit a9632d5


🐞 Bugs (3) 📘 Rule Violations (0) 📎 Requirement Gaps (0) 💡 Suggestions (0)

Grey Divider
Action Required
1. Missing return in async test 🐞 Bug
Description
• The second test function declares itself as async but doesn't return the Promise.all() call
• This causes the test to complete immediately without waiting for async operations
• Assertions that fail inside the Promise callbacks won't cause the test to fail, creating false
  positives

correctness

Code

test/github-issues/10263/issue-10263.ts[R34-46]

+    it("should have correctly named ancestor and descendant columns", async () => {
+        Promise.all(
+            dataSources.map(async (connection) => {
+                const queryRunner = connection.createQueryRunner();
+                const table = await queryRunner.getTable("test_schema.category_xyz_closure");
+                const ancestorColumn = table?.columns.find(column => column.name === "ancestor_xyz_id");
+                const descendantColumn = table?.columns.find(column => column.name === "descendant_xyz_id");
+                expect(ancestorColumn).to.exist;
+                expect(descendantColumn).to.exist;
+                await queryRunner.release();
+            }),
+        )
+    });
Evidence
The test at lines 34-46 is missing a return statement before Promise.all(), while the first test at
lines 21-32 correctly returns it. This pattern is confirmed by other closure table tests in the
codebase. Without the return, the test completes before assertions execute, potentially hiding
failures.

test/github-issues/10263/issue-10263.ts[34-46]
test/github-issues/10263/issue-10263.ts[21-32]

Agent Prompt
## Issue Description
The second test function in the file is declared as async but doesn't return the Promise.all() call, causing the test to complete before assertions execute.

## Issue Context
This is a common async testing anti-pattern where the test framework doesn't wait for the promise to resolve, potentially hiding test failures.

## Fix Focus Areas
- test/github-issues/10263/issue-10263.ts[34-46]

Change line 35 from:
```typescript
it("should have correctly named ancestor and descendant columns", async () => {
   Promise.all(
```

To:
```typescript
it("should have correctly named ancestor and descendant columns", async () => {
   return Promise.all(
```

Or alternatively, change the arrow function to not use async and return the Promise directly (matching the first test pattern).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation Recommended
2. Missing schema fallback to parent 🐞 Bug
Description
• When closureTableSchema is not provided, the closure junction table doesn't inherit the parent
  entity's schema
• This is inconsistent with JunctionEntityMetadataBuilder which uses fallback: schema:
  joinTable.schema || relation.entityMetadata.schema
• Users who set schema on their entity but don't explicitly set closureTableSchema will have closure
  tables created in the wrong schema

correctness

Code

src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts[R39-40]

+                schema: parentClosureEntityMetadata.treeOptions
+                    ?.closureTableSchema,
Evidence
The ClosureJunctionEntityMetadataBuilder sets schema directly from closureTableSchema without
fallback, while JunctionEntityMetadataBuilder provides a fallback to the parent entity's schema.
This inconsistency means closure tables won't inherit the parent entity's schema when
closureTableSchema is undefined, potentially creating tables in the default schema instead of the
intended one.

src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts[27-42]
src/metadata-builder/JunctionEntityMetadataBuilder.ts[53-64]

Agent Prompt
## Issue Description
The closure junction table doesn't inherit the parent entity's schema when closureTableSchema is not explicitly provided, which is inconsistent with how regular junction tables handle schema inheritance.

## Issue Context
JunctionEntityMetadataBuilder uses a fallback pattern: `schema: joinTable.schema || relation.entityMetadata.schema`. The ClosureJunctionEntityMetadataBuilder should follow the same pattern to ensure closure tables are created in the same schema as their parent entity when not explicitly specified.

## Fix Focus Areas
- src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts[39-40]

Change:
```typescript
schema: parentClosureEntityMetadata.treeOptions
   ?.closureTableSchema,
```

To:
```typescript
schema: parentClosureEntityMetadata.treeOptions?.closureTableSchema ||
   parentClosureEntityMetadata.schema,
```

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Empty string in documentation example 🐞 Bug
Description
• The documentation example shows closureTableSchema set to an empty string
• Empty string is a truthy value that would be passed through to EntityMetadata
• This could cause unexpected behavior in schema resolution or SQL generation

correctness

Code

docs/docs/entity/4-tree-entities.md[151]

+    closureTableSchema: "",
Evidence
The documentation example includes closureTableSchema with an empty string value. In
EntityMetadata.build(), line 988 checks 'if (this.tableMetadataArgs.schema)' which evaluates to
false for empty strings in JavaScript, but the intent is unclear. This could confuse users or lead
to unexpected behavior if the empty string is treated differently than undefined.

docs/docs/entity/4-tree-entities.md[148-153]
src/metadata/EntityMetadata.ts[988-997]

Agent Prompt
## Issue Description
The documentation example shows closureTableSchema set to an empty string, which is likely unintentional and could confuse users about the proper usage of this option.

## Issue Context
The documentation is demonstrating the new closureTableSchema option, but the empty string value doesn't represent a realistic use case. Users should either omit the field or provide a valid schema name.

## Fix Focus Areas
- docs/docs/entity/4-tree-entities.md[151]

Either remove the line entirely:
```typescript
@Tree("closure-table", {
   closureTableName: "category_closure",
   ancestorColumnName: (column) => "ancestor_" + column.propertyName,
   descendantColumnName: (column) => "descendant_" + column.propertyName,
})
```

Or use a meaningful example:
```typescript
@Tree("closure-table", {
   closureTableName: "category_closure",
   closureTableSchema: "my_schema",
   ancestorColumnName: (column) => "ancestor_" + column.propertyName,
   descendantColumnName: (column) => "descendant_" + column.propertyName,
})
```

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider
Qodo Logo

@gioboa gioboa changed the title feat: Postgres @Tree specify schema for closure tables feat: improve Postgres @Tree specify schema for closure tables Jan 14, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jan 14, 2026 •

Copy link
Copy Markdown
  • typeorm-sql-js-example

    npm i https://pkg.pr.new/typeorm/typeorm@10743
    

commit: e7fcd9b

@coveralls

coveralls commented Jan 14, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 81.42% (+0.001%) from 81.419%
when pulling e7fcd9b on andimattes:closure-table-schema
into f47246c on typeorm:master.

@alumni

alumni commented Jan 15, 2026 •

Copy link
Copy Markdown
Collaborator

@andimattes thanks for this contribution!

Could you please fix the merge conflicts, rename the test file to end with .test.ts and fix the lint error?

Also, I'm wondering whether the schema should not be inherited from the entity. Basically, I'm thinking the priority should be treeOptions.closureTableSchema (if we want to keep it), entityOptions.schema, dataSourceOptions.schema.

@alumni alumni changed the title feat: improve Postgres @Tree specify schema for closure tables feat(tree-entity): support configuring closure table schema Jan 15, 2026

@gioboa gioboa 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.

Could you please rename the test file to end with .test.ts and fix the lint error?

I did it, let's see if tests are passing 🤞

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Persistent review updated to latest commit 13cb8f4

@gioboa
gioboa requested review from G0maa, alumni and naorpeled January 17, 2026 13:28

@gioboa gioboa 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.

Thanks @andimattes for your help.

Also, I'm wondering whether the schema should not be inherited from the entity. Basically, I'm thinking the priority should be treeOptions.closureTableSchema (if we want to keep it), entityOptions.schema, dataSourceOptions.schema.

Can you address or answer at this feedback from @alumni please?

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Persistent review updated to latest commit bf125a8

@gioboa gioboa 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.

Can you address or answer at this feedback from @alumni please?

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Feb 24, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (5)   📘 Rule violations (1)   📎 Requirement gaps (0)   🎨 UX Issues (0)
🐞\ ≡ Correctness (3) ☼ Reliability (2) ⭐ New (3)
📘\ ≡ Correctness (1)

Grey Divider


Action required

1. Schema inheritance regression 🐞 ≡ ⭐
Description
ClosureJunctionEntityMetadataBuilder no longer defaults the closure table schema to the parent
entity schema, so @Tree("closure-table") entities with @Entity({ schema: ... }) will
create/query the closure table in the default schema unless closureTableSchema is explicitly
provided.
Code

src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts[R38-40]

+                schema: parentClosureEntityMetadata.treeOptions
+                    ?.closureTableSchema,
                database: parentClosureEntityMetadata.database,
Evidence
The closure junction metadata now takes schema only from treeOptions.closureTableSchema, so for
an entity like Space that sets @Entity({ schema: "my_schema" }) but does not set
closureTableSchema, the closure junction’s tableMetadataArgs.schema will be undefined.
EntityMetadata.build sets this.schema only when tableMetadataArgs.schema is truthy (or for
entity-child inheritance), so the closure junction tablePath will be built without the entity’s
schema, changing prior behavior and breaking schema isolation assumptions.

src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts[27-42]
test/github-issues/10263/entity/Space.ts[8-10]
src/metadata/EntityMetadata.ts[1008-1021]
src/metadata/EntityMetadata.ts[1076-1081]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Closure junction tables stopped inheriting the parent entity schema unless `closureTableSchema` is set, which is a breaking behavioral change for `@Tree("closure-table")` entities using non-default schemas.

## Issue Context
`Space` demonstrates the common pattern: entity has `schema: "my_schema"` but tree options do not set `closureTableSchema`. The closure junction builder now drops the schema.

## Fix Focus Areas
- Prefer preserving prior default behavior by falling back to the parent entity schema when `closureTableSchema` is `undefined`.
- Keep explicit override working when `closureTableSchema` is provided.

## Fix Focus Areas (code references)
- src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts[29-41]
- src/metadata/EntityMetadata.ts[1012-1021] (only if you decide to treat empty-string schema as intentional)

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Runtime circular import added 🐞 ☼ ⭐
Description
Changing DataSource from a type-only import to a value import in
ClosureJunctionEntityMetadataBuilder introduces a runtime circular dependency chain `DataSource ->
ConnectionMetadataBuilder -> EntityMetadataBuilder -> ClosureJunctionEntityMetadataBuilder ->
DataSource`, which can cause partially-initialized exports and hard-to-debug runtime failures in
CommonJS builds.
Code

src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts[R1-5]

+import { DataSource } from "../data-source/DataSource"
import { ColumnMetadata } from "../metadata/ColumnMetadata"
+import { EntityMetadata } from "../metadata/EntityMetadata"
import { ForeignKeyMetadata } from "../metadata/ForeignKeyMetadata"
-import type { DataSource } from "../data-source/DataSource"
import { IndexMetadata } from "../metadata/IndexMetadata"
Evidence
ClosureJunctionEntityMetadataBuilder now imports DataSource as a runtime value. DataSource.ts
imports ConnectionMetadataBuilder, which imports EntityMetadataBuilder, which imports
ClosureJunctionEntityMetadataBuilder, forming a full cycle that previously did not exist at
runtime due to the type-only import.

src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts[1-4]
src/data-source/DataSource.ts[24-30]
src/connection/ConnectionMetadataBuilder.ts[1-7]
src/metadata-builder/EntityMetadataBuilder.ts[11-16]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A runtime circular dependency was introduced by importing `DataSource` as a value when it’s only used as a type annotation.

## Issue Context
This file only uses `DataSource` in the constructor type position; importing it as a runtime value creates a CommonJS require-cycle.

## Fix Focus Areas
- Change back to `import type { DataSource } ...` and ensure no runtime usage requires a value import.

## Fix Focus Areas (code references)
- src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts[1-5]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Issue test added under github-issues 📘 ≡
Description
The PR adds new tests only under test/github-issues/10263, which conflicts with the preference to
place issue fixes in the functional test suite. Keeping this in test/github-issues without a clear
justification increases long-term maintenance cost and reduces coverage consistency.
Code

test/github-issues/10263/issue-10263.test.ts[R1-12]

+import "reflect-metadata"
+import {
+    createTestingConnections,
+    closeTestingConnections,
+    reloadTestingDatabases,
+} from "../../utils/test-utils"
+import { DataSource } from "../../../src"
+import { Category } from "./entity/Category"
+import { expect } from "chai"
+
+describe("github issues > #10263 Postgres @Tree specify schema for closure tables", () => {
+    let dataSources: DataSource[]
Evidence
Compliance ID 3 requires issue fixes to add/update tests in test/functional (with issue reference
comments when applicable) and considers it a failure when tests are only added under
test/github-issues without a clear reason. This PR introduces the new test file in
test/github-issues/10263 and labels it as a github-issues test, with no stated reason in the code
for not using test/functional.

Rule 3: Prefer functional tests over per-issue tests
test/github-issues/10263/issue-10263.test.ts[1-12]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
New coverage for issue #10263 was added only under `test/github-issues/10263`, but issue fixes should live in the functional test suite unless there is a clear exception.
## Issue Context
The PR introduces `closureTableSchema` support and adds tests for it. The current tests are placed under `test/github-issues`, which violates the testing placement guidance.
## Fix Focus Areas
- test/github-issues/10263/issue-10263.test.ts[1-57]
- test/github-issues/10263/entity/Category.ts[1-27]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

4. QueryRunner not finally released 🐞 ☼ ⭐
Description
The new tests release QueryRunners only on the happy path; if getTable or an assertion throws, the
QueryRunner is not released, potentially leaking connections and making the test suite flaky.
Code

test/github-issues/10263/issue-10263.test.ts[R25-36]

+            dataSources.map(async (connection) => {
+                const queryRunner = connection.createQueryRunner()
+                const table = (await queryRunner.getTable(
+                    "test_schema.category_xyz_closure",
+                ))!
+                expect(table.database).to.not.be.undefined
+                expect(table.schema).to.be.equal("test_schema")
+                expect(table.name).to.be.equal(
+                    "test_schema.category_xyz_closure",
+                )
+                await queryRunner.release()
+            }),
Evidence
Both test cases create a QueryRunner and call release() only after assertions. Any thrown error
skips the release call, leaving the connection checked out.

test/github-issues/10263/issue-10263.test.ts[23-36]
test/github-issues/10263/issue-10263.test.ts[39-55]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
QueryRunner must be released even when the test fails; otherwise tests can leak connections.

## Issue Context
Current tests do `createQueryRunner()` then `await queryRunner.release()` at the end without `try/finally`.

## Fix Focus Areas
- Wrap QueryRunner usage in `try { ... } finally { await queryRunner.release() }` in both test cases.

## Fix Focus Areas (code references)
- test/github-issues/10263/issue-10263.test.ts[23-37]
- test/github-issues/10263/issue-10263.test.ts[39-56]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Docs typo: descendant option 🐞 ≡
Description
Docs refer to descandantColumnName (typo) which doesn’t match the actual descendantColumnName
option name and can confuse users searching/copying from the prose.
Code

docs/docs/entity/4-tree-entities.md[146]

+You can specify the closure table name and/or closure table column names by setting optional parameter `options` into `@Tree("closure-table", options)`. `ancestorColumnName` and `descandantColumnName` are callback functions, which receive the primary column's metadata and return the column's name. `closureTableSchema` is the schema name of the closure table.
Evidence
The documentation prose misspells the option name, while the public API type defines
descendantColumnName as the valid option.

docs/docs/entity/4-tree-entities.md[146-146]
src/metadata/types/ClosureTreeOptions.ts[7-12]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The tree-entities docs prose contains a typo (`descandantColumnName`) that doesn’t match the actual option name (`descendantColumnName`).
### Issue Context
This is in the descriptive text right above the options snippet.
### Fix Focus Areas
- docs/docs/entity/4-tree-entities.md[146-146]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. Docs schema example ineffective 🐞 ≡
Description
Docs show closureTableSchema: "", but empty string is treated as “not set” when building
EntityMetadata and when building the table name, so this example won’t actually configure a schema
as the text suggests.
Code

docs/docs/entity/4-tree-entities.md[151]

+    closureTableSchema: "",
Evidence
EntityMetadata.build() only assigns this.schema when tableMetadataArgs.schema is truthy, so
"" is skipped and fallback schema rules apply. Additionally, the Postgres driver only prefixes
schema when the schema argument is truthy, so an empty string won’t be included in the table path.

docs/docs/entity/4-tree-entities.md[149-153]
src/metadata/EntityMetadata.ts[1020-1029]
src/driver/postgres/PostgresDriver.ts[1047-1055]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The docs example uses `closureTableSchema: ""`, which is effectively ignored by TypeORM’s schema/tablePath building logic, so readers won’t get the behavior the docs text implies.
### Issue Context
Empty string is falsy, and schema/table-name builders only apply schema when it’s a truthy value.
### Fix Focus Areas
- docs/docs/entity/4-tree-entities.md[151-151]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Grey Divider

Previous review results

Review updated until commit f3edd9a

Results up to commit N/A


🐞 Bugs (2)  
📘 Rule violations (1)  
📎 Requirement gaps (0)  
🎨 UX Issues (0)

🐞\ ≡ Correctness (2)
📘\ ≡ Correctness (1)

Grey Divider


Action required

1. Issue test added under github-issues 📘 ≡
Description
The PR adds new tests only under test/github-issues/10263, which conflicts with the preference to
place issue fixes in the functional test suite. Keeping this in test/github-issues without a clear
justification increases long-term maintenance cost and reduces coverage consistency.
Code

test/github-issues/10263/issue-10263.test.ts[R1-12]

+import "reflect-metadata"
+import {
+    createTestingConnections,
+    closeTestingConnections,
+    reloadTestingDatabases,
+} from "../../utils/test-utils"
+import { DataSource } from "../../../src"
+import { Category } from "./entity/Category"
+import { expect } from "chai"
+
+describe("github issues > #10263 Postgres @Tree specify schema for closure tables", () => {
+    let dataSources: DataSource[]
Evidence
Compliance ID 3 requires issue fixes to add/update tests in test/functional (with issue reference
comments when applicable) and considers it a failure when tests are only added under
test/github-issues without a clear reason. This PR introduces the new test file in
test/github-issues/10263 and labels it as a github-issues test, with no stated reason in the code
for not using test/functional.

Rule 3: Prefer functional tests over per-issue tests
test/github-issues/10263/issue-10263.test.ts[1-12]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
New coverage for issue #10263 was added only under `test/github-issues/10263`, but issue fixes should live in the functional test suite unless there is a clear exception.
## Issue Context
The PR introduces `closureTableSchema` support and adds tests for it. The current tests are placed under `test/github-issues`, which violates the testing placement guidance.
## Fix Focus Areas
- test/github-issues/10263/issue-10263.test.ts[1-57]
- test/github-issues/10263/entity/Category.ts[1-27]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Docs typo: descendant option 🐞 ≡
Description
Docs refer to descandantColumnName (typo) which doesn’t match the actual descendantColumnName
option name and can confuse users searching/copying from the prose.
Code

docs/docs/entity/4-tree-entities.md[146]

+You can specify the closure table name and/or closure table column names by setting optional parameter `options` into `@Tree("closure-table", options)`. `ancestorColumnName` and `descandantColumnName` are callback functions, which receive the primary column's metadata and return the column's name. `closureTableSchema` is the schema name of the closure table.
Evidence
The documentation prose misspells the option name, while the public API type defines
descendantColumnName as the valid option.

docs/docs/entity/4-tree-entities.md[146-146]
src/metadata/types/ClosureTreeOptions.ts[7-12]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The tree-entities docs prose contains a typo (`descandantColumnName`) that doesn’t match the actual option name (`descendantColumnName`).
### Issue Context
This is in the descriptive text right above the options snippet.
### Fix Focus Areas
- docs/docs/entity/4-tree-entities.md[146-146]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Docs schema example ineffective 🐞 ≡
Description
Docs show closureTableSchema: "", but empty string is treated as “not set” when building
EntityMetadata and when building the table name, so this example won’t actually configure a schema
as the text suggests.
Code

docs/docs/entity/4-tree-entities.md[151]

+    closureTableSchema: "",
Evidence
EntityMetadata.build() only assigns this.schema when tableMetadataArgs.schema is truthy, so
"" is skipped and fallback schema rules apply. Additionally, the Postgres driver only prefixes
schema when the schema argument is truthy, so an empty string won’t be included in the table path.

docs/docs/entity/4-tree-entities.md[149-153]
src/metadata/EntityMetadata.ts[1020-1029]
src/driver/postgres/PostgresDriver.ts[1047-1055]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The docs example uses `closureTableSchema: ""`, which is effectively ignored by TypeORM’s schema/tablePath building logic, so readers won’t get the behavior the docs text implies.
### Issue Context
Empty string is falsy, and schema/table-name builders only apply schema when it’s a truthy value.
### Fix Focus Areas
- docs/docs/entity/4-tree-entities.md[151-151]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Grey Divider

Qodo Logo

# Conflicts:
#	src/metadata-builder/ClosureJunctionEntityMetadataBuilder.ts
#	test/github-issues/10263/issue-10263.test.ts
@sonarqubecloud

Copy link
Copy Markdown

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Persistent review updated to latest commit f3edd9a

xEverth pushed a commit to xEverth/typeorm that referenced this pull request Jun 18, 2026
… the Tree decorator as typeorm#10743

Test locally with multiple database drivers which support the "schema" options
Update tests to remove driver-specific assumptions on closure table metadata's tablePath
Add functional test case for different schema options provided to the parent Entity and the Tree decorator
xEverth pushed a commit to xEverth/typeorm that referenced this pull request Jun 18, 2026
… the Tree decorator as typeorm#10743

Test locally with multiple database drivers which support the "schema" options
Update tests to remove driver-specific assumptions on closure table metadata's tablePath
Add functional test case for different schema options provided to the parent Entity and the Tree decorator
xEverth pushed a commit to xEverth/typeorm that referenced this pull request Jun 19, 2026
… the Tree decorator as typeorm#10743

Test locally with multiple database drivers which support the "schema" options
Update tests to remove driver-specific assumptions on closure table metadata's tablePath
Add functional test case for different schema options provided to the parent Entity and the Tree decorator
@alumni

alumni commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

@andimattes Thanks for the contribution - I will close the PR since it was stale and the idea was picked up and improved in #12590

@alumni alumni closed this Jun 19, 2026
@github-project-automation github-project-automation Bot moved this from Proposed to Done in TypeORM Roadmap Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Postgres @Tree specify schema for closure tables

5 participants