loopbackio / loopbackio/loopback-next
Multi-tenancy and dynamic schema selection
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
Recently, several people asked about implementing dynamic schema selection to enable schema-base multi-tenancy, where tenant isolation is achieved via DDL Schemas. (If you are not familiar with DDL schemas then you can learn the basics e.g. in PostgreSQL docs).
I am opening this Epic to do discuss possible solutions, implement necessary improvements and document how to implement multi-tenancy, possibly including an example app.
Related discussions:
- Loopback 4, Model, PostgresDB schema name https://github.com/strongloop/loopback-next/issues/5055
- StackOverflow question: Schema based Multi tenancy in Loopback 4
- StackOverflow answer: How to attach a single model (e.g. Product) to multiple datasources (LB3)
- StackOverflow anwser: How to prefix model name with tenant id (LB3)
Aspects to consider:
- CLI should recognize dynamic repository/datasource in commands like
lb4 datasource - How to boot custom artifacts - we can improve
@loopback/boot(if needed) or move the registration to a different place (e.g. from a datasource file to a boot script) - How to migrate/update database tables for all tenants when the model shape changes
- How to onboard a new tenant (create the new schema & all tables)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the related LoopBack 4 issue 5055 and the linked PostgreSQL schema documentation. Review the listed concerns around CLI commands, @loopback/boot, migrations, and tenant onboarding to determine the design scope. Done would require an agreed solution, implementation improvements, documentation, and possibly an example app.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, typescript
- Domain
- backend, cli, databases, documentation
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100