activerecord-cockroachdb-adapter 7.1.1 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +3 -3
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +4 -0
  5. data/CONTRIBUTING.md +35 -90
  6. data/Gemfile +4 -4
  7. data/LICENSE +1 -2
  8. data/README.md +7 -5
  9. data/activerecord-cockroachdb-adapter.gemspec +2 -2
  10. data/bin/console +1 -1
  11. data/lib/active_record/connection_adapters/cockroachdb/arel_tosql.rb +14 -0
  12. data/lib/active_record/connection_adapters/cockroachdb/attribute_methods.rb +16 -0
  13. data/lib/active_record/connection_adapters/cockroachdb/column.rb +16 -0
  14. data/lib/active_record/connection_adapters/cockroachdb/column_methods.rb +14 -0
  15. data/lib/active_record/connection_adapters/cockroachdb/database_statements.rb +16 -0
  16. data/lib/active_record/connection_adapters/cockroachdb/database_tasks.rb +18 -2
  17. data/lib/active_record/connection_adapters/cockroachdb/oid/date_time.rb +14 -0
  18. data/lib/active_record/connection_adapters/cockroachdb/oid/interval.rb +16 -0
  19. data/lib/active_record/connection_adapters/cockroachdb/oid/spatial.rb +14 -0
  20. data/lib/active_record/connection_adapters/cockroachdb/quoting.rb +16 -0
  21. data/lib/active_record/connection_adapters/cockroachdb/referential_integrity.rb +14 -0
  22. data/lib/active_record/connection_adapters/cockroachdb/schema_creation.rb +14 -1
  23. data/lib/active_record/connection_adapters/cockroachdb/schema_dumper.rb +14 -1
  24. data/lib/active_record/connection_adapters/cockroachdb/schema_statements.rb +94 -0
  25. data/lib/active_record/connection_adapters/cockroachdb/setup.rb +14 -0
  26. data/lib/active_record/connection_adapters/cockroachdb/spatial_column_info.rb +16 -0
  27. data/lib/active_record/connection_adapters/cockroachdb/table_definition.rb +14 -0
  28. data/lib/active_record/connection_adapters/cockroachdb/transaction_manager.rb +14 -0
  29. data/lib/active_record/connection_adapters/cockroachdb/type.rb +16 -0
  30. data/lib/active_record/connection_adapters/cockroachdb_adapter.rb +56 -55
  31. data/lib/active_record/migration/cockroachdb/compatibility.rb +16 -0
  32. data/lib/active_record/relation/query_methods_ext.rb +14 -0
  33. data/lib/activerecord-cockroachdb-adapter.rb +21 -0
  34. data/lib/arel/nodes/join_source_ext.rb +16 -0
  35. data/lib/version.rb +15 -1
  36. metadata +10 -11
  37. data/.ruby-version +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 672289521537934d4b9ed2d707c3faf55b4761c8d2b4e9e12cd8622166963ae7
4
- data.tar.gz: 345a84d7c5bca0d574aa65eb0fb0e30986a23fcc2830f422e5b1d80ffa971076
3
+ metadata.gz: 496e736f6d7baf4f0acb18461a70d7686765262e3fd09f4a65ac49534582d871
4
+ data.tar.gz: 9bd072d1ac20b7f1099076fb5019c9cfbee305da4463de7f91ec493c8f6eebe3
5
5
  SHA512:
6
- metadata.gz: 4ce6d2119bfc27192630c32ec488b3e7f533cc64963fc04035609122e5bdbc33e75b83766ca68e3eb73e2592b2fe0a1bae53a74389527762f790b16bda687da9
7
- data.tar.gz: 42e10ab1106e4ffc4df89bbbf98f8ddbd05b6bccf97b062a9445ebf874a8bfef9e628dce8b39c3287424a7094f70790457293a2766a849bd39ac0e20c7a684fe
6
+ metadata.gz: '044899369534c133039634cc835ce3efd71500a527d9249b10ca34fb8cb343f4754e0c72c8bc0f560267348881fe5d8e7701921b270431dfde1a810f1c48efad'
7
+ data.tar.gz: 5c67f56709062e0982998ff59f49f9caa1b14bb630e81339d6183821add59bfaf731f2af5e416b724fc00d3f57e17d63138eabec63166288185d69284bd53891
@@ -40,8 +40,8 @@ jobs:
40
40
  fail-fast: false
41
41
  matrix:
42
42
  # https://www.cockroachlabs.com/docs/releases/release-support-policy
43
- crdb: [v22.2, v23.1, v23.2]
44
- ruby: [head]
43
+ crdb: [v23.2, v24.1, v24.2]
44
+ ruby: ["3.3"]
45
45
  name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }})
