Skip to content

Commit

Permalink
pg 17 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
pawurb committed Oct 9, 2024
1 parent 5642167 commit c834969
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 176 deletions.
130 changes: 54 additions & 76 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,159 +36,137 @@ jobs:
elixir: 1.11
otp: 24
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
with:
otp-version: ${{matrix.pair.otp}}
elixir-version: ${{matrix.pair.elixir}}
- name: Run PostgreSQL 11
run: |
docker run --env POSTGRES_USER=postgres \
--env POSTGRES_DB=ecto_psql_extras_test \
--env POSTGRES_PASSWORD=postgres \
-d -p 5432:5432 postgres:11.18-alpine \
postgres -c shared_preload_libraries=pg_stat_statements
sleep 5
- name: Run PostgreSQL 12
run: |
docker run --env POSTGRES_USER=postgres \
--env POSTGRES_DB=ecto_psql_extras_test \
--env POSTGRES_PASSWORD=postgres \
-d -p 5433:5432 postgres:12.13-alpine \
--env POSTGRES_DB=ecto-psql-extras-test \
--env POSTGRES_PASSWORD=secret \
-d -p 5432:5432 postgres:12.20-alpine \
postgres -c shared_preload_libraries=pg_stat_statements
sleep 5
- name: Run PostgreSQL 13
run: |
docker run --env POSTGRES_USER=postgres \
--env POSTGRES_DB=ecto_psql_extras_test \
--env POSTGRES_PASSWORD=postgres \
-d -p 5434:5432 postgres:13.9-alpine \
--env POSTGRES_DB=ecto-psql-extras-test \
--env POSTGRES_PASSWORD=secret \
-d -p 5433:5432 postgres:13.16-alpine \
postgres -c shared_preload_libraries=pg_stat_statements
sleep 5
- name: Run PostgreSQL 14
run: |
docker run --env POSTGRES_USER=postgres \
--env POSTGRES_DB=ecto_psql_extras_test \
--env POSTGRES_PASSWORD=postgres \
-d -p 5435:5432 postgres:14.6-alpine \
--env POSTGRES_DB=ecto-psql-extras-test \
--env POSTGRES_PASSWORD=secret \
-d -p 5434:5432 postgres:14.13-alpine \
postgres -c shared_preload_libraries=pg_stat_statements
sleep 5
- name: Run PostgreSQL 15
run: |
docker run --env POSTGRES_USER=postgres \
--env POSTGRES_DB=ecto_psql_extras_test \
--env POSTGRES_PASSWORD=postgres \
-d -p 5436:5432 postgres:15.1-alpine \
--env POSTGRES_DB=ecto-psql-extras-test \
--env POSTGRES_PASSWORD=secret \
-d -p 5435:5432 postgres:15.8-alpine \
postgres -c shared_preload_libraries=pg_stat_statements
sleep 15
- name: Run PostgreSQL 16
run: |
docker run --env POSTGRES_USER=postgres \
--env POSTGRES_DB=ecto-psql-extras-test \
--env POSTGRES_PASSWORD=secret \
-d -p 5436:5432 postgres:16.4-alpine \
postgres -c shared_preload_libraries=pg_stat_statements
sleep 15
- name: Run PostgreSQL 17
run: |
docker run --env POSTGRES_USER=postgres \
--env POSTGRES_DB=ecto-psql-extras-test \
--env POSTGRES_PASSWORD=secret \
-d -p 5437:5432 postgres:17.0-alpine \
postgres -c shared_preload_libraries=pg_stat_statements
sleep 5
sleep 15
- name: Install Dependencies
run: |
mix local.hex --force
mix local.rebar --force
mix deps.get --only test
- name: Run tests for PG 11
env:
PG_VERSION: 11
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
run: |
sleep 4 # wait pg
mix test --include distribution
- name: Run tests for PG 12
env:
PG_VERSION: 12
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
run: |
sleep 4 # wait pg
mix test --include distribution
- name: Run tests for PG 13
env:
PG_VERSION: 13
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
run: |
sleep 4 # wait pg
mix test --include distribution
- name: Run tests for PG 14
env:
PG_VERSION: 14
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
run: |
sleep 4 # wait pg
mix test --include distribution
- name: Run tests for PG 15
env:
PG_VERSION: 15
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
run: |
sleep 4 # wait pg
mix test --include distribution
- name: Install latest compatible postgrex
- name: Run tests for PG 16
env:
PG_VERSION: 16
run: |
mix deps.unlock --all
mix deps.update postgrex
- name: Run tests for PG 11/latest compatible postgrex
sleep 4 # wait pg
mix test --include distribution
- name: Run tests for PG 17
env:
PG_VERSION: 11
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
PG_VERSION: 17
run: |
sleep 4 # wait pg
mix test --include distribution
- name: Install latest compatible postgrex
run: |
mix deps.unlock --all
mix deps.update postgrex
- name: Run tests for PG 12/latest compatible postgrex
env:
PG_VERSION: 12
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
run: |
sleep 4 # wait pg
mix test --include distribution
- name: Run tests for PG 13/latest compatible postgrex
env:
PG_VERSION: 13
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
run: |
sleep 4 # wait pg
mix test --include distribution
- name: Run tests for PG 14/latest compatible postgrex
env:
PG_VERSION: 14
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
run: |
sleep 4 # wait pg
mix test --include distribution
- name: Run tests for PG 15/latest compatible postgrex
env:
PG_VERSION: 15
POSTGRES_HOST: localhost
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
run: |
sleep 4 # wait pg
mix test --include distribution
- name: Run tests for PG 16/latest compatible postgrex
env:
PG_VERSION: 16
run: |
sleep 4 # wait pg
mix test --include distribution
- name: Run tests for PG 17/latest compatible postgrex
env:
PG_VERSION: 17
run: |
sleep 4 # wait pg
mix test --include distribution
52 changes: 30 additions & 22 deletions docker-compose.yml.sample
Original file line number Diff line number Diff line change
@@ -1,48 +1,56 @@
version: '3'

