Skip to content

Commit

Permalink
chore: Add pg17 to test matrix (#2176)
Browse files Browse the repository at this point in the history
Had to trim the unique test db names, for some reason Postgrex was
failing otherwise with pg17 (used short hashes to improve uniqueness
guarantee)

---------

Co-authored-by: Rob A'Court <[email protected]>
  • Loading branch information
msfstef and robacourt authored Dec 17, 2024
1 parent acb46e1 commit 5a844d9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/elixir_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
working-directory: packages/sync-service
strategy:
matrix:
postgres_version: [14, 15]
postgres_version: [14, 15, 17]
env:
MIX_ENV: test
POSTGRES_VERSION: "${{ matrix.postgres_version }}0000"
Expand Down
4 changes: 2 additions & 2 deletions packages/sync-service/dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "electric_dev"

services:
postgres:
image: postgres:16-alpine
image: postgres:17-alpine
environment:
POSTGRES_DB: electric
POSTGRES_USER: postgres
Expand All @@ -21,7 +21,7 @@ services:
- -c
- config_file=/etc/postgresql.conf
postgres2:
image: postgres:16-alpine
image: postgres:17-alpine
environment:
POSTGRES_DB: electric
POSTGRES_USER: postgres
Expand Down
13 changes: 12 additions & 1 deletion packages/sync-service/test/support/db_setup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ defmodule Support.DbSetup do
{:ok, utility_pool} = start_db_pool(base_config)
Process.unlink(utility_pool)

db_name = to_string(ctx.test)
full_db_name = to_string(ctx.test)

db_name_hash =
full_db_name
|> :erlang.phash2(64 ** 5)
|> :binary.encode_unsigned()
|> Base.encode64()
|> String.replace_trailing("==", "")

# Truncate the database name to 63 characters, use hash to guarantee uniqueness
db_name = "#{db_name_hash} ~ #{String.slice(full_db_name, 0..50)}"

escaped_db_name = :binary.replace(db_name, ~s'"', ~s'""', [:global])

Postgrex.query!(utility_pool, "DROP DATABASE IF EXISTS \"#{escaped_db_name}\"", [])
Expand Down

0 comments on commit 5a844d9

Please sign in to comment.