Skip to content

Commit

Permalink
merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Samkeer1 committed May 21, 2024
2 parents b67ce52 + e5f4fba commit 8dd5429
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 1 deletion.
33 changes: 33 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions config/test.exs.travis → config/test.exs.GH_actions
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion lib/ecto/soft_delete_repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions test/soft_delete_repo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]"})

_soft_deleted_user =
Repo.insert!(%User{email: "[email protected]", deleted_at: DateTime.utc_now()})

query_1 =
from(u in User,
select: u,
where: u.email == "[email protected]" and not is_nil(u.deleted_at)
)

query_2 =
from(u in User,
select: u,
where: u.email == "[email protected]",
where: not is_nil(u.deleted_at)
)

assert Repo.all(query_2) == Repo.all(query_1)
end
end
end

0 comments on commit 8dd5429

Please sign in to comment.