Skip to content

Postgres @Tree specify schema for closure tables #10263

Description

@guenzd

Issue description

Cannot specify schema for @Tree generated closure tables

Expected Behavior

When I specifiy the schemaname in my Entity:
@entity({ name: 'testentity', schema: 'sampleschema' })

I expect that the created closure table is stored in the same schema. However it always defaults to "public".

Using:
@entity({ name: 'hierarchylevel', schema: 'masterdata' })
@Tree('closure-table', {
closureTableName: 'sampleschema.hierarchylevel',
})

I get the closure table in my schema, but the synchronize=true does not recognize it correctly and produces an error if the table exists.

Actual Behavior

I use "synchronize=true" and this closure table is generated in the schema (only due to the schema name in the clousure) but produces an error.

Steps to reproduce

@entity({ name: 'testentity', schema: 'sampleschema' })
export class TestEntity {
@column()
name: string;

@manytoone(() => HierarchyLevel, (hierarchyLevel) => hierarchyLevel.children)
hierarchyLevel: HierarchyLevel;

}

@entity({ name: 'hierarchylevel', schema: 'masterdata' })
@Tree('closure-table', {
closureTableName: 'sampleschema.hierarchylevel',
})
export class HierarchyLevel {
@column()
name: string;

@column()
description: string;

@TreeChildren()
children: HierarchyLevel[];

@TreeParent()
parent: HierarchyLevel;
}

My Environment

| Dependency | Version |
| Operating System | Windows 10 |
| Node.js version | 18.14.2 |
| Typescript version | 5.0.2 |
| TypeORM version |nestjs/typeorm 9.0.1 |

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, but I don't know how to start. I would need guidance.

Activity

  1. added a commit that references this issue on Feb 18, 2024
    1812f11
  2. tophep commented on Feb 18, 2024

    @tophep

    Potential Fix:
    #10716

  3. github-actions commented on Sep 18, 2025

    @github-actions

    TypeORM has returned to active development after recently transitioning to new leadership (see related announcement).

    As part of the new team's efforts to prioritise work on the project moving forward, it is necessary to clean up the backlog of stale issues.

    🧹 This issue is being automatically closed because it has had no activity in the last 6 months.
    If you believe this issue is still relevant, feel free to comment below and the maintainers may reopen it. Thank you for your contribution.

  4. added a commit that references this issue on Mar 6, 2026
    136f58a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions