Skip to content

Commit

Permalink
Move SQL function templates into priv/
Browse files Browse the repository at this point in the history
...so that they are available in the packaged Elixir release to be
loaded and evaluated at run time.
  • Loading branch information
alco committed Dec 22, 2023
1 parent 42eed14 commit a4eab72
Show file tree
Hide file tree
Showing 29 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion components/electric/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ COPY mix.* /app/
RUN mix deps.get
RUN mix deps.compile

COPY config/*runtime.exs /app/config/
COPY lib /app/lib/
COPY src /app/src/
COPY config/*runtime.exs /app/config/
COPY priv /app/priv

ARG ELECTRIC_VERSION=local
ARG MAKE_RELEASE_TASK=release
Expand Down
14 changes: 7 additions & 7 deletions components/electric/lib/electric/postgres/extension/functions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ defmodule Electric.Postgres.Extension.Functions do

require EEx

sql_files =
"functions/**/*.sql.eex"
|> Path.expand(__DIR__)
|> Path.wildcard()
@template_dir "priv/sql_function_templates"

template_dir_path = Application.app_dir(:electric, @template_dir)
sql_template_paths = Path.wildcard(template_dir_path <> "/**/*.sql.eex")

function_paths =
for path <- sql_files do
relpath = Path.relative_to(path, Path.expand("./functions", __DIR__))
for path <- sql_template_paths do
relpath = Path.relative_to(path, template_dir_path)
name = path |> Path.basename(".sql.eex") |> String.to_atom()
{relpath, name}
end
Expand Down Expand Up @@ -64,7 +64,7 @@ defmodule Electric.Postgres.Extension.Functions do
end

defp eval_template(relpath) do
Path.join([Path.expand(__DIR__), "functions", relpath])
Path.join(Application.app_dir(:electric, @template_dir), relpath)
|> EEx.compile_file()
|> Code.eval_quoted([], __ENV__)
|> elem(0)
Expand Down

0 comments on commit a4eab72

Please sign in to comment.