Skip to content

Commit

Permalink
Merge pull request #81 from pepsico-ecommerce/bc/dependency-fixes
Browse files Browse the repository at this point in the history
chore: use Ecto.Type.type to determine db type
  • Loading branch information
BruceBC authored Aug 16, 2024
2 parents b6eb28c + b494802 commit 77a50be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/snowflex/ecto/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ defmodule Snowflex.EctoAdapter.Connection do

defp insert_all_value(nil), do: "DEFAULT"
defp insert_all_value({%Ecto.Query{} = query, _params_counter}), do: [?(, all(query), ?)]
defp insert_all_value(_), do: '?'
defp insert_all_value(_), do: "?"

@impl true
def update(prefix, table, fields, filters, _returning) do
Expand Down Expand Up @@ -598,7 +598,7 @@ defmodule Snowflex.EctoAdapter.Connection do
end

defp expr({:^, [], [_ix]}, _sources, _query) do
'?'
"?"
end

defp expr({{:., _, [{:parent_as, _, [as]}, field]}, _, []}, _sources, query)
Expand Down
10 changes: 2 additions & 8 deletions lib/snowflex/migration_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ defmodule Snowflex.MigrationGenerator do

create table(@source, primary_key: false) do
for {name, type} <- @fields do
field_type = ecto_type_to_db_type(type)
field_type = Ecto.Type.type(type)
field_source = name
add(field_source, type, primary_key: name in primary_keys)
end
end
end

defp ecto_type_to_db_type({:parameterized, Ecto.Enum, _}), do: :string
defp ecto_type_to_db_type(any), do: any
end

Ecto.Migrator.up(
Expand All @@ -55,16 +52,13 @@ defmodule Snowflex.MigrationGenerator do
type =
:type
|> @module.__schema__(field)
|> ecto_type_to_db_type()
|> Ecto.Type.type()

field_source = @module.__schema__(:field_source, field)
add(field_source, type, primary_key: field in primary_keys)
end
end
end

defp ecto_type_to_db_type({:parameterized, Ecto.Enum, _}), do: :string
defp ecto_type_to_db_type(any), do: any
end

Ecto.Migrator.up(
Expand Down

0 comments on commit 77a50be

Please sign in to comment.