Skip to content

Commit

Permalink
END-013 - Expose schema in Endo.Table.t()
Browse files Browse the repository at this point in the history
  • Loading branch information
vereis committed Jan 17, 2024
1 parent 0d3ff93 commit 600a532
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/endo/adapters/postgres.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ defmodule Endo.Adapters.Postgres do

%Table{
table
| size: repo.one(size),
| schema: opts[:prefix],
size: repo.one(size),
pg_class: repo.one(metadata),
indexes: repo.all(indexes)
}
Expand All @@ -54,6 +55,7 @@ defmodule Endo.Adapters.Postgres do
def to_endo(%Table{} = table, config) do
%Endo.Table{
adapter: __MODULE__,
schema: table.schema,
name: table.table_name,
indexes: Enum.map(table.indexes, &to_endo(&1, config)),
columns: table.columns |> Enum.map(&to_endo(&1, config)) |> Enum.sort_by(& &1.position),
Expand Down
1 change: 1 addition & 0 deletions lib/endo/adapters/postgres/table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ defmodule Endo.Adapters.Postgres.Table do
field(:indexes, :map, virtual: true)
field(:pg_class, :map, virtual: true)
field(:size, :map, virtual: true)
field(:schema, :string, virtual: true)
end

@impl Endo.Queryable
Expand Down
1 change: 1 addition & 0 deletions lib/endo/table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Endo.Table do
defstruct [
:adapter,
:name,
:schema,
columns: [],
associations: [],
indexes: [],
Expand Down
5 changes: 3 additions & 2 deletions test/endo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ defmodule EndoTest do

describe "get_table/3 (Postgres)" do
test "given valid table name and repo, returns Endo Table" do
assert %Endo.Table{name: "orgs"} = Endo.get_table(Test.Postgres.Repo, "orgs")
assert %Endo.Table{name: "orgs", schema: "public"} =
Endo.get_table(Test.Postgres.Repo, "orgs")
end

test "given invalid table name, but valid repo, returns nil" do
Expand All @@ -79,7 +80,7 @@ defmodule EndoTest do
end

test "returns table belonging to non-default prefix if specified correctly" do
assert %Endo.Table{name: "events"} =
assert %Endo.Table{name: "events", schema: "debug"} =
Endo.get_table(Test.Postgres.Repo, "events", prefix: "debug")
end
end
Expand Down

0 comments on commit 600a532

Please sign in to comment.