activerecord-cockroachdb-adapter 7.1.0 → 7.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +22 -29
- data/.gitignore +1 -0
- data/CHANGELOG.md +11 -2
- data/CONTRIBUTING.md +35 -90
- data/Gemfile +8 -4
- data/LICENSE +1 -2
- data/README.md +7 -5
- data/activerecord-cockroachdb-adapter.gemspec +2 -2
- data/bin/console +2 -2
- data/bin/start-cockroachdb +5 -20
- data/lib/active_record/connection_adapters/cockroachdb/arel_tosql.rb +14 -0
- data/lib/active_record/connection_adapters/cockroachdb/attribute_methods.rb +16 -0
- data/lib/active_record/connection_adapters/cockroachdb/column.rb +16 -0
- data/lib/active_record/connection_adapters/cockroachdb/column_methods.rb +14 -0
- data/lib/active_record/connection_adapters/cockroachdb/database_statements.rb +16 -0
- data/lib/active_record/connection_adapters/cockroachdb/database_tasks.rb +20 -3
- data/lib/active_record/connection_adapters/cockroachdb/oid/date_time.rb +14 -0
- data/lib/active_record/connection_adapters/cockroachdb/oid/interval.rb +16 -0
- data/lib/active_record/connection_adapters/cockroachdb/oid/spatial.rb +14 -0
- data/lib/active_record/connection_adapters/cockroachdb/quoting.rb +16 -0
- data/lib/active_record/connection_adapters/cockroachdb/referential_integrity.rb +14 -0
- data/lib/active_record/connection_adapters/cockroachdb/schema_creation.rb +14 -1
- data/lib/active_record/connection_adapters/cockroachdb/schema_dumper.rb +14 -1
- data/lib/active_record/connection_adapters/cockroachdb/schema_statements.rb +102 -1
- data/lib/active_record/connection_adapters/cockroachdb/setup.rb +14 -0
- data/lib/active_record/connection_adapters/cockroachdb/spatial_column_info.rb +16 -0
- data/lib/active_record/connection_adapters/cockroachdb/table_definition.rb +14 -0
- data/lib/active_record/connection_adapters/cockroachdb/transaction_manager.rb +14 -0
- data/lib/active_record/connection_adapters/cockroachdb/type.rb +16 -0
- data/lib/active_record/connection_adapters/cockroachdb_adapter.rb +72 -126
- data/lib/active_record/migration/cockroachdb/compatibility.rb +16 -0
- data/lib/active_record/relation/query_methods_ext.rb +16 -3
- data/lib/activerecord-cockroachdb-adapter.rb +21 -0
- data/lib/arel/nodes/join_source_ext.rb +16 -0
- data/lib/version.rb +15 -1
- data/setup.sql +18 -0
- metadata +11 -12
- data/.ruby-version +0 -1
- data/lib/active_record/connection_adapters/cockroachdb/oid/type_map_initializer.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 496e736f6d7baf4f0acb18461a70d7686765262e3fd09f4a65ac49534582d871
|
4
|
+
data.tar.gz: 9bd072d1ac20b7f1099076fb5019c9cfbee305da4463de7f91ec493c8f6eebe3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '044899369534c133039634cc835ce3efd71500a527d9249b10ca34fb8cb343f4754e0c72c8bc0f560267348881fe5d8e7701921b270431dfde1a810f1c48efad'
|
7
|
+
data.tar.gz: 5c67f56709062e0982998ff59f49f9caa1b14bb630e81339d6183821add59bfaf731f2af5e416b724fc00d3f57e17d63138eabec63166288185d69284bd53891
|
data/.github/workflows/ci.yml
CHANGED
@@ -37,15 +37,17 @@ jobs:
|
|
37
37
|
test:
|
38
38
|
runs-on: ubuntu-latest
|
39
39
|
strategy:
|
40
|
+
fail-fast: false
|
40
41
|
matrix:
|
41
|
-
|
42
|
-
|
42
|
+
# https://www.cockroachlabs.com/docs/releases/release-support-policy
|
43
|
+
crdb: [v23.2, v24.1, v24.2]
|
44
|
+
ruby: ["3.3"]
|
43
45
|
name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }})
|
44
46
|
steps:
|
45
47
|
- name: Set Up Actions
|
46
48
|
uses: actions/checkout@v4
|
47
49
|
- name: Install GEOS
|
48
|
-
run: sudo apt-get install libgeos-dev
|
50
|
+
run: sudo apt-get install -yqq libgeos-dev
|
49
51
|
- name: Set Up Ruby
|
50
52
|
uses: ruby/setup-ruby@v1
|
51
53
|
with:
|
@@ -54,16 +56,28 @@ jobs:
|
|
54
56
|
- name: Install and Start Cockroachdb
|
55
57
|
run: |
|
56
58
|
# Download CockroachDB
|
57
|
-
|
59
|
+
readonly full_version=$(ruby -rnet/http -ruri -ryaml -e '
|
60
|
+
link = "https://raw.githubusercontent.com/cockroachdb/docs/main/src/current/_data/releases.yml"
|
61
|
+
puts YAML.safe_load(Net::HTTP.get(URI(link))).reverse.find {
|
62
|
+
_1["major_version"] == "${{ matrix.crdb }}" &&
|
63
|
+
_1["release_type"] == "Production" &&
|
64
|
+
!_1["cloud_only"] &&
|
65
|
+
!_1["withdrawn"] &&
|
66
|
+
!_1["release_name"].include?("-") # Pre-release
|
67
|
+
}["release_name"]
|
68
|
+
')
|
58
69
|
|
59
|
-
|
70
|
+
echo "Downloading $full_version..."
|
71
|
+
wget -qO- "https://binaries.cockroachdb.com/cockroach-$full_version.linux-amd64.tgz" | tar xvz
|
72
|
+
|
73
|
+
export PATH=./cockroach-$full_version.linux-amd64/:$PATH
|
60
74
|
readonly urlfile=cockroach-url
|
61
75
|
|
62
76
|
# Start a CockroachDB server and wait for it to become ready.
|
63
77
|
rm -f "$urlfile"
|
64
78
|
rm -rf cockroach-data
|
65
79
|
# Start CockroachDB.
|
66
|
-
cockroach start-single-node --max-sql-memory=25% --cache=25% --insecure --host=localhost --spatial-libs=./cockroach-$
|
80
|
+
cockroach start-single-node --max-sql-memory=25% --cache=25% --insecure --host=localhost --spatial-libs=./cockroach-$full_version.linux-amd64/lib --listening-url-file="$urlfile" >/dev/null 2>&1 &
|
67
81
|
# Ensure CockroachDB is stopped on script exit.
|
68
82
|
# Wait until CockroachDB has started.
|
69
83
|
for i in {0..3}; do
|
@@ -72,27 +86,6 @@ jobs:
|
|
72
86
|
echo "server not yet available; sleeping for $backoff seconds"
|
73
87
|
sleep $backoff
|
74
88
|
done
|
75
|
-
cockroach sql --insecure
|
76
|
-
CREATE DATABASE activerecord_unittest;
|
77
|
-
CREATE DATABASE activerecord_unittest2;
|
78
|
-
SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;
|
79
|
-
SET CLUSTER SETTING sql.stats.histogram_collection.enabled = false;
|
80
|
-
SET CLUSTER SETTING jobs.retention_time = '180s';
|
81
|
-
SET CLUSTER SETTING sql.defaults.experimental_alter_column_type.enabled = 'true';
|
82
|
-
|
83
|
-
ALTER RANGE default CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
|
84
|
-
ALTER TABLE system.public.jobs CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
|
85
|
-
ALTER RANGE meta CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
|
86
|
-
ALTER RANGE system CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
|
87
|
-
ALTER RANGE liveness CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;
|
88
|
-
|
89
|
-
SET CLUSTER SETTING kv.range_merge.queue_interval = '50ms';
|
90
|
-
SET CLUSTER SETTING kv.raft_log.disable_synchronization_unsafe = 'true';
|
91
|
-
SET CLUSTER SETTING jobs.registry.interval.cancel = '180s';
|
92
|
-
SET CLUSTER SETTING jobs.registry.interval.gc = '30s';
|
93
|
-
SET CLUSTER SETTING kv.range_split.by_load_merge_delay = '5s';
|
94
|
-
|
95
|
-
SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true';
|
96
|
-
"
|
89
|
+
cat ${{ github.workspace }}/setup.sql | cockroach sql --insecure
|
97
90
|
- name: Test
|
98
|
-
run: bundle exec rake test TESTOPTS='--profile=
|
91
|
+
run: bundle exec rake test TESTOPTS='--profile=5'
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,12 +2,21 @@
|
|
2
2
|
|
3
3
|
## Ongoing
|
4
4
|
|
5
|
-
|
6
|
-
|
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
|
+
|
9
|
+
## 7.1.1 - 2024-05-01
|
10
|
+
|
11
|
+
- Enable precision support ([#318](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/318))
|
12
|
+
- Support arbitrary max identifier length ([#317](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/317)).
|
13
|
+
- Fix `#schema_names` not to return `crdb_internal` ([#316](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/316))
|
7
14
|
|
8
15
|
## 7.1.0 - 2024-01-30
|
9
16
|
|
10
17
|
- Add support for Rails 7.1 ([#300](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/300)).
|
18
|
+
- Add support for [AOST](cockroachlabs.com/docs/stable/as-of-system-time) queries ([#284](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/284))
|
19
|
+
- Dump schema name in foreign keys ([#289](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/289))
|
11
20
|
|
12
21
|
## 7.0.3 - 2023-08-23
|
13
22
|
|
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
|
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
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
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,16 +50,20 @@ 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"
|
56
57
|
gem "minitest-excludes", "~> 2.0.1"
|
57
58
|
gem "minitest-github_action_reporter", github: "BuonOmo/minitest-github_action_reporter", require: "minitest/github_action_reporter_plugin"
|
59
|
+
gem "ostruct", "~> 0.6"
|
60
|
+
|
61
|
+
# Gems used for tests meta-programming.
|
62
|
+
gem "parser"
|
58
63
|
|
59
64
|
# Gems used by the ActiveRecord test suite
|
60
|
-
gem "bcrypt", "~> 3.1
|
61
|
-
gem "
|
62
|
-
gem "sqlite3", "~> 1.4.4"
|
65
|
+
gem "bcrypt", "~> 3.1"
|
66
|
+
gem "sqlite3", "~> 1.4"
|
63
67
|
|
64
|
-
gem "minitest", "~> 5.15
|
68
|
+
gem "minitest", "~> 5.15"
|
65
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
|
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.
|
11
|
+
gem 'activerecord-cockroachdb-adapter', '~> 7.2.0'
|
11
12
|
```
|
12
13
|
|
13
|
-
If you're using Rails
|
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
|
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.
|
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.
|
18
|
-
spec.add_dependency "pg", "~> 1.
|
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,14 +5,14 @@ $:.unshift(File.expand_path("../lib", __dir__))
|
|
5
5
|
# require "bundler/setup"
|
6
6
|
# Bundler.require :development
|
7
7
|
|
8
|
-
require "
|
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
|
-
schema_kind = ENV.fetch("SCHEMA_KIND", "default")
|
15
|
+
schema_kind = ENV.fetch("SCHEMA_KIND", ENV.fetch("SCHEMA", "default"))
|
16
16
|
|
17
17
|
system("cockroach sql --insecure --host=localhost:26257 --execute='drop database if exists ar_crdb_console'",
|
18
18
|
exception: true)
|
data/bin/start-cockroachdb
CHANGED
@@ -9,7 +9,7 @@ pid_file="$root_dir/tmp/cockroach.pid"
|
|
9
9
|
log_file="$root_dir/tmp/cockroachdb.log"
|
10
10
|
|
11
11
|
mkdir -p "$root_dir/tmp"
|
12
|
-
[[ -f "$pid_file" ]] && kill -9 $(cat "$pid_file")
|
12
|
+
[[ -f "$pid_file" ]] && kill -9 $(cat "$pid_file") || true
|
13
13
|
rm -f "$pid_file"
|
14
14
|
|
15
15
|
if ! (( ${+commands[cockroach]} )); then
|
@@ -18,7 +18,9 @@ See https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html'
|
|
18
18
|
fi
|
19
19
|
|
20
20
|
cockroach start-single-node \
|
21
|
-
--insecure --store=type=mem,size=0.25 --advertise-addr=localhost
|
21
|
+
--insecure --store=type=mem,size=0.25 --advertise-addr=localhost \
|
22
|
+
--spatial-libs="$(geos-config --includes)" \
|
23
|
+
--pid-file "$pid_file" \
|
22
24
|
&> "$log_file" &
|
23
25
|
|
24
26
|
until [[ -f "$pid_file" ]]; do
|
@@ -26,23 +28,6 @@ until [[ -f "$pid_file" ]]; do
|
|
26
28
|
done
|
27
29
|
|
28
30
|
|
29
|
-
cat
|
30
|
-
-- https://www.cockroachlabs.com/docs/stable/local-testing.html
|
31
|
-
SET CLUSTER SETTING kv.raft_log.disable_synchronization_unsafe = true;
|
32
|
-
SET CLUSTER SETTING kv.range_merge.queue_interval = '50ms';
|
33
|
-
SET CLUSTER SETTING jobs.registry.interval.gc = '30s';
|
34
|
-
SET CLUSTER SETTING jobs.registry.interval.cancel = '180s';
|
35
|
-
SET CLUSTER SETTING jobs.retention_time = '15s';
|
36
|
-
SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;
|
37
|
-
SET CLUSTER SETTING kv.range_split.by_load_merge_delay = '5s';
|
38
|
-
ALTER RANGE default CONFIGURE ZONE USING "gc.ttlseconds" = 600;
|
39
|
-
ALTER DATABASE system CONFIGURE ZONE USING "gc.ttlseconds" = 600;
|
40
|
-
|
41
|
-
CREATE DATABASE activerecord_unittest;
|
42
|
-
CREATE DATABASE activerecord_unittest2;
|
43
|
-
|
44
|
-
SET CLUSTER SETTING sql.defaults.experimental_alter_column_type.enabled = 'true';
|
45
|
-
SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true';
|
46
|
-
SQL
|
31
|
+
cat "$root_dir/setup.sql" | cockroach sql --insecure --host=localhost:26257 > /dev/null
|
47
32
|
|
48
33
|
echo "CockroachDB started. PID: $(cat "$pid_file"). log: $log_file"
|
@@ -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,13 +37,14 @@ module ActiveRecord
|
|
21
37
|
ActiveRecord.dump_schemas
|
22
38
|
end
|
23
39
|
|
24
|
-
conn = ActiveRecord::Base.
|
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|
|
45
|
+
# NOTE: There is no issue with the crdb_internal schema, it is ignored by SHOW CREATE.
|
29
46
|
%w(SCHEMAS TYPES).each do |object_kind|
|
30
|
-
|
47
|
+
conn.execute("SHOW CREATE ALL #{object_kind}").each_row { file.puts _1 }
|
31
48
|
end
|
32
49
|
|
33
50
|
ignore_tables = ActiveRecord::SchemaDumper.ignore_tables.to_set
|
@@ -44,7 +61,7 @@ module ActiveRecord
|
|
44
61
|
|
45
62
|
file.puts sql
|
46
63
|
end
|
47
|
-
file.puts "SET
|
64
|
+
file.puts "SET search_path TO #{conn.schema_search_path};\n\n"
|
48
65
|
end
|
49
66
|
ensure
|
50
67
|
conn.schema_search_path = old_search_path
|
@@ -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
|