Files
mesh-controller/testdata/beside/mesh-catalog/modules/supabase/files/pooler.exs
T
jschoubben 5ccc87f4d0 Capture mesh-catalog at feat/r4g (2246ccc4) with the templates its manifests name and its predefined.json, and lay the copy out as a repository's root
The catalogue's manifests moved their content into template files and fall back to predefined keys, so a copy of
module.json alone no longer passes the catalogue's own check; the bus's Dockerfile is gone from the catalogue.
2026-10-23 16:24:14 +02:00

44 lines
1.6 KiB
Elixir

{: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