Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add support for multiple schemas (including UoW) #2296

Merged
merged 7 commits into from
Nov 6, 2021

Conversation

B4nan
Copy link
Member

@B4nan B4nan commented Oct 24, 2021

Entity instances now hold schema name (as part of WrappedEntity). Managed entities will have the schema from FindOptions or metadata. Methods that create new entity instances like em.create() or em.getReference() now have an options parameter to allow setting the schema. We can also use wrap(entity).setSchema().

Entities can now specify @Entity({ schema: '*' }), that way they will be ignored in SchemaGenerator unless schema option is specified.

  • if we have schema specified on entity level, it only exists in that schema
  • if we have * schema on entity, it can exist in any schema, always controlled by the parameter
  • no schema on entity - default schema or from global orm config

Closes #2074

BREAKING CHANGE:
em.getReference() now has options parameter.

@codecov-commenter
Copy link

codecov-commenter commented Oct 24, 2021

Codecov Report

Merging #2296 (34b8bcf) into master (c5a5c6b) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #2296   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          186       186           
  Lines        10311     10366   +55     
  Branches      2255      2274   +19     
=========================================
+ Hits         10311     10366   +55     
Impacted Files Coverage Δ
packages/core/src/drivers/IDatabaseDriver.ts 100.00% <ø> (ø)
...core/src/naming-strategy/AbstractNamingStrategy.ts 100.00% <ø> (ø)
packages/core/src/typings.ts 100.00% <ø> (ø)
packages/cli/src/commands/SchemaCommandFactory.ts 100.00% <100.00%> (ø)
packages/core/src/EntityManager.ts 100.00% <100.00%> (ø)
packages/core/src/drivers/DatabaseDriver.ts 100.00% <100.00%> (ø)
packages/core/src/entity/BaseEntity.ts 100.00% <100.00%> (ø)
packages/core/src/entity/EntityAssigner.ts 100.00% <100.00%> (ø)
packages/core/src/entity/EntityFactory.ts 100.00% <100.00%> (ø)
packages/core/src/entity/EntityRepository.ts 100.00% <100.00%> (ø)
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5a5c6b...34b8bcf. Read the comment docs.

Closes #2074

BREAKING CHANGE:
`em.getReference()` now has options parameter.
…(WIP)

Support for working with `SchemaGenerator` with specific schema.
Entities can now specify `schema: '*'`, that way they will be ignored in schema
generator unless `schema` option is specified.

- if we have schema specified on entity level, it only exists in that schema
- if we have * schema on entity, it can exist in any schema, always controlled by the parameter
- no schema on entity - default schema or from global orm config
@B4nan B4nan merged commit d64d100 into master Nov 6, 2021
@B4nan B4nan deleted the schema-support branch November 6, 2021 13:57
@Uminily
Copy link

Uminily commented Nov 11, 2021

Thanks a lot for this feature!

@Langstra
Copy link
Collaborator

BREAKING CHANGE:
em.getReference() now has options parameter.

Should this breaking change also be described in the Upgrading from v4 to v5 docs?

@Langstra
Copy link
Collaborator

Oh yes, I must have missed that, sorry. Good job!

B4nan pushed a commit that referenced this pull request Sep 25, 2023
Hi,

I want to start with thanking you all for this great ORM that is so
actively maintained and offer so many great features. One thing that
really catches my eye is the per request (shell)EntityManager that I
think will make this ORM a winner when it comes to multi tenancy. Almost
all of the other big ORM libraries are based on a global concept.

My aim with this PR is to make a shoot at implementing schema based
multi tenancy support with help of the per request EntityManager. With
this PR it's possible to set a schema when forking the EntityManager.
That schema will be applied as a default schema if no other schema is
present. It makes use of the schema options introduced in:
#2296
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.

PostgreSQL schemas for multitenancy
4 participants