Skip to content

Commit

Permalink
fix dialyser and rebase issues
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetised committed Sep 18, 2023
1 parent 2646c2e commit 0bc620f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule Electric.Postgres.Dialect.Builder do
alias Electric.Postgres.Schema.Proto
alias PgQuery, as: Pg
alias Electric.Postgres.Dialect

@type stmt() :: [binary() | sql() | nil]
@type sql() :: Dialect.sql()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Electric.Postgres.Extension.Migrations.Migration_20230918115714_DDLCom
"""
ALTER TABLE #{ddl_table}
ADD CONSTRAINT ddl_table_unique_migrations
UNIQUE (txid, txts ,version, query);
UNIQUE (txid, txts, query);
""",
"""
CREATE OR REPLACE FUNCTION #{schema}.create_active_migration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule Electric.Postgres.Proxy.Injector do
@type msgs() :: [M.t()]
@type response() :: {:ok, state(), backend_msgs :: msgs(), frontend_msgs :: msgs()}
@type quote_mark() :: String.t()
@type t :: module()

@callback capture_ddl_query(query :: binary()) :: binary()
@callback capture_version_query(version :: binary()) :: binary()
Expand Down
13 changes: 11 additions & 2 deletions components/electric/lib/electric/postgres/proxy/prisma.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ defmodule Electric.Postgres.Proxy.Prisma do

alias Electric.Postgres.Proxy.Injector

require Logger

def parse_query("SELECT version()" <> _rest) do
{:ok, Electric.Postgres.Proxy.Prisma.Query.VersionV5_2}
end

def parse_query(sql) do
with [stmt] <- Electric.Postgres.parse!(sql) do
analyse_stmt(stmt)
analyse_stmt(stmt, sql)
end
end

defp analyse_stmt(%PgQuery.SelectStmt{} = stmt) do
defp analyse_stmt(%PgQuery.SelectStmt{} = stmt, sql) do
case target_list_names(stmt) do
["", "", "numeric_version"] ->
{:ok, Electric.Postgres.Proxy.Prisma.Query.NamespaceVersionV5_2}
Expand Down Expand Up @@ -124,6 +126,13 @@ defmodule Electric.Postgres.Proxy.Prisma do
"cache_size"
] ->
{:ok, Electric.Postgres.Proxy.Prisma.Query.SequenceV5_2}

columns ->
Logger.error(
"Received unknown prisma introspection query: #{inspect(sql)} with columns #{inspect(columns)}"
)

:error
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
defmodule Electric.Postgres.Proxy.Prisma.Query do
alias Electric.Postgres.Proxy.Prisma
alias Electric.Postgres.Extension.SchemaLoader
alias Electric.Postgres.Schema
alias PgProtocol.Message, as: M

@type data_row() :: [binary()]
@callback parameter_description(Prisma.t()) :: [integer()]
@callback row_description(Prisma.t()) :: [M.RowDescription.Field.t()]
@callback data_rows([term()], SchemaLoader.t(), Prisma.t()) :: [data_row()]
@callback data_rows([term()], Schema.t(), Prisma.t()) :: [data_row()]

# PG_VERSION_NUM => sprintf("%d%04d", $majorver, $minorver)
defguard is_major_version(config, v)
Expand Down Expand Up @@ -99,7 +99,7 @@ defmodule Electric.Postgres.Proxy.Prisma.Query.VersionV5_2 do
]
end

def data_rows(_binds, _loader, config) do
def data_rows(_binds, _schema, config) do
[[server_version_string(config)]]
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ defmodule Electric.Satellite.WsValidationsTest do
migrate(
ctx.db,
vsn,
"public.foo",
"CREATE TABLE public.foo (id TEXT PRIMARY KEY, b BOOLEAN)"
"CREATE TABLE public.foo (id TEXT PRIMARY KEY, b BOOLEAN)",
electrify: "public.foo"
)

valid_records = [
Expand Down Expand Up @@ -369,8 +369,8 @@ defmodule Electric.Satellite.WsValidationsTest do
migrate(
ctx.db,
vsn,
"public.foo",
"CREATE TABLE public.foo (id TEXT PRIMARY KEY, t1 timestamp, t2 timestamptz)"
"CREATE TABLE public.foo (id TEXT PRIMARY KEY, t1 timestamp, t2 timestamptz)",
electrify: "public.foo"
)

valid_records = [
Expand Down

0 comments on commit 0bc620f

Please sign in to comment.