Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Allow tenant connection strings to be aliased #67

Open
jimsimon opened this issue Oct 19, 2020 · 3 comments
Open

Allow tenant connection strings to be aliased #67

jimsimon opened this issue Oct 19, 2020 · 3 comments

Comments

@jimsimon
Copy link

The current approach requires storing usernames and passwords for the database connection strings in plain text which isn't great for security. A better approach might be to use an alias and environment variables for retrieving the connection strings.

Tenant Table:

NameAlias
Small Cool Tenantdb1
Small Awesome Tenantdb1
Large Tenantdb2

.env

DB1_URL=postgres://user:password@db1:5432/myapp
DB2_URL=postgres://user:password@db2:5432/myapp

This could be done in a backwards compatible way by making the current URL column nullable and adding a new alias column. Then use URL if it's present and fall back to alias. The CLI would just need to ensure that one of the two are provided, and a check constraint could be used on the table to ensure it never ends up in a situation where both columns are null.

@Errorname
Copy link
Owner

That's a good idea! Feel free to make a PR to add this feature in pmt

@m-leon
Copy link

m-leon commented Nov 4, 2020

Adding on to this, I think it would be beneficial to allow us to resolve the URL with a function. This would allow us to create our own adapters to the URLs.

Environment variables could be resolved with this:
(alias) => process.env[alias]

@Errorname
Copy link
Owner

The issue with resolving URL with a function is that other commands of pmt (e.g: migrate, studio,...) would not work.

However, if you only want the pmt client, you could use the .directGet method instead of .get. (See documentation)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants