Skip to content

Commit

Permalink
END-011 - Handle postgres tables without pg_class
Browse files Browse the repository at this point in the history
  • Loading branch information
vereis committed Nov 1, 2023
1 parent 13c74a8 commit 2b7b493
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/endo/adapters/postgres/metadata.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ defmodule Endo.Adapters.Postgres.Metadata do
alias Endo.Adapters.Postgres.Table

@spec derive!(Table.t()) :: Endo.Metadata.Postgres.t()
def derive!(%Table{pg_class: nil} = table) do
%Endo.Metadata.NotAvailable{
table: table.table_name,
adapter: Endo.Adapters.Postgres,
message: "Could not find `pg_class` for table."
}
end

def derive!(%Table{pg_class: pg_class, size: size}) do
%Endo.Metadata.Postgres{
replica_identity: replica_identity(pg_class),
Expand All @@ -29,7 +37,7 @@ defmodule Endo.Adapters.Postgres.Metadata do
defp replica_identity(%PgClass{relreplident: "n"}), do: "NOTHING"
defp replica_identity(%PgClass{relreplident: "f"}), do: "FULL"
defp replica_identity(%PgClass{relreplident: "i"}), do: "INDEX"
defp replica_identity(%PgClass{relreplident: _}), do: nil
defp replica_identity(_otherwise), do: nil

defp kind(%PgClass{relkind: "r"}), do: "ordinary table"
defp kind(%PgClass{relkind: "i"}), do: "index"
Expand All @@ -41,5 +49,5 @@ defmodule Endo.Adapters.Postgres.Metadata do
defp kind(%PgClass{relkind: "f"}), do: "foreign table"
defp kind(%PgClass{relkind: "p"}), do: "partitioned table"
defp kind(%PgClass{relkind: "I"}), do: "partitioned index"
defp kind(%PgClass{relkind: _}), do: nil
defp kind(_otherwise), do: nil
end
6 changes: 6 additions & 0 deletions lib/endo/metadata.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ defmodule Endo.Metadata do
defstruct []
end

defmodule NotAvailable do
@moduledoc false
@type t :: %__MODULE__{}
defstruct [:table, :adapter, :message]
end

defmodule Postgres do
@moduledoc false
@type t :: %__MODULE__{}
Expand Down

0 comments on commit 2b7b493

Please sign in to comment.