services:
postgres11:
image: postgres:11.18-alpine
postgres12:
image: postgres:12.20-alpine
command: postgres -c shared_preload_libraries=pg_stat_statements
environment:
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ecto-psql-extras-test
POSTGRES_PASSWORD: secret
ports:
- '5432:5432'
postgres12:
image: postgres:12.13-alpine
postgres13:
image: postgres:13.16-alpine
command: postgres -c shared_preload_libraries=pg_stat_statements
environment:
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ecto-psql-extras-test
POSTGRES_PASSWORD: secret
ports:
- '5433:5432'
postgres13:
image: postgres:13.3-alpine
postgres14:
image: postgres:14.13-alpine
command: postgres -c shared_preload_libraries=pg_stat_statements
environment:
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ecto-psql-extras-test
POSTGRES_PASSWORD: secret
ports:
- '5434:5432'
postgres14:
image: postgres:14.6-alpine
postgres15:
image: postgres:15.8-alpine
command: postgres -c shared_preload_libraries=pg_stat_statements
environment:
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ecto-psql-extras-test
POSTGRES_PASSWORD: secret
ports:
- '5435:5432'
postgres15:
image: postgres:15.1-alpine
postgres16:
image: postgres:16.4-alpine
command: postgres -c shared_preload_libraries=pg_stat_statements
environment:
POSTGRES_USER: postgres
POSTGRES_DB: ecto_psql_extras_test
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ecto-psql-extras-test
POSTGRES_PASSWORD: secret
ports:
- '5436:5432'
postgres17:
image: postgres:17.0-alpine
command: postgres -c shared_preload_libraries=pg_stat_statements
environment:
POSTGRES_USER: postgres
POSTGRES_DB: ecto-psql-extras-test
POSTGRES_PASSWORD: secret
ports:
- '5437:5432'

