Skip to content

Commit 6c150f9

Browse files
committed
chore: bump activerecord
- Update supported versions of Cockroach and ActiveRecord - Fix some tests, updgrade codebase to adapt to rails 7.2 Closes #305. Closes #336
1 parent 8c1841b commit 6c150f9

File tree

80 files changed

+555
-527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+555
-527
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ 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]
44-
ruby: [head]
43+
crdb: [v23.2, v24.1, v24.2]
44+
ruby: ["3.3"]
4545
name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }})
4646
steps:
4747
- name: Set Up Actions
@@ -88,4 +88,4 @@ jobs:
8888
done
8989
cat ${{ github.workspace }}/setup.sql | cockroach sql --insecure
9090
- name: Test
91-
run: bundle exec rake test TESTOPTS='--profile=3'
91+
run: bundle exec rake test TESTOPTS='--profile=5'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
/docker_root/
1616
/ruby-build/
1717
/test/db/
18+
/.ruby-version

.ruby-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Ongoing
44

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+
59
## 7.1.1 - 2024-05-01
610

711
- Enable precision support ([#318](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/318))

CONTRIBUTING.md

Lines changed: 35 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
# Getting started
22

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-
163
## Setup and running tests
174

185
### CockroachDB
@@ -23,6 +10,7 @@ create two databases to be used by the ActiveRecord test suite:
2310
activerecord_unittest and activerecord_unittest2.
2411

2512
```sql
13+
-- See /setup.sql file for the whole setup.
2614
CREATE DATABASE activerecord_unittest;
2715
CREATE DATABASE activerecord_unittest2;
2816
```
@@ -36,30 +24,6 @@ Ruby version.
3624
tests similarly to TeamCity. The database is destroyed between each
3725
test file.)
3826

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-
6327
Using [bundler](http://bundler.io/), install the dependencies of Rails.
6428

6529
```bash
@@ -87,9 +51,12 @@ TEST_FILES="test/cases/adapter_test.rb,test/cases/associations/left_outer_join_a
8751
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
8852

8953
```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
9155
```
9256

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+
9360
`test/config.yml` assumes CockroachDB will be running at localhost:26257 with a root user. Make changes to `test/config.yml` as needed.
9461

9562
### Run Tests from a Backup
@@ -121,7 +88,6 @@ master branch, with an alpha build of CockroachDB. it would be even
12188
better to be able to test multiple versions of the adapter, and do so
12289
against different versions of CockroachDB.
12390

124-
12591
## Adding feature support
12692

12793
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
13197
linking those issues back to this adapter so that part of the feature
13298
completing includes updating the adapter.
13399

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+
```
143130

144131
## Publishing to Rubygems
145132

@@ -151,7 +138,6 @@ gem build ...
151138
gem publish <output file>
152139
```
153140

154-
155141
# Notes
156142

157143
When executing the test suite, each test file will reload fixtures. This
@@ -182,49 +168,8 @@ cleaned up, or skipped until passing.
182168
The purpose of these was to make the tests grep-able while going through
183169
all the failures.
184170

185-
186171
[cockroachdb/cockroach#20753]: https://github.com/cockroachdb/cockroach/issues/20753#issuecomment-352810425
187172

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-
228173
# Notes for the non-Rubyer
229174

230175
rbenv is an environment manager that lets you manage and swap between

Gemfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ group :development, :test do
5050

5151
# Needed for the test suite
5252
gem "msgpack", ">= 1.7.0"
53+
gem "mutex_m", "~> 0.2.0"
5354

5455
gem "rake"
5556
gem "debug"
@@ -61,8 +62,8 @@ group :development, :test do
6162
gem "parser"
6263

6364
# Gems used by the ActiveRecord test suite
64-
gem "bcrypt", "~> 3.1.18"
65-
gem "sqlite3", "~> 1.4.4"
65+
gem "bcrypt", "~> 3.1"
66+
gem "sqlite3", "~> 1.4"
6667

67-
gem "minitest", "~> 5.15.0"
68+
gem "minitest", "~> 5.15"
6869
end

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
# ActiveRecord CockroachDB Adapter
22

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).
45

56
## Installation
67

78
Add this line to your project's Gemfile:
89

910
```ruby
10-
gem 'activerecord-cockroachdb-adapter', '~> 7.0.0'
11+
gem 'activerecord-cockroachdb-adapter', '~> 7.2.0'
1112
```
1213

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.
1415

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.
1617

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.
1820

1921
In `database.yml`, use the following adapter setting:
2022

activerecord-cockroachdb-adapter.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Gem::Specification.new do |spec|
1414
spec.description = "Allows the use of CockroachDB as a backend for ActiveRecord and Rails apps."
1515
spec.homepage = "https://github.com/cockroachdb/activerecord-cockroachdb-adapter"
1616

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"
1919
spec.add_dependency "rgeo-activerecord", "~> 7.0.0"
2020

2121
spec.add_development_dependency "benchmark-ips", "~> 2.9.1"

bin/console

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ $:.unshift(File.expand_path("../lib", __dir__))
55
# require "bundler/setup"
66
# Bundler.require :development
77

8-
require "active_record"
8+
require "activerecord-cockroachdb-adapter"
99
# This allows playing with the rake task as well. Ex:
1010
#
1111
# ActiveRecord::Tasks::DatabaseTasks.

lib/active_record/connection_adapters/cockroachdb/database_tasks.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ def structure_dump(filename, extra_flags=nil)
3737
ActiveRecord.dump_schemas
3838
end
3939

40-
conn = ActiveRecord::Base.connection
40+
conn = ActiveRecord::Base.lease_connection
4141
begin
4242
old_search_path = conn.schema_search_path
4343
conn.schema_search_path = search_path
4444
File.open(filename, "w") do |file|
4545
# NOTE: There is no issue with the crdb_internal schema, it is ignored by SHOW CREATE.
4646
%w(SCHEMAS TYPES).each do |object_kind|
47-
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 }
4848
end
4949

5050
ignore_tables = ActiveRecord::SchemaDumper.ignore_tables.to_set

0 commit comments

Comments
 (0)