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
Multitenancy support #8
Conversation
# Conflicts: # config/config.exs # config/runtime.exs # lib/pg_edge/application.ex # lib/pg_edge/client_handler.ex
Hey, @supabase/dashbit team, another day, another PR for the review! |
hostname: System.get_env("DB_HOST", "localhost"), | ||
username: System.get_env("DB_USER", "postgres"), | ||
password: System.get_env("DB_PASSWORD", "postgres"), | ||
database: System.get_env("DB_NAME", "postgres"), | ||
port: System.get_env("DB_PORT", "6432"), | ||
pool_size: System.get_env("DB_POOL_SIZE", "5") |> String.to_integer(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a friendly reminder that while it is of course totally fine to configure each parameter separately, on very DB-centric projects where I would often jump between system/docker/hosted pg and elixir/psql, I found it very convenient to configure the connection through the URL:
url: System.get_env("DATABASE_URL", "ecto://postgres:postgres@localhost:6432/postgres?pool_size=5")
(yup, we can configure pool_size like this too!)
Again, no need for the change, just something to keep in mind in case you weren't aware!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes it's handy to update only a single value in production, for example, only pool size. In the case of URL, it needs to copy and find all credentials.
"joken": {:hex, :joken, "2.5.0", "09be497d804b8115eb6f07615cef2e60c2a1008fb89dc0aef0d4c4b4609b99aa", [:mix], [{:jose, "~> 1.11.2", [hex: :jose, repo: "hexpm", optional: false]}], "hexpm", "22b25c89617c5ed8ca7b31026340a25ea0f9ca7160f9706b79be9ed81fdf74e7"}, | ||
"jose": {:hex, :jose, "1.11.5", "3bc2d75ffa5e2c941ca93e5696b54978323191988eb8d225c2e663ddfefd515e", [:mix, :rebar3], [], "hexpm", "dcd3b215bafe02ea7c5b23dafd3eb8062a5cd8f2d904fd9caa323d37034ab384"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless you get significant benefits out of using Joken, I'd go for the JOSE library directly to keep dependencies to minimum as well as if you do need to debug something you'll have less layers to peel off. But if for your use case Joken is not just delegating to JOSE but actually encapsulates a lot of logic that you'd rather not implement yourself, by all means go for it!
Co-authored-by: Wojtek Mach <wojtekmach@users.noreply.github.com>
Co-authored-by: Wojtek Mach <wojtekmach@users.noreply.github.com>
Co-authored-by: Wojtek Mach <wojtekmach@users.noreply.github.com>
Added cloak_ecto for password encryption |
What kind of change does this PR introduce?
This PR adds support for multitenancy. Different credentials can be stored in the database and managed by HTTP API.
The tenant record includes the
external_id
column, which will store the Supabase project id.During connections, pg_edge gets the
external_id
value from the query parameters "options".Additional context
How to start it
At first, we need to reinitialize a database image:
Then we need to apply migrations:
Launch the pg_edge application as usual:
When you start the application, you can try following commands to add tenants to the database
add/update tenant:
and now it's possible to connect through the proxy
delete tenant: