Skip to content

Commit

Permalink
many things
Browse files Browse the repository at this point in the history
  • Loading branch information
BuonOmo committed Aug 29, 2024
1 parent 10fa07c commit 08dddfe
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.3
3.4.0-preview1
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Getting started


## ActiveRecord adapters and you

There are two repositories for the ActiveRecord adapter. The one you're in
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
25 changes: 0 additions & 25 deletions lib/active_record/connection_adapters/cockroachdb_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/excludes/BasicsTest.rb
Original file line number Diff line number Diff line change
@@ -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"
76 changes: 40 additions & 36 deletions test/schema/cockroachdb_specific_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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.
Expand All @@ -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|
Expand Down

0 comments on commit 08dddfe

Please sign in to comment.