Skip to content

Commit

Permalink
fix: use correct column name from the control plane (#1970)
Browse files Browse the repository at this point in the history
  • Loading branch information
icehaunter authored Nov 13, 2024
1 parent ffd7e13 commit 501e119
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/sync-service/lib/electric/control_plane.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ defmodule Electric.ControlPlane do
defstruct [
:base_url,
:auth,
req_opts: [],
paths: %{
"tenant_shape" => %{
"url" => "/v1/shape",
"params" => %{
"offset" => "-1",
"table" => "databases",
"where" => "electric_url ILIKE '%%{instance_id}'",
"where" => "electric_url LIKE '%%{instance_id}%'",
"select" => "id,connection_url"
}
}
Expand All @@ -23,6 +24,7 @@ defmodule Electric.ControlPlane do
@type t() :: %__MODULE__{
base_url: String.t(),
auth: nil | String.t() | {:basic, String.t()} | {:bearer, String.t()},
req_opts: keyword(),
paths: %{optional(String.t()) => map()}
}

Expand Down Expand Up @@ -115,6 +117,7 @@ defmodule Electric.ControlPlane do
auth: plane.auth,
headers: headers
)
|> Req.merge(plane.req_opts)
end

defp insert_instance_id(string, instance_id),
Expand Down
2 changes: 1 addition & 1 deletion packages/sync-service/lib/electric/tenant_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ defmodule Electric.TenantManager do
end
end)

Enum.reduce(to_add, state, fn %{"id" => tenant_id, "connection_uri" => connection_url},
Enum.reduce(to_add, state, fn %{"id" => tenant_id, "connection_url" => connection_url},
state ->
{:ok, result} = Electric.ConfigParser.parse_postgresql_uri(connection_url)
connection_opts = Electric.Utils.obfuscate_password(result)
Expand Down
43 changes: 43 additions & 0 deletions packages/sync-service/test/electric/control_plane_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
defmodule Electric.ControlPlaneTest do
alias Electric.ControlPlane
use ExUnit.Case, async: true

setup ctx do
%{
plane: %ControlPlane{
base_url: "http://localhost",
req_opts: [
plug: fn conn ->
conn
|> Plug.Conn.put_resp_content_type("application/json")
|> Plug.Conn.put_resp_header("electric-up-to-date", "true")
|> Plug.Conn.send_resp(200, Jason.encode!(ctx.plug_response))
end
]
}
}
end

describe "list_tenants/2" do
@tag plug_response: [
%{
headers: %{operation: "insert"},
key: "id1",
value: %{
id: "test_id",
connection_url: "postgresql://test:me@localhost:5432/postgres"
}
}
]
test "returns tenants from an Electric API", %{plane: plane} do
assert {:ok,
[
%{
"connection_url" => "postgresql://test:me@localhost:5432/postgres",
"id" => "test_id"
}
],
[]} = ControlPlane.list_tenants(plane, app_config: %{electric_instance_id: "test"})
end
end
end

0 comments on commit 501e119

Please sign in to comment.