From 5a844d9690c7b831ff9b1a01d155468a39881f37 Mon Sep 17 00:00:00 2001 From: Stefanos Mousafeiris Date: Tue, 17 Dec 2024 18:16:57 +0200 Subject: [PATCH] chore: Add pg17 to test matrix (#2176) 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 --- .github/workflows/elixir_tests.yml | 2 +- packages/sync-service/dev/docker-compose.yml | 4 ++-- packages/sync-service/test/support/db_setup.ex | 13 ++++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/elixir_tests.yml b/.github/workflows/elixir_tests.yml index c1406110a7..61b33691c1 100644 --- a/.github/workflows/elixir_tests.yml +++ b/.github/workflows/elixir_tests.yml @@ -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" diff --git a/packages/sync-service/dev/docker-compose.yml b/packages/sync-service/dev/docker-compose.yml index 3fe51b382f..0ab43e545b 100644 --- a/packages/sync-service/dev/docker-compose.yml +++ b/packages/sync-service/dev/docker-compose.yml @@ -3,7 +3,7 @@ name: "electric_dev" services: postgres: - image: postgres:16-alpine + image: postgres:17-alpine environment: POSTGRES_DB: electric POSTGRES_USER: postgres @@ -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 diff --git a/packages/sync-service/test/support/db_setup.ex b/packages/sync-service/test/support/db_setup.ex index 1493ba6ac9..7412506eae 100644 --- a/packages/sync-service/test/support/db_setup.ex +++ b/packages/sync-service/test/support/db_setup.ex @@ -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}\"", [])