diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..44ac7bc --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,33 @@ +name: Publish + +on: + push: + tags: [ 'v*.*.*' ] + branches: master + +env: + OTP_VERSION_SPEC: "21.1" + ELIXIR_VERSION_SPEC: "1.9.4" + +jobs: + test: + uses: ./.github/workflows/test.yml + publish: + needs: test + runs-on: ubuntu-20.04 + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - uses: erlef/setup-beam@v1 + with: + otp-version: ${{ env.OTP_VERSION_SPEC }} + elixir-version: ${{ env.ELIXIR_VERSION_SPEC }} + + # https://hex.pm/docs/publish + - name: Publish + env: + HEX_API_KEY: ${{ secrets.HEX_API_KEY }} + run: | + mix deps.get + mix hex.publish --yes \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..eb9b15c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,43 @@ +name: Test + +on: [push, workflow_call] + +env: + OTP_VERSION_SPEC: "21.1" + ELIXIR_VERSION_SPEC: "1.9.4" + MIX_ENV: test + PGUSER: postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_HOST: localhost + POSTGRES_PORT: 5432 + +jobs: + test: + runs-on: ubuntu-20.04 + services: + postgres: + env: + POSTGRES_HOST_AUTH_METHOD: trust + image: postgres:9.5 + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready --health-interval 10s + --health-timeout 5s --health-retries 5 + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - uses: erlef/setup-beam@v1 + with: + otp-version: ${{ env.OTP_VERSION_SPEC }} + elixir-version: ${{ env.ELIXIR_VERSION_SPEC }} + + - name: Run Tests + run: | + mix deps.get + cp config/test.exs.GH_actions config/test.exs + mix ecto.create + mix test diff --git a/config/test.exs.travis b/config/test.exs.GH_actions similarity index 92% rename from config/test.exs.travis rename to config/test.exs.GH_actions index c5464c6..27f9ce5 100644 --- a/config/test.exs.travis +++ b/config/test.exs.GH_actions @@ -6,6 +6,7 @@ config :ecto_soft_delete, Ecto.SoftDelete.Test.Repo, database: "soft_delete_test", hostname: "localhost", port: 5432, + username: "postgres", adapter: Ecto.Adapters.Postgres, pool: Ecto.Adapters.SQL.Sandbox, types: EctoSoftDelete.PostgresTypes diff --git a/lib/ecto/soft_delete_repo.ex b/lib/ecto/soft_delete_repo.ex index 0643fe1..7295614 100644 --- a/lib/ecto/soft_delete_repo.ex +++ b/lib/ecto/soft_delete_repo.ex @@ -93,7 +93,15 @@ defmodule Ecto.SoftDelete.Repo do # if it does, we want to be sure that we don't exclude soft deleted records defp has_include_deleted_at_clause?(%Ecto.Query{wheres: wheres}) do Enum.any?(wheres, fn %{expr: expr} -> - expr == {:not, [], [{:is_nil, [], [{{:., [], [{:&, [], [0]}, :deleted_at]}, [], []}]}]} + expr + |> Inspect.Algebra.to_doc(%Inspect.Opts{ + inspect_fun: fn expr, _ -> + inspect(expr, limit: :infinity) + end + }) + |> String.contains?( + "{:not, [], [{:is_nil, [], [{{:., [], [{:&, [], [0]}, :deleted_at]}, [], []}]}]}" + ) end) end diff --git a/test/soft_delete_repo_test.exs b/test/soft_delete_repo_test.exs index 6d4d9e3..98c6da6 100644 --- a/test/soft_delete_repo_test.exs +++ b/test/soft_delete_repo_test.exs @@ -136,5 +136,27 @@ defmodule Ecto.SoftDelete.Repo.Test do assert length(results) == 1 end + + test "returns same result for different types of where clauses" do + _user = Repo.insert!(%User{email: "test0@example.com"}) + + _soft_deleted_user = + Repo.insert!(%User{email: "deleted@example.com", deleted_at: DateTime.utc_now()}) + + query_1 = + from(u in User, + select: u, + where: u.email == "test0@example.com" and not is_nil(u.deleted_at) + ) + + query_2 = + from(u in User, + select: u, + where: u.email == "test0@example.com", + where: not is_nil(u.deleted_at) + ) + + assert Repo.all(query_2) == Repo.all(query_1) + end end end