From e3b552464af309ea78fc7f771ec9dabb19299a55 Mon Sep 17 00:00:00 2001 From: Ayan Haider Date: Mon, 20 Nov 2023 19:10:21 +0500 Subject: [PATCH 01/10] Ensure that deleted_at check is included only once (#158) * Ensure that deleted_at check is included only once * Minor fix * Use Inspect.Algebra.to_doc instead of simple inspect * Minor edit --- lib/ecto/soft_delete_repo.ex | 10 +++++++++- test/soft_delete_repo_test.exs | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) 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 From 6ab5a702a39c4d4d258c4e3693af98ca87162a7b Mon Sep 17 00:00:00 2001 From: Samuel Aaron Katz Keer Date: Thu, 4 Apr 2024 11:00:23 -0500 Subject: [PATCH 02/10] testing migration to GH actions - test workflow --- .github/workflows/publish.yml | 26 ++++++++++ .github/workflows/test.yml | 50 +++++++++++++++++++ .../{test.exs.travis => test.exs.GH_actions} | 1 + 3 files changed, 77 insertions(+) create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/test.yml rename config/{test.exs.travis => test.exs.GH_actions} (92%) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..9fbc9a5 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,26 @@ +name: Publish + +on: + push: + tags: [ 'v*.*.*' ] + branches: master + +env: + OTP_VERSION_SPEC: "21.1" + ELIXIR_VERSION_SPEC: "1.9.4" + +jobs: + 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 }} + + - name: Publish + run: 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..35d0a53 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,50 @@ +name: Test + +on: push + +env: + OTP_VERSION_SPEC: "21.1" + ELIXIR_VERSION_SPEC: "1.9.4" + +jobs: + test: + runs-on: ubuntu-20.04 + services: + postgres: + env: + MIX_ENV: test + PGUSER: postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_HOST: localhost + POSTGRES_PORT: 5432 + 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 + env: + MIX_ENV: test + PGUSER: postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_HOST: localhost + POSTGRES_PORT: 5432 + 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 From efa58f8809617e2f1ff49f50ab4e9c275cb27b82 Mon Sep 17 00:00:00 2001 From: Samuel Aaron Katz Keer Date: Thu, 4 Apr 2024 11:02:57 -0500 Subject: [PATCH 03/10] adios, travis --- .travis.yml | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 37320f3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: elixir -dist: zenial -elixir: - - 1.9.4 -otp_release: - - 21.1 -addons: - postgresql: '9.5' -services: - - postgresql -before_script: - - cp config/test.exs.travis config/test.exs - - MIX_ENV=test mix ecto.create -script: - - MIX_ENV=test mix test -deploy: - skip_cleanup: true - provider: script - script: mix hex.publish --yes - on: - tags: true From fdbf7d887c37c0116713a1149aba56e158f7d88e Mon Sep 17 00:00:00 2001 From: Samuel Aaron Katz Keer Date: Thu, 4 Apr 2024 11:10:18 -0500 Subject: [PATCH 04/10] testing publish without providing api key --- .github/workflows/publish.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9fbc9a5..0a8ce5a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,8 +2,8 @@ name: Publish on: push: - tags: [ 'v*.*.*' ] - branches: master + # tags: [ 'v*.*.*' ] + branches: 245-github-actions-migrate env: OTP_VERSION_SPEC: "21.1" @@ -23,4 +23,4 @@ jobs: elixir-version: ${{ env.ELIXIR_VERSION_SPEC }} - name: Publish - run: mix hex.publish --yes \ No newline at end of file + run: mix hex.publish \ No newline at end of file From edeabb99a60f82176f720edd5356827a9d043dc5 Mon Sep 17 00:00:00 2001 From: Samuel Aaron Katz Keer Date: Thu, 4 Apr 2024 11:17:49 -0500 Subject: [PATCH 05/10] still testing publish --- .github/workflows/publish.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0a8ce5a..22aa498 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,6 +10,8 @@ env: ELIXIR_VERSION_SPEC: "1.9.4" jobs: + test: + uses: ./.github/workflows/test.yml publish: needs: test runs-on: ubuntu-20.04 @@ -23,4 +25,4 @@ jobs: elixir-version: ${{ env.ELIXIR_VERSION_SPEC }} - name: Publish - run: mix hex.publish \ No newline at end of file + run: mix hex.publish --yes \ No newline at end of file From d07d026bbd7da4da4084140f0ce3fc95c2e74bc1 Mon Sep 17 00:00:00 2001 From: Samuel Aaron Katz Keer Date: Thu, 4 Apr 2024 11:18:48 -0500 Subject: [PATCH 06/10] add action trigger to test.yml --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 35d0a53..d0aa908 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,6 @@ name: Test -on: push +on: [push, workflow_call] env: OTP_VERSION_SPEC: "21.1" From 145d00a35d65e1907cc9570aa2301ef9d894ab99 Mon Sep 17 00:00:00 2001 From: Samuel Aaron Katz Keer Date: Thu, 4 Apr 2024 11:21:30 -0500 Subject: [PATCH 07/10] add dependency fetch to publish.yml --- .github/workflows/publish.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 22aa498..148e174 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,4 +25,6 @@ jobs: elixir-version: ${{ env.ELIXIR_VERSION_SPEC }} - name: Publish - run: mix hex.publish --yes \ No newline at end of file + run: | + mix deps.get + mix hex.publish --yes \ No newline at end of file From 255b8b9f12d2aa4d7fb13a71229e2e9ec4e44f1f Mon Sep 17 00:00:00 2001 From: Samuel Aaron Katz Keer Date: Thu, 4 Apr 2024 11:27:18 -0500 Subject: [PATCH 08/10] checking to see if different auth error for hex publish --- .github/workflows/publish.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 148e174..35f30f7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,7 +24,10 @@ jobs: 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 From f66612697c41cc0b5e9686e613e47edc53cc6b9d Mon Sep 17 00:00:00 2001 From: Samuel Aaron Katz Keer Date: Thu, 4 Apr 2024 11:31:47 -0500 Subject: [PATCH 09/10] changing publish conditions to a tagged merge to master --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 35f30f7..44ac7bc 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,8 +2,8 @@ name: Publish on: push: - # tags: [ 'v*.*.*' ] - branches: 245-github-actions-migrate + tags: [ 'v*.*.*' ] + branches: master env: OTP_VERSION_SPEC: "21.1" From 68893bbaf196d8fa6f0c2300f1366cd69d3a7be4 Mon Sep 17 00:00:00 2001 From: Samuel Aaron Katz Keer Date: Thu, 4 Apr 2024 11:44:25 -0500 Subject: [PATCH 10/10] drying things off a bit --- .github/workflows/test.yml | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d0aa908..eb9b15c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,6 +5,12 @@ 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: @@ -12,12 +18,6 @@ jobs: services: postgres: env: - MIX_ENV: test - PGUSER: postgres - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_HOST: localhost - POSTGRES_PORT: 5432 POSTGRES_HOST_AUTH_METHOD: trust image: postgres:9.5 ports: @@ -36,13 +36,6 @@ jobs: elixir-version: ${{ env.ELIXIR_VERSION_SPEC }} - name: Run Tests - env: - MIX_ENV: test - PGUSER: postgres - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_HOST: localhost - POSTGRES_PORT: 5432 run: | mix deps.get cp config/test.exs.GH_actions config/test.exs