Feature 57 (config and provisioning): modules declare config and provisions, their files rendered from templates; synced with main (issues of feature 57, 874)
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
{:ok, _} = Application.ensure_all_started(:supavisor)
|
||||
|
||||
# Written by the mesh (modules/supabase). Per-machine values come from settings.json (the module's
|
||||
# one merge:json file); secrets come from the environment the image reads.
|
||||
settings = "/etc/pooler/settings.json" |> File.read!() |> Jason.decode!() |> Map.get("pooler", %{})
|
||||
|
||||
{:ok, version} =
|
||||
case Supavisor.Repo.query!("select version()") do
|
||||
%{rows: [[ver]]} -> Supavisor.Helpers.parse_pg_version(ver)
|
||||
_ -> nil
|
||||
end
|
||||
|
||||
params = %{
|
||||
"external_id" => to_string(settings["tenant"] || "default"),
|
||||
"db_host" => "supabase-db",
|
||||
"db_port" => System.get_env("POSTGRES_PORT"),
|
||||
"db_database" => System.get_env("POSTGRES_DB"),
|
||||
"require_user" => false,
|
||||
"auth_query" => "SELECT * FROM pgbouncer.get_auth($1)",
|
||||
"default_max_clients" => settings["max-client-connections"] || 100,
|
||||
"default_pool_size" => settings["pool-size"] || 20,
|
||||
"default_parameter_status" => %{"server_version" => version},
|
||||
"users" => [%{
|
||||
"db_user" => "pgbouncer",
|
||||
"db_password" => System.get_env("POSTGRES_PASSWORD"),
|
||||
"mode_type" => System.get_env("POOLER_POOL_MODE"),
|
||||
"pool_size" => settings["pool-size"] || 20,
|
||||
"is_manager" => true
|
||||
}]
|
||||
}
|
||||
|
||||
case Supavisor.Tenants.get_tenant_by_external_id(params["external_id"]) do
|
||||
nil ->
|
||||
{:ok, _} = Supavisor.Tenants.create_tenant(params)
|
||||
|
||||
# A tenant made elsewhere (HAL named the database host "db") is pointed at this module's
|
||||
# database container; nothing else it holds is changed.
|
||||
%{db_host: host} = tenant when host != "supabase-db" ->
|
||||
{:ok, _} = Supavisor.Tenants.update_tenant(tenant, %{"db_host" => "supabase-db"})
|
||||
|
||||
_ ->
|
||||
:ok
|
||||
end
|
||||
Reference in New Issue
Block a user