46
46
  steps:
47
47
  - name: Set Up Actions
@@ -88,4 +88,4 @@ jobs:
88
88
  done
89
89
  cat ${{ github.workspace }}/setup.sql | cockroach sql --insecure
90
90
  - name: Test
91
- run: bundle exec rake test TESTOPTS='--profile=3'
91
+ run: bundle exec rake test TESTOPTS='--profile=5'
data/.gitignore CHANGED
@@ -15,3 +15,4 @@
15
15
  /docker_root/
16
16
  /ruby-build/
17
17
  /test/db/
18
+ /.ruby-version
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Ongoing
4
4
 
5
+ ## 7.2.0 - 2024-09-24
6
+
7
+ - Add support for Rails 7.2 ([#337](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/337))
8
+
5
9
  ## 7.1.1 - 2024-05-01
6
10
 
7
11
  - Enable precision support ([#318](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/318))
data/CONTRIBUTING.md CHANGED
@@ -1,18 +1,5 @@
1
1
  # Getting started
2
2
 
3
-
4
- ## ActiveRecord adapters and you
5
-
6
- There are two repositories for the ActiveRecord adapter. The one you're in
7
- currently, [activerecord-cockroachdb-adapter], is the CockroachDB specific
8
- ActiveRecord code. Users install this alongside ActiveRecord then use
9
- CockroachDBAdapter to initialize ActiveRecord for their projects.
10
-
11
- This adapter extends the PostgreSQL ActiveRecord adapter in order to
12
- override and monkey-patch functionality.
13
-
14
- [activerecord-cockroachdb-adapter]: https://github.com/cockroachdb/activerecord-cockroachdb-adapter/
15
-
16
3
  ## Setup and running tests
17
4
 
18
5
  ### CockroachDB
@@ -23,6 +10,7 @@ create two databases to be used by the ActiveRecord test suite:
23
10
  activerecord_unittest and activerecord_unittest2.
24
11
 
25
12
  ```sql
13
+ -- See /setup.sql file for the whole setup.
26
14
  CREATE DATABASE activerecord_unittest;
27
15
  CREATE DATABASE activerecord_unittest2;
28
16
  ```
@@ -36,30 +24,6 @@ Ruby version.
36
24
  tests similarly to TeamCity. The database is destroyed between each
37
25
  test file.)
38
26
 
39
- Install rbenv with ruby-build on MacOS:
40
-
41
- ```bash
42
- brew install rbenv ruby-build
43
- echo 'eval "$(rbenv init - zsh)"' >> ~/.profile
44
- ```
45
-
46
- Install rbenv with ruby-build on Ubuntu:
47
-
48
- ```bash
49
- sudo apt-get install rbenv
50
- echo 'eval "$(rbenv init - zsh)"' >> ~/.profile
51
-
52
- git clone https://github.com/sstephenson/ruby-build.git ~/ruby-build
53
- sh ~/ruby-build/install.sh
54
- ```
55
-
56
- Use rbenv to install version of Ruby specified by `.ruby-version`.
57
-
58
- ```bash
59
- rbenv install
60
- rbenv rehash
61
- ```
62
-
63
27
  Using [bundler](http://bundler.io/), install the dependencies of Rails.
64
28
 
65
29
  ```bash
@@ -87,9 +51,12 @@ TEST_FILES="test/cases/adapter_test.rb,test/cases/associations/left_outer_join_a
87
51
  To run a specific test case, use minitest's `-n` option to run tests that match a given pattern. All minitest options are set via the `TESTOPTS` environemnt variable. For example, to run `test_indexes` from CockroachDB's `test/cases/adapter_test.rb` file
88
52
 
89
53
  ```bash
90
- TEST_FILES="test/cases/adapter_test.rb" TESTOPTS=`-n=/test_indexes/` bundle exec rake test
54
+ TEST_FILES="test/cases/adapter_test.rb" TESTOPTS=`--name=/test_indexes/` bundle exec rake test
91
55
  ```
92
56
 
57
+ You can also use the constant `COCKROACH_SKIP_LOAD_SCHEMA` to avoid reloading the schema every time (faster).
58
+ Only do it if you know the schema was left in a correct state.
59
+
93
60
  `test/config.yml` assumes CockroachDB will be running at localhost:26257 with a root user. Make changes to `test/config.yml` as needed.
94
61
 
95
62
  ### Run Tests from a Backup
@@ -121,7 +88,6 @@ master branch, with an alpha build of CockroachDB. it would be even
121
88
  better to be able to test multiple versions of the adapter, and do so
122
89
  against different versions of CockroachDB.
123
90
 
124
-
125
91
  ## Adding feature support
126
92
 
127
93
  As CockroachDB improves, so do the features that can be supported in
@@ -131,15 +97,36 @@ gates should be toggled. Something that would help this process would be
131
97
  linking those issues back to this adapter so that part of the feature
132
98
  completing includes updating the adapter.
133
99
 
134
-
135
- ## Execute only tests that run with a connection
136
-
137
- I have not investigated if this is already possible, but I would assume
138
- no.
139
-
140
- A possible way to approach this would be to add a shim to cause any
141
- tests that use it to fail, and grep the tests that pass and then skip
142
- them.
100
+ ## Upgrading Rails
101
+
102
+ Whenever you upgrade rails version, loads of things will change.
103
+ This section intent to help you with a checklist.
104
+
105
+ - Check for TODO or NOTE tags that are referencing the old or new version of
106
+ rails.
107
+ ```bash
108
+ rg 'TODO|NOTE' --after-context=2
109
+ ```
110
+ - Check postgresql_specific_schema.rb changelog in rails, and apply the changes
111
+ you want. Ex:
112
+ ```bash
113
+ git diff v7.1.4..v7.2.1 -- $(fd postgresql_specific_schema)
114
+ ```
115
+ - Verify the written text at the beginning of the test suite, there are likely
116
+ some changes in excluded tests.
117
+ - Check for some important methods, some will change for sure:
118
+ - [x] `def new_column_from_field(`
119
+ - [x] `def column_definitions(`
120
+ - [x] `def pk_and_sequence_for(`
121
+ - [ ] ...
122
+ - Check for setups containing `drop_table` in the test suite.
123
+ Especially if you have tons of failure, this is likely the cause.
124
+ - In the same way, run `test/cases/fixtures_test.rb` first, and check
125
+ if this corrupted the test database for other tests.
126
+ - For both of the above, the diff of `schema.rb` can be useful:
127
+ ```bash
128
+ git diff v7.1.2..v7.2.1 -- activerecord/test/schema/schema.rb
129
+ ```
143
130
 
144
131
  ## Publishing to Rubygems
145
132
 
@@ -151,7 +138,6 @@ gem build ...
151
138
  gem publish <output file>
152
139
  ```
153
140
 
154
-
155
141
  # Notes
156
142
 
157
143
  When executing the test suite, each test file will reload fixtures. This
@@ -182,49 +168,8 @@ cleaned up, or skipped until passing.
182
168
  The purpose of these was to make the tests grep-able while going through
183
169
  all the failures.
184
170
 
185
-
186
171
  [cockroachdb/cockroach#20753]: https://github.com/cockroachdb/cockroach/issues/20753#issuecomment-352810425
187
172
 
188
-
189
- ## Tracked test failures
190
-
191
- Some of the skipped failures are:
192
-
193
- - `default:` key is not working for columns in table schema
194
- definitions. This causes tests to fail due to unexpected data.
195
-
196
- - `array:` key is not working for columns in table schema definitions.
197
-
198
- - `"Salary is not appearing in list"` is being raised in a number of
199
- places. Likely during fixture setup.
200
-
201
- - `sum` function seems to result in a different type in ActiveRecord.
202
- Instead of returning a Ruby `int`, it returns a Ruby `string`. It
203
- appears that MySQL2 also does this. A suspected cause might be how
204
- `Decimal` is handled if `sum` consumes integers and return a
205
- decimal.
206
-
207
- - Potentially fork the PostgreSQL::SchemaDumper to handle anything
208
- specific to CockroachDB, like primary keys or bigints.
209
-
210
- - You can call `@connection.create_table(..., id: :bigint)`, but this
211
- will not changes things for CockroachDB (I think...), so it would be
212
- not allowed. Even better, our adapter could interpret this and
213
- generate the appropriate explicit pkey column. Not sure what string
214
- pkeys look like...
215
-
216
- - `string` types are introspected to `text` types.
217
-
218
- - A user can do an update, delete, and insert on views.
219
-
220
- - Postgres specific bit strings are not properly supported.
221
-
222
- Grepping for `FIXME(joey)`, `TODO(joey)`, and `NOTE(joey)` will yeild
223
- most of the touchpoints including test failures and temporary monkey
224
- patches. Some monkey patches were made directly to Rails, which will
225
- need to be cleaned up.
226
-
227
-
228
173
  # Notes for the non-Rubyer
229
174
 
230
175
  rbenv is an environment manager that lets you manage and swap between
data/Gemfile CHANGED
@@ -50,6 +50,7 @@ group :development, :test do
50
50
 
51
51
  # Needed for the test suite
52
52
  gem "msgpack", ">= 1.7.0"
53
+ gem "mutex_m", "~> 0.2.0"
53
54
 
54
55
  gem "rake"
55
56
  gem "debug"
@@ -61,9 +62,8 @@ group :development, :test do
61
62
  gem "parser"
62
63
 
63
64
  # Gems used by the ActiveRecord test suite
64
- gem "bcrypt", "~> 3.1.18"
65
- gem "mocha", "~> 1.14.0"
66
- gem "sqlite3", "~> 1.4.4"
65
+ gem "bcrypt", "~> 3.1"
66
+ gem "sqlite3", "~> 1.4"
67
67
 
68
- gem "minitest", "~> 5.15.0"
68
+ gem "minitest", "~> 5.15"
69
69
  end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Apache License
1
+ Apache License
2
2
  Version 2.0, January 2004
3
3
  http://www.apache.org/licenses/
4
4
 
@@ -199,4 +199,3 @@ Apache License
199
199
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
200
  See the License for the specific language governing permissions and
201
201
  limitations under the License.
202
-
data/README.md CHANGED
@@ -1,20 +1,22 @@
1
1
  # ActiveRecord CockroachDB Adapter
2
2
 
3
- CockroachDB adapter for ActiveRecord 5, 6, and 7. This is a lightweight extension of the PostgreSQL adapter that establishes compatibility with [CockroachDB](https://github.com/cockroachdb/cockroach).
3
+ CockroachDB adapter for ActiveRecord. This is a lightweight extension
4
+ of the PostgreSQL adapter that establishes compatibility with [CockroachDB](https://github.com/cockroachdb/cockroach).
4
5
 
5
6
  ## Installation
6
7
 
7
8
  Add this line to your project's Gemfile:
8
9
 
9
10
  ```ruby
10
- gem 'activerecord-cockroachdb-adapter', '~> 7.0.0'
11
+ gem 'activerecord-cockroachdb-adapter', '~> 7.2.0'
11
12
  ```
12
13
 
13
- If you're using Rails 5.2, use the `5.2.x` versions of this gem.
14
+ If you're using Rails 7.0, use the `7.0.x` versions of this gem.
14
15
 
15
- If you're using Rails 6.0, use the `6.0.x` versions of this gem.
16
+ If you're using Rails 7.1, use the `7.1.x` versions of this gem.
16
17
 
17
- If you're using Rails 7.0, use the `7.0.x` versions of this gem.
18
+ If you're using Rails 7.2, use the `7.2.x` versions of this gem.
19
+ The minimal CockroachDB version required is 23.1.12 for this version.
18
20
 
19
21
  In `database.yml`, use the following adapter setting:
20
22
 
@@ -14,8 +14,8 @@ Gem::Specification.new do |spec|
14
14
  spec.description = "Allows the use of CockroachDB as a backend for ActiveRecord and Rails apps."
15
15
  spec.homepage = "https://github.com/cockroachdb/activerecord-cockroachdb-adapter"
16
16
 
17
- spec.add_dependency "activerecord", "~> 7.1.0"
18
- spec.add_dependency "pg", "~> 1.2"
17
+ spec.add_dependency "activerecord", "~> 7.2.0"
18
+ spec.add_dependency "pg", "~> 1.5"
19
19
  spec.add_dependency "rgeo-activerecord", "~> 7.0.0"
20
20
 
21
21
  spec.add_development_dependency "benchmark-ips", "~> 2.9.1"
data/bin/console CHANGED
@@ -5,7 +5,7 @@ $:.unshift(File.expand_path("../lib", __dir__))
5
5
  # require "bundler/setup"
6
6
  # Bundler.require :development
7
7
 
8
- require "active_record"
8
+ require "activerecord-cockroachdb-adapter"
9
9
  # This allows playing with the rake task as well. Ex:
10
10
  #
11
11
  # ActiveRecord::Tasks::DatabaseTasks.
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  module RGeo
4
18
  module ActiveRecord
5
19
  ##
@@ -1,3 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
1
17
  module ActiveRecord
2
18
  module CockroachDB
3
19
  module AttributeMethodsMonkeyPatch
@@ -1,3 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
1
17
  module ActiveRecord
2
18
  module ConnectionAdapters
3
19
  module CockroachDB
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  module ActiveRecord
4
18
  module ConnectionAdapters
5
19
  module CockroachDB
@@ -1,3 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
1
17
  module ActiveRecord
2
18
  module ConnectionAdapters
3
19
  module CockroachDB
@@ -1,3 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
1
17
  require "active_record/base"
2
18
 
3
19
  module ActiveRecord
@@ -21,14 +37,14 @@ module ActiveRecord
21
37
  ActiveRecord.dump_schemas
22
38
  end
23
39
 
24
- conn = ActiveRecord::Base.connection
40
+ conn = ActiveRecord::Base.lease_connection
25
41
  begin
26
42
  old_search_path = conn.schema_search_path
27
43
  conn.schema_search_path = search_path
28
44
  File.open(filename, "w") do |file|
29
45
  # NOTE: There is no issue with the crdb_internal schema, it is ignored by SHOW CREATE.
30
46
  %w(SCHEMAS TYPES).each do |object_kind|
31
- ActiveRecord::Base.connection.execute("SHOW CREATE ALL #{object_kind}").each_row { file.puts _1 }
47
+ conn.execute("SHOW CREATE ALL #{object_kind}").each_row { file.puts _1 }
32
48
  end
33
49
 
34
50
  ignore_tables = ActiveRecord::SchemaDumper.ignore_tables.to_set
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  module ActiveRecord
4
18
  module ConnectionAdapters
5
19
  module CockroachDB
@@ -1,3 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
1
17
  # frozen-string-literal: true
2
18
 
3
19
  require "active_support/duration"
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  module ActiveRecord
4
18
  module ConnectionAdapters
5
19
  module CockroachDB
@@ -1,3 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
1
17
  module ActiveRecord
2
18
  module ConnectionAdapters
3
19
  module CockroachDB
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  # The PostgresSQL Adapter's ReferentialIntegrity module can disable and
4
18
  # re-enable foreign key constraints by disabling all table triggers. Since
5
19
  # triggers are not available in CockroachDB, we have to remove foreign keys and
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  module ActiveRecord
4
18
  module ConnectionAdapters
5
19
  module CockroachDB
@@ -15,4 +29,3 @@ module ActiveRecord
15
29
  end
16
30
  end
17
31
  end
18
-
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  module ActiveRecord
4
18
  module ConnectionAdapters
5
19
  module CockroachDB
@@ -16,4 +30,3 @@ module ActiveRecord
16
30
  end
17
31
  end
18
32
  end
19
-
@@ -1,3 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
1
17
  module ActiveRecord
2
18
  module ConnectionAdapters
3
19
  module CockroachDB
@@ -39,6 +55,84 @@ module ActiveRecord
39
55
  end
40
56
  end
41
57
 
58
+ # OVERRIDE: CockroachDB does not support deferrable constraints.
59
+ # See: https://go.crdb.dev/issue-v/31632/v23.1
60
+ def foreign_key_options(from_table, to_table, options)
61
+ options = super
62
+ options.delete(:deferrable) unless supports_deferrable_constraints?
63
+ options
64
+ end
65
+
66
+ # OVERRIDE: Added `unique_rowid` to the last line of the second query.
67
+ # This is a CockroachDB-specific function used for primary keys.
68
+ # Also make sure we don't consider `NOT VISIBLE` columns.
69
+ #
70
+ # Returns a table's primary key and belonging sequence.
71
+ def pk_and_sequence_for(table) # :nodoc:
72
+ # First try looking for a sequence with a dependency on the
73
+ # given table's primary key.
74
+ result = query(<<~SQL, "SCHEMA")[0]
75
+ SELECT attr.attname, nsp.nspname, seq.relname
76
+ FROM pg_class seq,
77
+ pg_attribute attr,
78
+ pg_depend dep,
79
+ pg_constraint cons,
80
+ pg_namespace nsp,
81
+ -- TODO: use the pg_catalog.pg_attribute(attishidden) column when
82
+ -- it is added instead of joining on crdb_internal.
83
+ -- See https://github.com/cockroachdb/cockroach/pull/126397
84
+ crdb_internal.table_columns tc
85
+ WHERE seq.oid = dep.objid
86
+ AND seq.relkind = 'S'
87
+ AND attr.attrelid = dep.refobjid
88
+ AND attr.attnum = dep.refobjsubid
89
+ AND attr.attrelid = cons.conrelid
90
+ AND attr.attnum = cons.conkey[1]
91
+ AND seq.relnamespace = nsp.oid
92
+ AND attr.attrelid = tc.descriptor_id
93
+ AND attr.attname = tc.column_name
94
+ AND tc.hidden = false
95
+ AND cons.contype = 'p'
96
+ AND dep.classid = 'pg_class'::regclass
97
+ AND dep.refobjid = #{quote(quote_table_name(table))}::regclass
98
+ SQL
99
+
100
+ if result.nil? || result.empty?
101
+ result = query(<<~SQL, "SCHEMA")[0]
102
+ SELECT attr.attname, nsp.nspname,
103
+ CASE
104
+ WHEN pg_get_expr(def.adbin, def.adrelid) !~* 'nextval' THEN NULL
105
+ WHEN split_part(pg_get_expr(def.adbin, def.adrelid), '''', 2) ~ '.' THEN
106
+ substr(split_part(pg_get_expr(def.adbin, def.adrelid), '''', 2),
107
+ strpos(split_part(pg_get_expr(def.adbin, def.adrelid), '''', 2), '.')+1)
108
+ ELSE split_part(pg_get_expr(def.adbin, def.adrelid), '''', 2)
109
+ END
110
+ FROM pg_class t
111
+ JOIN pg_attribute attr ON (t.oid = attrelid)
112
+ JOIN pg_attrdef def ON (adrelid = attrelid AND adnum = attnum)
113
+ JOIN pg_constraint cons ON (conrelid = adrelid AND adnum = conkey[1])
114
+ JOIN pg_namespace nsp ON (t.relnamespace = nsp.oid)
115
+ -- TODO: use the pg_catalog.pg_attribute(attishidden) column when
116
+ -- it is added instead of joining on crdb_internal.
117
+ -- See https://github.com/cockroachdb/cockroach/pull/126397
118
+ JOIN crdb_internal.table_columns tc ON (attr.attrelid = tc.descriptor_id AND attr.attname = tc.column_name)
119
+ WHERE t.oid = #{quote(quote_table_name(table))}::regclass
120
+ AND tc.hidden = false
121
+ AND cons.contype = 'p'
122
+ AND pg_get_expr(def.adbin, def.adrelid) ~* 'nextval|uuid_generate|gen_random_uuid|unique_rowid'
123
+ SQL
124
+ end
125
+
126
+ pk = result.shift
127
+ if result.last
128
+ [pk, PostgreSQL::Name.new(*result)]
129
+ else
130
+ [pk, nil]
131
+ end
132
+ rescue
133
+ nil
134
+ end
135
+
42
136
  # override
43
137
  # Modified version of the postgresql foreign_keys method.
44
138
  # Replaces t2.oid::regclass::text with t2.relname since this is
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  module ActiveRecord # :nodoc:
4
18
  module ConnectionAdapters # :nodoc:
5
19
  module CockroachDB # :nodoc:
@@ -1,3 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
1
17
  module ActiveRecord
2
18
  module ConnectionAdapters
3
19
  module CockroachDB
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  module ActiveRecord # :nodoc:
4
18
  module ConnectionAdapters # :nodoc:
5
19
  module CockroachDB # :nodoc:
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  module ActiveRecord
4
18
  module ConnectionAdapters
5
19
  module CockroachDB
@@ -1,3 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
1
17
  module ActiveRecord
2
18
  module Type
3
19
  module CRDBExt
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  require "rgeo/active_record"
4
18
 
5
19
  require_relative "../../arel/nodes/join_source_ext"
@@ -31,20 +45,6 @@ require_relative "../relation/query_methods_ext"
31
45
  # Defined in ./setup.rb
32
46
  ActiveRecord::ConnectionAdapters::CockroachDB.initial_setup
33
47
 
34
- module ActiveRecord
35
- # TODO: once in rails 7.2, remove this and replace with a `#register` call.
36
- # See: https://github.com/rails/rails/commit/22a26d7f74ea8f0d5f7c4169531ae38441cfd5e5#diff-2468c670eb10c24bd2823e42708489a336d6f21c6efc7e3c4a574166fa77bb22
37
- module ConnectionHandling
38
- def cockroachdb_adapter_class
39
- ConnectionAdapters::CockroachDBAdapter
40
- end
41
-
42
- def cockroachdb_connection(config)
43
- cockroachdb_adapter_class.new(config)
44
- end
45
- end
46
- end
47
-
48
48
  module ActiveRecord
49
49
  module ConnectionAdapters
50
50
  module CockroachDBConnectionPool
@@ -137,15 +137,23 @@ module ActiveRecord
137
137
  end
138
138
 
139
139
  def get_database_version
140
- major, minor, patch = query_value("SHOW crdb_version").match(/v(\d+).(\d+).(\d+)/)[1..].map(&:to_i)
141
- major * 100 * 100 + minor * 100 + patch
140
+ with_raw_connection do |conn|
141
+ conn.async_exec("SHOW crdb_version") do |result|
142
+ major, minor, patch = result
143
+ .getvalue(0, 0)
144
+ .match(/v(\d+).(\d+).(\d+)/)
145
+ .captures
146
+ .map(&:to_i)
147
+ major * 100 * 100 + minor * 100 + patch
148
+ end
149
+ end
142
150
  end
143
151
  undef :postgresql_version
144
152
  alias :cockroachdb_version :database_version
145
153
 
146
154
  def supports_datetime_with_precision?
147
155
  # https://github.com/cockroachdb/cockroach/pull/111400
148
- database_version >= 23_01_13
156
+ true
149
157
  end
150
158
 
151
159
  def supports_nulls_not_distinct?
@@ -162,7 +170,7 @@ module ActiveRecord
162
170
  end
163
171
 
164
172
  def supports_materialized_views?
165
- false
173
+ true
166
174
  end
167
175
 
168
176
  def supports_index_include?
@@ -201,50 +209,44 @@ module ActiveRecord
201
209
  end
202
210
 
203
211
  def supports_deferrable_constraints?
212
+ # https://go.crdb.dev/issue-v/31632/v23.1
204
213
  false
205
214
  end
206
215
 
207
- # NOTE: This commented bit of code allows to have access to crdb version,
208
- # which can be useful for feature detection. However, we currently don't
209
- # need, hence we avoid the extra queries.
210
- #
211
- # def initialize(connection, logger, conn_params, config)
212
- # super(connection, logger, conn_params, config)
213
-
214
- # # crdb_version is the version of the binary running on the node. We
215
- # # really want to use `SHOW CLUSTER SETTING version` to get the cluster
216
- # # version, but that is only available to admins. Instead, we can use
217
- # # crdb_internal.is_at_least_version, but that's only available in 22.1.
218
- # crdb_version_string = query_value("SHOW crdb_version")
219
- # if crdb_version_string.include? "v22.1"
220
- # version_num = query_value(<<~SQL, "VERSION")
221
- # SELECT
222
- # CASE
223
- # WHEN crdb_internal.is_at_least_version('22.2') THEN 2220
224
- # WHEN crdb_internal.is_at_least_version('22.1') THEN 2210
225
- # ELSE 2120
226
- # END;
227
- # SQL
228
- # end
229
- # @crdb_version = version_num.to_i
230
- # end
231
-
232
- def self.database_exists?(config)
233
- !!ActiveRecord::Base.cockroachdb_connection(config)
234
- rescue ActiveRecord::NoDatabaseError
235
- false
216
+ def check_version # :nodoc:
217
+ # https://www.cockroachlabs.com/docs/releases/release-support-policy
218
+ if database_version < 23_01_12 # < 23.1.12
219
+ raise "Your version of CockroachDB (#{database_version}) is too old. Active Record supports CockroachDB >= 23.1.12."
220
+ end
236
221
  end
237
222
 
238
- def initialize(...)
223
+ def configure_connection(...)
239
224
  super
240
225
 
241
226
  # This rescue flow appears in new_client, but it is needed here as well
242
227
  # since Cockroach will sometimes not raise until a query is made.
228
+ #
229
+ # See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/337#issuecomment-2328419453
230
+ #
231
+ # The error conditions used to differ from the ones in new_client, but
232
+ # the reasons why are no longer relevant. We keep this in sync with new_client
233
+ # even though some conditions might never be checked.
234
+ #
235
+ # See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/229
236
+ #
237
+ # We have to rescue `ActiveRecord::StatementInvalid` instead of `::PG::Error`
238
+ # here as the error has already been casted (in `#with_raw_connection` as
239
+ # of Rails 7.2.1).
243
240
  rescue ActiveRecord::StatementInvalid => error
244
- no_db_err_check1 = @connection_parameters && @connection_parameters[:dbname] && error.cause.message.include?(@connection_parameters[:dbname])
245
- no_db_err_check2 = @connection_parameters && @connection_parameters[:dbname] && error.cause.message.include?("pg_type")
246
- if no_db_err_check1 || no_db_err_check2
247
- raise ActiveRecord::NoDatabaseError
241
+ conn_params = @connection_parameters
242
+ if conn_params && conn_params[:dbname] == "postgres"
243
+ raise ActiveRecord::ConnectionNotEstablished, error.message
244
+ elsif conn_params && conn_params[:dbname] && error.cause.message.include?(conn_params[:dbname])
245
+ raise ActiveRecord::NoDatabaseError.db_error(conn_params[:dbname])
246
+ elsif conn_params && conn_params[:user] && error.cause.message.include?(conn_params[:user])
247
+ raise ActiveRecord::DatabaseConnectionError.username_error(conn_params[:user])
248
+ elsif conn_params && conn_params[:host] && error.cause.message.include?(conn_params[:host])
249
+ raise ActiveRecord::DatabaseConnectionError.hostname_error(conn_params[:host])
248
250
  else
249
251
  raise ActiveRecord::ConnectionNotEstablished, error.message
250
252
  end
@@ -292,7 +294,6 @@ module ActiveRecord
292
294
  precision = extract_precision(sql_type)
293
295
  scale = extract_scale(sql_type)
294
296
 
295
-
296
297
  # The type for the numeric depends on the width of the field,
297
298
  # so we'll do something special here.
298
299
  #
@@ -511,7 +512,7 @@ module ActiveRecord
511
512
  # so this modified query uses AS OF SYSTEM TIME '-10s' to read historical data.
512
513
  def add_pg_decoders
513
514
  if @config[:use_follower_reads_for_type_introspection]
514
- @default_timezone = nil
515
+ @mapped_default_timezone = nil
515
516
  @timestamp_decoder = nil
516
517
 
517
518
  coders_by_name = {
@@ -526,6 +527,7 @@ module ActiveRecord
526
527
  "timestamp" => PG::TextDecoder::TimestampUtc,
527
528
  "timestamptz" => PG::TextDecoder::TimestampWithTimeZone,
528
529
  }
530
+ coders_by_name["date"] = PG::TextDecoder::Date if decode_dates
529
531
 
530
532
  known_coder_types = coders_by_name.keys.map { |n| quote(n) }
531
533
  query = <<~SQL % known_coder_types.join(", ")
@@ -533,7 +535,6 @@ module ActiveRecord
533
535
  FROM pg_type as t AS OF SYSTEM TIME '-10s'
534
536
  WHERE t.typname IN (%s)
535
537
  SQL
536
-
537
538
  coders = execute_and_clear(query, "SCHEMA", [], allow_retry: true, materialize_transactions: false) do |result|
538
539
  result.filter_map { |row| construct_coder(row, coders_by_name[row["typname"]]) }
539
540
  end
@@ -1,3 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
1
17
  require "active_record/migration"
2
18
  require "active_record/migration/compatibility"
3
19
 
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  module ActiveRecord
4
18
  class Relation
5
19
  module QueryMethodsExt
@@ -1,3 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
1
17
  if defined?(Rails::Railtie)
2
18
  module ActiveRecord
3
19
  module ConnectionAdapters
@@ -9,3 +25,8 @@ if defined?(Rails::Railtie)
9
25
  end
10
26
  end
11
27
  end
28
+
29
+ require "active_record"
30
+ require "active_record/connection_adapters"
31
+
32
+ ActiveRecord::ConnectionAdapters.register "cockroachdb", "ActiveRecord::ConnectionAdapters::CockroachDBAdapter", "active_record/connection_adapters/cockroachdb_adapter"
@@ -1,3 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
1
17
  module Arel
2
18
  module Nodes
3
19
  module JoinSourceExt
data/lib/version.rb CHANGED
@@ -1,5 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Copyright 2024 The Cockroach Authors.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
3
17
  module ActiveRecord
4
- COCKROACH_DB_ADAPTER_VERSION = "7.1.1"
18
+ COCKROACH_DB_ADAPTER_VERSION = "7.2.0"
5
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-cockroachdb-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.1
4
+ version: 7.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cockroach Labs
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-04 00:00:00.000000000 Z
11
+ date: 2024-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 7.1.0
19
+ version: 7.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 7.1.0
26
+ version: 7.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pg
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.2'
33
+ version: '1.5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.2'
40
+ version: '1.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rgeo-activerecord
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -79,7 +79,6 @@ files:
79
79
  - ".github/workflows/docker.yml"
80
80
  - ".gitignore"
81
81
  - ".gitmodules"
82
- - ".ruby-version"
83
82
  - CHANGELOG.md
84
83
  - CONTRIBUTING.md
85
84
  - Gemfile
@@ -128,7 +127,7 @@ licenses:
128
127
  - Apache-2.0
129
128
  metadata:
130
129
  allowed_push_host: https://rubygems.org
131
- post_install_message:
130
+ post_install_message:
132
131
  rdoc_options: []
133
132
  require_paths:
134
133
  - lib
@@ -143,8 +142,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
142
  - !ruby/object:Gem::Version
144
143
  version: '0'
145
144
  requirements: []
146
- rubygems_version: 3.4.9
147
- signing_key:
145
+ rubygems_version: 3.0.3.1
146
+ signing_key:
148
147
  specification_version: 4
149
148
  summary: CockroachDB adapter for ActiveRecord.
150
149
  test_files: []
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 3.2.3