Skip to content

Commit

Permalink
Add MySQL 8 to CI (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-rychlewski authored Oct 4, 2023
1 parent e25ea9e commit 2df2896
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
- "1.11.4-erlang-21.3.8.24-alpine-3.13.3"
mysql:
- "5.7"
- "8.0"
steps:
- uses: earthly/actions-setup@v1
- uses: actions/checkout@v3
Expand Down
5 changes: 4 additions & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ integration-test-mysql:
--pull "mysql:$MYSQL"
RUN set -e; \
timeout=$(expr $(date +%s) + 30); \
docker run --name mysql --network=host -d -e MYSQL_ROOT_PASSWORD=root "mysql:$MYSQL" --sql_mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES"; \
docker run --name mysql --network=host -d -e MYSQL_ROOT_PASSWORD=root "mysql:$MYSQL" \
--sql_mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES" \
# the default authentication plugin for MySQL 8 is sha 256 but it doesn't come with the docker image. falling back to the 5.7 way
--default-authentication-plugin=mysql_native_password; \
# wait for mysql to start
while ! mysqladmin ping --host=127.0.0.1 --port=3306 --protocol=TCP --silent; do \
test "$(date +%s)" -le "$timeout" || (echo "timed out waiting for mysql"; exit 1); \
Expand Down
9 changes: 9 additions & 0 deletions integration_test/myxql/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ Application.put_env(:ecto_sql, TestRepo,
url: Application.get_env(:ecto_sql, :mysql_test_url) <> "/ecto_test",
pool: Ecto.Adapters.SQL.Sandbox,
show_sensitive_data_on_connection_error: true,
after_connect: {Ecto.Integration.TestRepo, :set_connection_charset, []},
log: false
)

defmodule Ecto.Integration.TestRepo do
use Ecto.Integration.Repo, otp_app: :ecto_sql, adapter: Ecto.Adapters.MyXQL

def set_connection_charset(conn) do
%{rows: [[version]]} = MyXQL.query!(conn, "SELECT @@version", [])

if version >= "8.0.0" do
_ = MyXQL.query!(conn, "SET NAMES utf8mb4 COLLATE utf8mb4_0900_ai_ci;", [])
end
end

def create_prefix(prefix) do
"create database #{prefix}"
end
Expand Down

0 comments on commit 2df2896

Please sign in to comment.