Skip to content

Commit

Permalink
adds create execute_ddl function clause, #44
Browse files Browse the repository at this point in the history
  • Loading branch information
Danwhy committed Feb 18, 2019
1 parent 33f3102 commit 403bb1a
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions lib/alog/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,49 @@ defmodule Alog.Connection do
@behaviour Ecto.Adapters.SQL.Connection

@impl true
defdelegate ddl_logs(result), to: Ecto.Adapter.Postgres
defdelegate child_spec(opts), to: Ecto.Adapters.Postgres.Connection

@impl true
defdelegate ddl_logs(result), to: Ecto.Adapter.Postgres.Connection

@impl true
defdelegate prepare_execute(connection, name, statement, params, options),
to: Ecto.Adapter.Postgres
to: Ecto.Adapter.Postgres.Connection

@impl true
defdelegate query(connection, statement, params, options), to: Ecto.Adapter.Postgres
defdelegate query(connection, statement, params, options), to: Ecto.Adapter.Postgres.Connection

@impl true
defdelegate stream(connection, statement, params, options), to: Ecto.Adapter.Postgres
defdelegate stream(connection, statement, params, options), to: Ecto.Adapter.Postgres.Connection

@impl true
def execute_ddl({c, %Ecto.Migration.Table{} = table, columns} = command)
when c in [:create, :create_if_not_exists] do
case Enum.any?(
columns,
fn
{:add, field, type, [primary_key: true]} -> true
_ -> false
end
) do
true ->
raise ArgumentError, "you cannot add a primary key"

false ->
Ecto.Adapter.Postgres.Connection.execute_ddl(
{c, table, subcommand ++ [{:add, :cid, "varchar", [primary_key: true]}]}
)
end
end

def execute_ddl({:alter, %Ecto.Migration.Table{}, changes} = command) do
end

def execute_ddl({:create, %Ecto.Migration.Index{}} = command) do
end

def execute_ddl({:create_if_not_exists, %Ecto.Migration.Index{}} = command) do
end

defdelegate execute_ddl(command), to: Ecto.Adapter.Postgres.Connection
end

0 comments on commit 403bb1a

Please sign in to comment.