diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8974277..054c51ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: fail-fast: false matrix: # https://www.cockroachlabs.com/docs/releases/release-support-policy - crdb: [v22.2, v23.1, v23.2] + crdb: [v23.2, v24.1, v24.2] ruby: [head] name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }}) steps: diff --git a/.ruby-version b/.ruby-version index b347b11e..da719d1f 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.2.3 +3.4.0-preview1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b0d7e1cb..f7e9683d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,5 @@ # Getting started - ## ActiveRecord adapters and you There are two repositories for the ActiveRecord adapter. The one you're in @@ -121,7 +120,6 @@ master branch, with an alpha build of CockroachDB. it would be even better to be able to test multiple versions of the adapter, and do so against different versions of CockroachDB. - ## Adding feature support As CockroachDB improves, so do the features that can be supported in @@ -148,6 +146,10 @@ This section intent to help you with a checklist. ``` - Verify the written text at the beginning of the test suite, there are likely some changes in excluded tests. +- Check for some important methods, some will change for sure: + - [x] `def new_column_from_field(` + - [x] `def column_definitions(` + - [ ] ... ## Execute only tests that run with a connection diff --git a/lib/active_record/connection_adapters/cockroachdb_adapter.rb b/lib/active_record/connection_adapters/cockroachdb_adapter.rb index 15d9519c..76ebdbd0 100644 --- a/lib/active_record/connection_adapters/cockroachdb_adapter.rb +++ b/lib/active_record/connection_adapters/cockroachdb_adapter.rb @@ -217,31 +217,6 @@ def check_version # :nodoc: end end - # NOTE: This commented bit of code allows to have access to crdb version, - # which can be useful for feature detection. However, we currently don't - # need, hence we avoid the extra queries. - # - # def initialize(connection, logger, conn_params, config) - # super(connection, logger, conn_params, config) - - # # crdb_version is the version of the binary running on the node. We - # # really want to use `SHOW CLUSTER SETTING version` to get the cluster - # # version, but that is only available to admins. Instead, we can use - # # crdb_internal.is_at_least_version, but that's only available in 22.1. - # crdb_version_string = query_value("SHOW crdb_version") - # if crdb_version_string.include? "v22.1" - # version_num = query_value(<<~SQL, "VERSION") - # SELECT - # CASE - # WHEN crdb_internal.is_at_least_version('22.2') THEN 2220 - # WHEN crdb_internal.is_at_least_version('22.1') THEN 2210 - # ELSE 2120 - # END; - # SQL - # end - # @crdb_version = version_num.to_i - # end - def initialize(...) super diff --git a/test/excludes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapterTest.rb b/test/excludes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapterTest.rb index 53e09a4d..c848d183 100644 --- a/test/excludes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapterTest.rb +++ b/test/excludes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapterTest.rb @@ -19,12 +19,3 @@ exclude :test_pk_and_sequence_for, "The test needs a little rework since the sequence is empty in CRDB" exclude :test_pk_and_sequence_for_with_non_standard_primary_key, "The test needs a little rework since the sequence is empty in CRDB" - -plpgsql_needed = "Will be testable with CRDB 23.2, introducing PL-PGSQL" -exclude :test_ignores_warnings_when_behaviour_ignore, plpgsql_needed -exclude :test_logs_warnings_when_behaviour_log, plpgsql_needed -exclude :test_raises_warnings_when_behaviour_raise, plpgsql_needed -exclude :test_reports_when_behaviour_report, plpgsql_needed -exclude :test_warnings_behaviour_can_be_customized_with_a_proc, plpgsql_needed -exclude :test_allowlist_of_warnings_to_ignore, plpgsql_needed -exclude :test_allowlist_of_warning_codes_to_ignore, plpgsql_needed diff --git a/test/excludes/BasicsTest.rb b/test/excludes/BasicsTest.rb index 62e129f7..9061ca48 100644 --- a/test/excludes/BasicsTest.rb +++ b/test/excludes/BasicsTest.rb @@ -1 +1 @@ -exclude :test_column_names_are_escaped, "The test raises an exception because the setup doesn't account for other adpaters like CockroachDBAdapter." +exclude :test_column_names_are_escaped, "Rewritten for CockroachDB" diff --git a/test/schema/cockroachdb_specific_schema.rb b/test/schema/cockroachdb_specific_schema.rb index ccd702ba..c6b69e1d 100644 --- a/test/schema/cockroachdb_specific_schema.rb +++ b/test/schema/cockroachdb_specific_schema.rb @@ -57,6 +57,15 @@ id INT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY ) SQL + + drop_table "cpk_postgresql_identity_table", if_exists: true + execute <<~SQL + create table cpk_postgresql_identity_table ( + another_id INT NOT NULL, + id INT NOT NULL GENERATED BY DEFAULT AS IDENTITY, + CONSTRAINT cpk_postgresql_identity_table_pkey PRIMARY KEY (another_id, id) + ) + SQL end create_table :postgresql_times, force: true do |t| @@ -77,9 +86,7 @@ execute "ALTER TABLE companies ALTER COLUMN id SET DEFAULT nextval('companies_nonstd_seq')" execute "DROP SEQUENCE IF EXISTS companies_id_seq" - # Stored procedures are not supported in CockroachDB. - # See https://github.com/cockroachdb/cockroach/issues/17511. - # execute "DROP FUNCTION IF EXISTS partitioned_insert_trigger()" + execute "DROP FUNCTION IF EXISTS partitioned_insert_trigger()" # CockroachDB uses unique_rowid() for primary keys by default instead of # sequences. Therefore, there aren't any sequences to update here. @@ -95,39 +102,36 @@ ); _SQL -# Since stored procedures are not supported in CockroachDB, it won't be possible -# to do trigger based partitioning. -# See https://github.com/cockroachdb/cockroach/issues/17511. -# begin -# execute <<_SQL -# CREATE TABLE postgresql_partitioned_table_parent ( -# id SERIAL PRIMARY KEY, -# number integer -# ); -# CREATE TABLE postgresql_partitioned_table ( ) -# INHERITS (postgresql_partitioned_table_parent); -# -# CREATE OR REPLACE FUNCTION partitioned_insert_trigger() -# RETURNS TRIGGER AS $$ -# BEGIN -# INSERT INTO postgresql_partitioned_table VALUES (NEW.*); -# RETURN NULL; -# END; -# $$ -# LANGUAGE plpgsql; -# -# CREATE TRIGGER insert_partitioning_trigger -# BEFORE INSERT ON postgresql_partitioned_table_parent -# FOR EACH ROW EXECUTE PROCEDURE partitioned_insert_trigger(); -# _SQL -# rescue ActiveRecord::StatementInvalid => e -# if e.message.include?('language "plpgsql" does not exist') -# execute "CREATE LANGUAGE 'plpgsql';" -# retry -# else -# raise e -# end -# end + begin + execute <<_SQL + CREATE TABLE postgresql_partitioned_table_parent ( + id SERIAL PRIMARY KEY, + number integer + ); + CREATE TABLE postgresql_partitioned_table ( ) + INHERITS (postgresql_partitioned_table_parent); + + CREATE OR REPLACE FUNCTION partitioned_insert_trigger() + RETURNS TRIGGER AS $$ + BEGIN + INSERT INTO postgresql_partitioned_table VALUES (NEW.*); + RETURN NULL; + END; + $$ + LANGUAGE plpgsql; + + CREATE TRIGGER insert_partitioning_trigger + BEFORE INSERT ON postgresql_partitioned_table_parent + FOR EACH ROW EXECUTE PROCEDURE partitioned_insert_trigger(); +_SQL + rescue ActiveRecord::StatementInvalid => e + if e.message.include?('language "plpgsql" does not exist') + execute "CREATE LANGUAGE 'plpgsql';" + retry + else + raise e + end + end # This table is to verify if the :limit option is being ignored for text and binary columns create_table :limitless_fields, force: true do |t|