Skip to content

Commit 08dddfe

Browse files
committed
many things
1 parent 10fa07c commit 08dddfe

File tree

7 files changed

+47
-75
lines changed

7 files changed

+47
-75
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
fail-fast: false
4141
matrix:
4242
# https://www.cockroachlabs.com/docs/releases/release-support-policy
43-
crdb: [v22.2, v23.1, v23.2]
43+
crdb: [v23.2, v24.1, v24.2]
4444
ruby: [head]
4545
name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }})
4646
steps:

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.3
1+
3.4.0-preview1

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Getting started
22

3-
43
## ActiveRecord adapters and you
54

65
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
121120
better to be able to test multiple versions of the adapter, and do so
122121
against different versions of CockroachDB.
123122

124-
125123
## Adding feature support
126124

127125
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.
148146
```
149147
- Verify the written text at the beginning of the test suite, there are likely
150148
some changes in excluded tests.
149+
- Check for some important methods, some will change for sure:
150+
- [x] `def new_column_from_field(`
151+
- [x] `def column_definitions(`
152+
- [ ] ...
151153

152154
## Execute only tests that run with a connection
153155

lib/active_record/connection_adapters/cockroachdb_adapter.rb

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -217,31 +217,6 @@ def check_version # :nodoc:
217217
end
218218
end
219219

220-
# NOTE: This commented bit of code allows to have access to crdb version,
221-
# which can be useful for feature detection. However, we currently don't
222-
# need, hence we avoid the extra queries.
223-
#
224-
# def initialize(connection, logger, conn_params, config)
225-
# super(connection, logger, conn_params, config)
226-
227-
# # crdb_version is the version of the binary running on the node. We
228-
# # really want to use `SHOW CLUSTER SETTING version` to get the cluster
229-
# # version, but that is only available to admins. Instead, we can use
230-
# # crdb_internal.is_at_least_version, but that's only available in 22.1.
231-
# crdb_version_string = query_value("SHOW crdb_version")
232-
# if crdb_version_string.include? "v22.1"
233-
# version_num = query_value(<<~SQL, "VERSION")
234-
# SELECT
235-
# CASE
236-
# WHEN crdb_internal.is_at_least_version('22.2') THEN 2220
237-
# WHEN crdb_internal.is_at_least_version('22.1') THEN 2210
238-
# ELSE 2120
239-
# END;
240-
# SQL
241-
# end
242-
# @crdb_version = version_num.to_i
243-
# end
244-
245220
def initialize(...)
246221
super
247222

test/excludes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapterTest.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,3 @@
1919

2020
exclude :test_pk_and_sequence_for, "The test needs a little rework since the sequence is empty in CRDB"
2121
exclude :test_pk_and_sequence_for_with_non_standard_primary_key, "The test needs a little rework since the sequence is empty in CRDB"
22-
23-
plpgsql_needed = "Will be testable with CRDB 23.2, introducing PL-PGSQL"
24-
exclude :test_ignores_warnings_when_behaviour_ignore, plpgsql_needed
25-
exclude :test_logs_warnings_when_behaviour_log, plpgsql_needed
26-
exclude :test_raises_warnings_when_behaviour_raise, plpgsql_needed
27-
exclude :test_reports_when_behaviour_report, plpgsql_needed
28-
exclude :test_warnings_behaviour_can_be_customized_with_a_proc, plpgsql_needed
29-
exclude :test_allowlist_of_warnings_to_ignore, plpgsql_needed
30-
exclude :test_allowlist_of_warning_codes_to_ignore, plpgsql_needed

test/excludes/BasicsTest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exclude :test_column_names_are_escaped, "The test raises an exception because the setup doesn't account for other adpaters like CockroachDBAdapter."
1+
exclude :test_column_names_are_escaped, "Rewritten for CockroachDB"

test/schema/cockroachdb_specific_schema.rb

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@
5757
id INT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
5858
)
5959
SQL
60+
61+
drop_table "cpk_postgresql_identity_table", if_exists: true
62+
execute <<~SQL
63+
create table cpk_postgresql_identity_table (
64+
another_id INT NOT NULL,
65+
id INT NOT NULL GENERATED BY DEFAULT AS IDENTITY,
66+
CONSTRAINT cpk_postgresql_identity_table_pkey PRIMARY KEY (another_id, id)
67+
)
68+
SQL
6069
end
6170

6271
create_table :postgresql_times, force: true do |t|
@@ -77,9 +86,7 @@
7786
execute "ALTER TABLE companies ALTER COLUMN id SET DEFAULT nextval('companies_nonstd_seq')"
7887
execute "DROP SEQUENCE IF EXISTS companies_id_seq"
7988

80-
# Stored procedures are not supported in CockroachDB.
81-
# See https://github.com/cockroachdb/cockroach/issues/17511.
82-
# execute "DROP FUNCTION IF EXISTS partitioned_insert_trigger()"
89+
execute "DROP FUNCTION IF EXISTS partitioned_insert_trigger()"
8390

8491
# CockroachDB uses unique_rowid() for primary keys by default instead of
8592
# sequences. Therefore, there aren't any sequences to update here.
@@ -95,39 +102,36 @@
95102
);
96103
_SQL
97104

98-
# Since stored procedures are not supported in CockroachDB, it won't be possible
99-
# to do trigger based partitioning.
100-
# See https://github.com/cockroachdb/cockroach/issues/17511.
101-
# begin
102-
# execute <<_SQL
103-
# CREATE TABLE postgresql_partitioned_table_parent (
104-
# id SERIAL PRIMARY KEY,
105-
# number integer
106-
# );
107-
# CREATE TABLE postgresql_partitioned_table ( )
108-
# INHERITS (postgresql_partitioned_table_parent);
109-
#
110-
# CREATE OR REPLACE FUNCTION partitioned_insert_trigger()
111-
# RETURNS TRIGGER AS $$
112-
# BEGIN
113-
# INSERT INTO postgresql_partitioned_table VALUES (NEW.*);
114-
# RETURN NULL;
115-
# END;
116-
# $$
117-
# LANGUAGE plpgsql;
118-
#
119-
# CREATE TRIGGER insert_partitioning_trigger
120-
# BEFORE INSERT ON postgresql_partitioned_table_parent
121-
# FOR EACH ROW EXECUTE PROCEDURE partitioned_insert_trigger();
122-
# _SQL
123-
# rescue ActiveRecord::StatementInvalid => e
124-
# if e.message.include?('language "plpgsql" does not exist')
125-
# execute "CREATE LANGUAGE 'plpgsql';"
126-
# retry
127-
# else
128-
# raise e
129-
# end
130-
# end
105+
begin
106+
execute <<_SQL
107+
CREATE TABLE postgresql_partitioned_table_parent (
108+
id SERIAL PRIMARY KEY,
109+
number integer
110+
);
111+
CREATE TABLE postgresql_partitioned_table ( )
112+
INHERITS (postgresql_partitioned_table_parent);
113+
114+
CREATE OR REPLACE FUNCTION partitioned_insert_trigger()
115+
RETURNS TRIGGER AS $$
116+
BEGIN
117+
INSERT INTO postgresql_partitioned_table VALUES (NEW.*);
118+
RETURN NULL;
119+
END;
120+
$$
121+
LANGUAGE plpgsql;
122+
123+
CREATE TRIGGER insert_partitioning_trigger
124+
BEFORE INSERT ON postgresql_partitioned_table_parent
125+
FOR EACH ROW EXECUTE PROCEDURE partitioned_insert_trigger();
126+
_SQL
127+
rescue ActiveRecord::StatementInvalid => e
128+
if e.message.include?('language "plpgsql" does not exist')
129+
execute "CREATE LANGUAGE 'plpgsql';"
130+
retry
131+
else
132+
raise e
133+
end
134+
end
131135

132136
# This table is to verify if the :limit option is being ignored for text and binary columns
133137
create_table :limitless_fields, force: true do |t|

0 commit comments

Comments
 (0)