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

[Multi-Tenant] Stub out Database Connections Service #3104

Open
4 tasks
Tracked by #2893
njlie opened this issue Nov 18, 2024 · 0 comments
Open
4 tasks
Tracked by #2893

[Multi-Tenant] Stub out Database Connections Service #3104

njlie opened this issue Nov 18, 2024 · 0 comments
Labels
pkg: backend Changes in the backend package.

Comments

@njlie
Copy link
Contributor

njlie commented Nov 18, 2024

Parent Issue: #2893

The latest design for Multi-Tenancy outlines a new service called the "Database Connection Manager" that handles per-request connections to tenanted databases on the Rafiki instance.

It should maintain an in-memory data structure that maps tenant ids to active database connections, as well as methods to get those connections given a tenant id. If the connection doesn't exist, create it.

For this version of multi-tenancy, the Database Connection Manager should also extend the capability to create a new (logical) database on the Rafiki instance's postgres instance for use during tenant creation so that a databaseConnectionUrl can be provided during that process.

The basic interface for DatabaseConnectionsService is as follows:

DatabaseConnectionsService {
  connections: Record<string, Knex> // key is tenant id, value is Knex instance
  getOrCreateConnection: (tenantId: string) => Knex
  createDatabase: () => string // returns database URL
  destroyDatabase: (url: string) => void // in case tenant creation fails after the database is created
  closeConnections: () => void // close all active connections
}

In the interest of keeping changes small, the PR for this issue should stub out the major methods like getOrCreateConnection, createDatabase or destroyDatabase. Other issues will capture the scope of these implementations.

  • Create DatabaseConnectionsService & add it to the IoC container
  • Describe interface for other services DatabaseConnectionsService depends on
  • Implement closeConnections & call it during app shutdown
  • Define connections data structure in interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: backend Changes in the backend package.
Projects
Status: Backlog
Development

No branches or pull requests

1 participant