From 2417d20d474a416cd11cb620f83ac91a3d8924f4 Mon Sep 17 00:00:00 2001 From: Ulysse Buonomo Date: Sun, 18 Feb 2024 09:22:11 -0300 Subject: [PATCH] matrix --- .github/workflows/ci.yml | 17 +++++++++++++---- bin/start-cockroachdb | 2 +- .../connection_adapters/cockroachdb_adapter.rb | 12 ++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76358457..f2363cb1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,8 +37,10 @@ jobs: test: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - crdb: [v23.2.0] + # https://www.cockroachlabs.com/docs/releases/release-support-policy + crdb: [v22.2, v23.1, v23.2] ruby: [head] name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }}) steps: @@ -54,16 +56,23 @@ jobs: - name: Install and Start Cockroachdb run: | # Download CockroachDB - wget -qO- https://binaries.cockroachdb.com/cockroach-${{ matrix.crdb }}.linux-amd64.tgz | tar xvz + readonly patch=$( + ruby -rnet/http -ruri -e 'puts Net::HTTP.get( + URI("https://www.cockroachlabs.com/docs/releases/${{ matrix.crdb }}") + )[%r(https://binaries.cockroachdb.com/cockroach-${{ matrix.crdb }}.(\d+).linux-amd64.tgz), 1]' + ) - export PATH=./cockroach-${{ matrix.crdb }}.linux-amd64/:$PATH + echo "Downloading ${{ matrix.crdb }}.$patch" + wget -qO- "https://binaries.cockroachdb.com/cockroach-${{ matrix.crdb }}.$patch.linux-amd64.tgz" | tar xvz + + export PATH=./cockroach-${{ matrix.crdb }}.$patch.linux-amd64/:$PATH readonly urlfile=cockroach-url # Start a CockroachDB server and wait for it to become ready. rm -f "$urlfile" rm -rf cockroach-data # Start CockroachDB. - cockroach start-single-node --max-sql-memory=25% --cache=25% --insecure --host=localhost --spatial-libs=./cockroach-${{ matrix.crdb }}.linux-amd64/lib --listening-url-file="$urlfile" >/dev/null 2>&1 & + cockroach start-single-node --max-sql-memory=25% --cache=25% --insecure --host=localhost --spatial-libs=./cockroach-${{ matrix.crdb }}.$patch.linux-amd64/lib --listening-url-file="$urlfile" >/dev/null 2>&1 & # Ensure CockroachDB is stopped on script exit. # Wait until CockroachDB has started. for i in {0..3}; do diff --git a/bin/start-cockroachdb b/bin/start-cockroachdb index 4b0ddd0c..a4268c37 100755 --- a/bin/start-cockroachdb +++ b/bin/start-cockroachdb @@ -9,7 +9,7 @@ pid_file="$root_dir/tmp/cockroach.pid" log_file="$root_dir/tmp/cockroachdb.log" mkdir -p "$root_dir/tmp" -[[ -f "$pid_file" ]] && kill -9 $(cat "$pid_file") +[[ -f "$pid_file" ]] && kill -9 $(cat "$pid_file") || true rm -f "$pid_file" if ! (( ${+commands[cockroach]} )); then diff --git a/lib/active_record/connection_adapters/cockroachdb_adapter.rb b/lib/active_record/connection_adapters/cockroachdb_adapter.rb index 95d22577..7be8b133 100644 --- a/lib/active_record/connection_adapters/cockroachdb_adapter.rb +++ b/lib/active_record/connection_adapters/cockroachdb_adapter.rb @@ -154,6 +154,18 @@ def max_transaction_retries @max_transaction_retries ||= @config.fetch(:max_transaction_retries, 3) end + def get_database_version + major, minor, patch = query_value("SHOW crdb_version").match(/v(\d+).(\d+).(\d+)/)[1..].map(&:to_i) + major * 100 * 100 + minor * 100 + patch + end + undef :postgresql_version + alias :cockroachdb_version :database_version + + def supports_datetime_with_precision? + # https://github.com/cockroachdb/cockroach/pull/111400 + database_version >= 23_01_13 + end + def supports_ddl_transactions? false end