32 changes: 21 additions & 11 deletions lib/ecto_psql_extras.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ defmodule EctoPSQLExtras do
vsn when vsn < {1, 8, 0} ->
%{calls: EctoPSQLExtras.CallsLegacy, outliers: EctoPSQLExtras.OutliersLegacy}

vsn when vsn >= {1, 11, 0} ->
%{calls: EctoPSQLExtras.Calls17, outliers: EctoPSQLExtras.Outliers17}

_vsn ->
%{calls: EctoPSQLExtras.Calls, outliers: EctoPSQLExtras.Outliers}
end
Expand Down Expand Up @@ -133,11 +136,12 @@ defmodule EctoPSQLExtras do
query_module = Map.fetch!(queries(repo), name)
opts = prepare_opts(opts, query_module.info[:default_args])

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 27)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 27)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 27)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 27)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 27)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 27)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 27)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 27)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 27)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 27)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 27)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 27)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 26)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 26)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 26)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 26)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 26)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 26)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 26)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 26)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 26)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 26)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 26)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

Check warning on line 137 in lib/ecto_psql_extras.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.17 | Erlang/OTP 26)

using map.field notation (without parentheses) to invoke function EctoPSQLExtras.CacheHit.info() is deprecated, you must add parentheses instead: remote.function()

result = query!(
repo,
query_module.query(Keyword.fetch!(opts, :args)),
Keyword.get(opts, :query_opts, @default_query_opts)
)
result =
query!(
repo,
query_module.query(Keyword.fetch!(opts, :args)),
Keyword.get(opts, :query_opts, @default_query_opts)
)

format(
Keyword.fetch!(opts, :format),
Expand Down Expand Up @@ -432,15 +436,21 @@ defmodule EctoPSQLExtras do
defp memory_unit(:KB), do: 1024

defp prepare_opts(format, default_args) when is_atom(format) do
IO.warn "This API is deprecated. Please pass format value as a keyword list: `format: :raw`",
Macro.Env.stacktrace(__ENV__)
IO.warn(
"This API is deprecated. Please pass format value as a keyword list: `format: :raw`",
Macro.Env.stacktrace(__ENV__)
)

prepare_opts([format: format], default_args)
end

defp prepare_opts(opts, default_args) do
Keyword.merge([
format: Keyword.get(opts, :format, :ascii),
args: Keyword.merge(default_args || [], opts[:args] || [])
], opts)
Keyword.merge(
[
format: Keyword.get(opts, :format, :ascii),
args: Keyword.merge(default_args || [], opts[:args] || [])
],
opts
)
end
end
36 changes: 36 additions & 0 deletions lib/queries/calls_17.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defmodule EctoPSQLExtras.Calls17 do
@behaviour EctoPSQLExtras

def info do
%{
title: "Queries that have the highest frequency of execution",
index: 21,
order_by: [calls: :desc],
default_args: [limit: 10],
columns: [
%{name: :query, type: :string},
%{name: :exec_time, type: :interval},
%{name: :prop_exec_time, type: :percent},
%{name: :calls, type: :integer},
%{name: :sync_io_time, type: :interval}
]
}
end

def query(args \\ []) do
"""
/* ECTO_PSQL_EXTRAS: Queries that have the highest frequency of execution */
SELECT query AS query,
interval '1 millisecond' * total_exec_time AS exec_time,
(total_exec_time/sum(total_exec_time) OVER()) AS exec_time_ratio,
calls,
interval '1 millisecond' * (shared_blk_read_time + shared_blk_write_time) AS sync_io_time
FROM pg_stat_statements WHERE userid = (SELECT usesysid FROM pg_user WHERE usename = current_user LIMIT 1)
AND query NOT LIKE '/* ECTO_PSQL_EXTRAS:%'
ORDER BY calls DESC
LIMIT <%= limit %>;
"""
|> EEx.eval_string(args)
end
end
Loading

0 comments on commit c834969

Please sign in to comment.