From c8b3ee21dd12cb6432263db319f36b125752147e Mon Sep 17 00:00:00 2001 From: Matt McFarland <783024+vanetix@users.noreply.github.com> Date: Thu, 7 Mar 2019 07:09:18 -0600 Subject: [PATCH] Fix compilation error when specific adapter is not included (#64) * Remove references to postgrex and mariaex error structs * Update docker-compose with test databases, remove outdated dockerfile --- Dockerfile | 13 ------------- docker-compose.yml | 33 ++++++++++++++++----------------- lib/triplex.ex | 33 +++++++++++++-------------------- 3 files changed, 29 insertions(+), 50 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index d494c12..0000000 --- a/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -# https://hub.docker.com/_/elixir/ -FROM elixir:1.4.2 - -ENV DEBIAN_FRONTEND=noninteractive - -RUN apt-get update && apt-get install -y postgresql-client - -ADD . /app -RUN mix local.hex --force -RUN mix local.rebar --force -WORKDIR /app -RUN mix do deps.get, compile - diff --git a/docker-compose.yml b/docker-compose.yml index 774a949..0c6f562 100644 --- a/docker-compose.yml +++ b/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 diff --git a/lib/triplex.ex b/lib/triplex.ex index 5818e23..a010c09 100644 --- a/lib/triplex.ex +++ b/lib/triplex.ex @@ -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 @@ -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 @@ -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 @@ -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 @@ -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