activerecord-cockroachdb-adapter 7.1.1 → 7.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +6 -3
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +7 -1
  5. data/CONTRIBUTING.md +39 -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 +7 -5
  11. data/bin/console_schemas/default.rb +2 -0
  12. data/lib/active_record/connection_adapters/cockroachdb/arel_tosql.rb +14 -0
  13. data/lib/active_record/connection_adapters/cockroachdb/attribute_methods.rb +16 -0
  14. data/lib/active_record/connection_adapters/cockroachdb/column.rb +16 -0
  15. data/lib/active_record/connection_adapters/cockroachdb/column_methods.rb +14 -0
  16. data/lib/active_record/connection_adapters/cockroachdb/database_statements.rb +27 -3
  17. data/lib/active_record/connection_adapters/cockroachdb/database_tasks.rb +18 -2
  18. data/lib/active_record/connection_adapters/cockroachdb/oid/date_time.rb +14 -0
  19. data/lib/active_record/connection_adapters/cockroachdb/oid/interval.rb +16 -0
  20. data/lib/active_record/connection_adapters/cockroachdb/oid/spatial.rb +14 -0
  21. data/lib/active_record/connection_adapters/cockroachdb/quoting.rb +16 -0
  22. data/lib/active_record/connection_adapters/cockroachdb/referential_integrity.rb +99 -9
  23. data/lib/active_record/connection_adapters/cockroachdb/schema_creation.rb +14 -1
  24. data/lib/active_record/connection_adapters/cockroachdb/schema_dumper.rb +14 -1
  25. data/lib/active_record/connection_adapters/cockroachdb/schema_statements.rb +125 -25
  26. data/lib/active_record/connection_adapters/cockroachdb/setup.rb +14 -0
  27. data/lib/active_record/connection_adapters/cockroachdb/spatial_column_info.rb +16 -0
  28. data/lib/active_record/connection_adapters/cockroachdb/table_definition.rb +14 -0
  29. data/lib/active_record/connection_adapters/cockroachdb/transaction_manager.rb +35 -0
  30. data/lib/active_record/connection_adapters/cockroachdb/type.rb +16 -0
  31. data/lib/active_record/connection_adapters/cockroachdb_adapter.rb +56 -55
  32. data/lib/active_record/migration/cockroachdb/compatibility.rb +16 -0
  33. data/lib/active_record/relation/query_methods_ext.rb +14 -0
  34. data/lib/activerecord-cockroachdb-adapter.rb +21 -0
  35. data/lib/arel/nodes/join_source_ext.rb +16 -0
  36. data/lib/version.rb +15 -1
  37. metadata +7 -8
  38. 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: c28f723090995949b4ca82645717432e09a8d71d9c5e714bea958432af87b0cc
4
+ data.tar.gz: 4855cb4a35acad52324f86833777b9b9f0f74d5a0fbade33fad8f0f5c5fb67fa
5
5
  SHA512:
6
- metadata.gz: 4ce6d2119bfc27192630c32ec488b3e7f533cc64963fc04035609122e5bdbc33e75b83766ca68e3eb73e2592b2fe0a1bae53a74389527762f790b16bda687da9
7
- data.tar.gz: 42e10ab1106e4ffc4df89bbbf98f8ddbd05b6bccf97b062a9445ebf874a8bfef9e628dce8b39c3287424a7094f70790457293a2766a849bd39ac0e20c7a684fe
6
+ metadata.gz: 9a75bb056071fc5ced4b3df285a74e42d2c4bbfd4ae34a21aa860702e88e5dae51ede402be1ff24664d1cee95f5d9c182a26106473a486f6b65591212a82a067
7
+ data.tar.gz: cb96f815a2d9970ca62006bded80d5d57b5ba6b8ce43be5dae0bfe0d9d610cbe5394d7f321c5605df9bc806fd87fb26105a97c448ba58dd1486528bc3409282f
@@ -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.4]
45
45
  name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }})
46
46
  steps:
47
47
  - name: Set Up Actions
@@ -88,4 +88,7 @@ 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
92
+ env:
93
+ TESTOPTS: "--profile=5"
94
+ RAILS_MINITEST_PLUGIN: "1" # Make sure that we use the minitest plugin for profiling.
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
@@ -1,6 +1,12 @@
1
1
  # Changelog
2
2
 
