Skip to content

Commit

Permalink
Fix compilation error when specific adapter is not included (#64)
Browse files Browse the repository at this point in the history
* Remove references to postgrex and mariaex error structs

* Update docker-compose with test databases, remove outdated dockerfile
  • Loading branch information
vanetix authored and mgiacomini committed Mar 7, 2019
1 parent 3f768a1 commit c8b3ee2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 50 deletions.
13 changes: 0 additions & 13 deletions Dockerfile

This file was deleted.

33 changes: 16 additions & 17 deletions docker-compose.yml
@@ -1,18 +1,17 @@
app:
build: .
command: bash -c 'while [ true ]; do sleep 10; done'
environment:
- PG_HOST=postgres
- PG_USERNAME=postgres
- PG_PASSWORD=postgres
volumes:
- .:/app
links:
- postgres
version: '3'

postgres:
image: postgres:9.5
environment:
- POSTGRES_PASSWORD=postgres
ports:
- 5432
services:
mysql:
image: mariadb:latest
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_ROOT_PASSWORD=
ports:
- 3306:3306

postgres:
image: postgres:latest
environment:
- POSTGRES_PASSWORD=postgres
ports:
- 5432:5432
33 changes: 13 additions & 20 deletions lib/triplex.ex
Expand Up @@ -22,8 +22,6 @@ defmodule Triplex do

alias Ecto.Adapters.SQL
alias Ecto.Migrator
alias Postgrex.Error, as: PGError
alias Mariaex.Error, as: MXError

@doc """
Returns a `%Triplex.Config{}` struct with all the args loaded from the app
Expand Down Expand Up @@ -172,9 +170,13 @@ defmodule Triplex do
end
end

defp error_message(%PGError{} = e), do: PGError.message(e)
defp error_message(%MXError{} = e), do: MXError.message(e)
defp error_message(msg), do: msg
defp error_message(msg) do
if Exception.exception?(msg) do
Exception.message(msg)
else
msg
end
end

defp add_to_tenants_table(tenant, repo) do
case repo.__adapter__ do
Expand Down Expand Up @@ -229,11 +231,8 @@ defmodule Triplex do
{:ok, _} <- remove_from_tenants_table(tenant, repo) do
{:ok, tenant}
else
{:error, %PGError{} = e} ->
{:error, PGError.message(e)}

{:error, %MXError{} = e} ->
{:error, MXError.message(e)}
{:error, exception} ->
{:error, error_message(exception)}
end
end
end
Expand Down Expand Up @@ -264,11 +263,8 @@ defmodule Triplex do
{:ok, _} ->
{:ok, new_tenant}

{:error, %PGError{} = e} ->
{:error, PGError.message(e)}

{:error, %MXError{} = e} ->
{:error, MXError.message(e)}
{:error, message} ->
{:error, error_message(message)}
end
end
end
Expand Down Expand Up @@ -346,11 +342,8 @@ defmodule Triplex do

{:ok, migrated_versions}
rescue
e in PGError ->
{:error, PGError.message(e)}

e in MXError ->
{:error, MXError.message(e)}
exception ->
{:error, error_message(exception)}
after
Code.compiler_options(ignore_module_conflict: false)
end
Expand Down

0 comments on commit c8b3ee2

Please sign in to comment.