3
- ## Ongoing
3
+ ## 7.2.1 - 2025-03-26
4
+
5
+ - Fix transaction state on rollback ([#364](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/364))
6
+
7
+ ## 7.2.0 - 2024-09-24
8
+
9
+ - Add support for Rails 7.2 ([#337](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/337))
4
10
 
5
11
  ## 7.1.1 - 2024-05-01
6
12
 
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,40 @@ 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
+ - [ ] `def new_column_from_field(`
122
+ - [ ] `def column_definitions(`
123
+ - [ ] `def pk_and_sequence_for(`
124
+ - [ ] `def foreign_keys(` and `def all_foreign_keys(`
125
+ - [ ] ...
126
+ - Check for setups containing `drop_table` in the test suite.
127
+ Especially if you have tons of failure, this is likely the cause.
128
+ - In the same way, run `test/cases/fixtures_test.rb` first, and check
129
+ if this corrupted the test database for other tests.
130
+ - For both of the above, the diff of `schema.rb` can be useful:
131
+ ```bash
132
+ git diff v7.1.2..v7.2.1 -- activerecord/test/schema/schema.rb
133
+ ```
143
134
 
144
135
  ## Publishing to Rubygems
145
136
 
@@ -151,7 +142,6 @@ gem build ...
151
142
  gem publish <output file>
152
143
  ```
153
144
 
154
-
155
145
  # Notes
156
146
 
157
147
  When executing the test suite, each test file will reload fixtures. This
@@ -182,49 +172,8 @@ cleaned up, or skipped until passing.
182
172
  The purpose of these was to make the tests grep-able while going through
183
173
  all the failures.
184
174
 
185
-
186
175
  [cockroachdb/cockroach#20753]: https://github.com/cockroachdb/cockroach/issues/20753#issuecomment-352810425
187
176
 
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
177
  # Notes for the non-Rubyer
229
178
 
230
179
  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,27 +5,29 @@ $:.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.
12
12
  # structure_load(Post.connection_db_config, "awesome-file.sql")
13
13
  require "active_record/connection_adapters/cockroachdb/database_tasks"
14
14
 
15
+ DB_NAME = "ar_crdb_console"
16
+
15
17
  schema_kind = ENV.fetch("SCHEMA_KIND", ENV.fetch("SCHEMA", "default"))
16
18
 
17
- system("cockroach sql --insecure --host=localhost:26257 --execute='drop database if exists ar_crdb_console'",
19
+ system("cockroach sql --insecure --host=localhost:26257 --execute='drop database if exists #{DB_NAME}'",
18
20
  exception: true)
19
- system("cockroach sql --insecure --host=localhost:26257 --execute='create database ar_crdb_console'",
21
+ system("cockroach sql --insecure --host=localhost:26257 --execute='create database #{DB_NAME}'",
20
22
  exception: true)
21
23
 
22
24
  ActiveRecord::Base.establish_connection(
23
- #Alternative version: "cockroachdb://root@localhost:26257/ar_crdb_console"
25
+ #Alternative version: "cockroachdb://root@localhost:26257/#{DB_NAME}"
24
26
  adapter: "cockroachdb",
25
27
  host: "localhost",
26
28
  port: 26257,
27
29
  user: "root",
28
- database: "ar_crdb_console"
30
+ database: DB_NAME
29
31
  )
30
32
 
31
33
  load "#{__dir__}/console_schemas/#{schema_kind}.rb"
@@ -6,4 +6,6 @@ ActiveRecord::Schema.define do
6
6
  t.string :title
7
7
  t.text :body
8
8
  end
9
+
10
+ add_index("posts", ["title"], name: "index_posts_on_title", unique: true)
9
11
  end
@@ -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
@@ -8,9 +24,17 @@ module ActiveRecord
8
24
  table_deletes = tables_to_delete.map { |table| "DELETE FROM #{quote_table_name(table)}" }
9
25
  statements = table_deletes + fixture_inserts
10
26
 
11
- with_multi_statements do
12
- disable_referential_integrity do
13
- execute_batch(statements, "Fixtures Load")
27
+ begin # much faster without disabling referential integrity, worth trying.
28
+ with_multi_statements do
29
+ transaction(requires_new: true) do
30
+ execute_batch(statements, "Fixtures Load")
31
+ end
32
+ end
33
+ rescue
34
+ with_multi_statements do
35
+ disable_referential_integrity do
36
+ execute_batch(statements, "Fixtures Load")
37
+ end
14
38
  end
15
39
  end
16
40
  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/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