activerecord-cockroachdb-adapter 7.0.2 → 7.1.0
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.
- checksums.yaml +4 -4
- data/.editorconfig +7 -0
- data/.github/workflows/ci.yml +98 -0
- data/CHANGELOG.md +16 -0
- data/CONTRIBUTING.md +6 -26
- data/Gemfile +44 -44
- data/README.md +1 -1
- data/Rakefile +5 -15
- data/activerecord-cockroachdb-adapter.gemspec +3 -6
- data/bin/console +27 -7
- data/bin/console_schemas/default.rb +9 -0
- data/bin/console_schemas/schemas.rb +23 -0
- data/bin/start-cockroachdb +48 -0
- data/build/Dockerfile +1 -1
- data/build/teamcity-test.sh +2 -7
- data/lib/active_record/connection_adapters/cockroachdb/arel_tosql.rb +8 -0
- data/lib/active_record/connection_adapters/cockroachdb/column.rb +3 -11
- data/lib/active_record/connection_adapters/cockroachdb/column_methods.rb +8 -0
- data/lib/active_record/connection_adapters/cockroachdb/database_statements.rb +0 -83
- data/lib/active_record/connection_adapters/cockroachdb/database_tasks.rb +86 -2
- data/lib/active_record/connection_adapters/cockroachdb/quoting.rb +6 -0
- data/lib/active_record/connection_adapters/cockroachdb/referential_integrity.rb +14 -10
- data/lib/active_record/connection_adapters/cockroachdb/schema_statements.rb +43 -15
- data/lib/active_record/connection_adapters/cockroachdb/type.rb +7 -3
- data/lib/active_record/connection_adapters/cockroachdb_adapter.rb +88 -148
- data/lib/active_record/relation/query_methods_ext.rb +127 -0
- data/lib/activerecord-cockroachdb-adapter.rb +1 -1
- data/lib/arel/nodes/join_source_ext.rb +28 -0
- data/lib/version.rb +1 -1
- metadata +12 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c3f85e82470685a2ece6851d557bcaf03f5a77ce309d76062c3960ca17d1606
|
4
|
+
data.tar.gz: b6ab7bfb9d29feebf217b70b11ccf2f73e6fb0853138cc27f4556f07b6c36dac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96fbb4c5a42c1ab3f2fe590f3c74012b883c818608c5b9d0525f30739f1d4d8733c95cfffd31a8a05350d6210d995f84d915727a494264d1cb1c217d10d200b1
|
7
|
+
data.tar.gz: 12ae86ab8f26eb074eabb60cd3f831eed44729d98f70bdc88d1c0d9c3d5cff5680ae7cf0a9643756395e6cfc1257cb7fc62ee5abab4c37c6f0fe45817fc619a0
|
data/.editorconfig
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# Inspired from:
|
2
|
+
# - https://github.com/cockroachdb/sqlalchemy-cockroachdb/blob/master/.github/workflows/ci.yml
|
3
|
+
# - https://github.com/rgeo/activerecord-postgis-adapter/blob/master/.github/workflows/tests.yml
|
4
|
+
name: Test
|
5
|
+
|
6
|
+
on:
|
7
|
+
push:
|
8
|
+
branches: [master]
|
9
|
+
# Triggers the workflow on pull request events.
|
10
|
+
pull_request:
|
11
|
+
types: [opened, reopened, synchronize]
|
12
|
+
|
13
|
+
# Allows you to run this workflow manually from the Actions tab
|
14
|
+
workflow_dispatch:
|
15
|
+
|
16
|
+
# This allows a subsequently queued workflow run to interrupt previous runs.
|
17
|
+
concurrency:
|
18
|
+
group: "${{ github.workflow }} @ ${{ github.ref }}"
|
19
|
+
cancel-in-progress: true
|
20
|
+
|
21
|
+
jobs:
|
22
|
+
# Since the name of the matrix job depends on the version, we define another job with a more stable name.
|
23
|
+
test_results:
|
24
|
+
if: ${{ always() }}
|
25
|
+
runs-on: ubuntu-latest
|
26
|
+
name: Test Results
|
27
|
+
needs: [test]
|
28
|
+
steps:
|
29
|
+
- run: |
|
30
|
+
result="${{ needs.test.result }}"
|
31
|
+
if [[ $result == "success" || $result == "skipped" ]]; then
|
32
|
+
exit 0
|
33
|
+
else
|
34
|
+
exit 1
|
35
|
+
fi
|
36
|
+
|
37
|
+
test:
|
38
|
+
runs-on: ubuntu-latest
|
39
|
+
strategy:
|
40
|
+
matrix:
|
41
|
+
crdb: [v23.1.11]
|
42
|
+
ruby: [head]
|
43
|
+
name: Test (crdb=${{ matrix.crdb }} ruby=${{ matrix.ruby }})
|
44
|
+
steps:
|
45
|
+
- name: Set Up Actions
|
46
|
+
uses: actions/checkout@v4
|
47
|
+
- name: Install GEOS
|
48
|
+
run: sudo apt-get install libgeos-dev
|
49
|
+
- name: Set Up Ruby
|
50
|
+
uses: ruby/setup-ruby@v1
|
51
|
+
with:
|
52
|
+
ruby-version: ${{ matrix.ruby }}
|
53
|
+
bundler-cache: true
|
54
|
+
- name: Install and Start Cockroachdb
|
55
|
+
run: |
|
56
|
+
# Download CockroachDB
|
57
|
+
wget -qO- https://binaries.cockroachdb.com/cockroach-${{ matrix.crdb }}.linux-amd64.tgz | tar xvz
|
58
|
+
|
59
|
+
export PATH=./cockroach-${{ matrix.crdb }}.linux-amd64/:$PATH
|
60
|
+
readonly urlfile=cockroach-url
|
61
|
+
|
62
|
+
# Start a CockroachDB server and wait for it to become ready.
|
63
|
+
rm -f "$urlfile"
|
64
|
+
rm -rf cockroach-data
|
65
|
+
# Start CockroachDB.
|
66
|
+
cockroach start-single-node --max-sql-memory=25% --cache=25% --insecure --host=localhost --spatial-libs=./cockroach-${{ matrix.crdb }}.linux-amd64/lib --listening-url-file="$urlfile" >/dev/null 2>&1 &
|
67
|
+
# Ensure CockroachDB is stopped on script exit.
|
68
|
+
# Wait until CockroachDB has started.
|
69
|
+
for i in {0..3}; do
|
70
|
+
[[ -f "$urlfile" ]] && break
|
71
|
+
backoff=$((2 ** i))
|
72
|
+
echo "server not yet available; sleeping for $backoff seconds"
|
73
|
+
sleep $backoff
|
74
|
+
done
|
75
|
+
cockroach sql --insecure -e "
|
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
|
+
"
|
97
|
+
- name: Test
|
98
|
+
run: bundle exec rake test TESTOPTS='--profile=3'
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Ongoing
|
4
|
+
|
5
|
+
- Add support for [AOST](cockroachlabs.com/docs/stable/as-of-system-time) queries ([#284](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/284))
|
6
|
+
- Dump schema name in foreign keys ([#289](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/289))
|
7
|
+
|
8
|
+
## 7.1.0 - 2024-01-30
|
9
|
+
|
10
|
+
- Add support for Rails 7.1 ([#300](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/300)).
|
11
|
+
|
12
|
+
## 7.0.3 - 2023-08-23
|
13
|
+
|
14
|
+
- Fix Multiple Database connections ([#283](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/)).
|
15
|
+
- Add support for sql load in rake tasks ([#275](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/)).
|
16
|
+
- Add support for sql dump in rake tasks ([#273](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/)).
|
17
|
+
- Add support for table optimize hints ([#266](https://github.com/cockroachdb/activerecord-cockroachdb-adapter/pull/)).
|
18
|
+
|
3
19
|
## 7.0.2 - 2023-05-23
|
4
20
|
|
5
21
|
- Fix default numbers test to expect the correct result after
|
data/CONTRIBUTING.md
CHANGED
@@ -15,12 +15,15 @@ override and monkey-patch functionality.
|
|
15
15
|
|
16
16
|
## Setup and running tests
|
17
17
|
|
18
|
-
|
18
|
+
### CockroachDB
|
19
|
+
|
20
|
+
First, You should setup a cockroachdb local instance. You can use the
|
21
|
+
`bin/start-cockroachdb` to help you with that task. Otherwise, once setup,
|
22
|
+
create two databases to be used by the ActiveRecord test suite:
|
19
23
|
activerecord_unittest and activerecord_unittest2.
|
20
24
|
|
21
25
|
```sql
|
22
26
|
CREATE DATABASE activerecord_unittest;
|
23
|
-
|
24
27
|
CREATE DATABASE activerecord_unittest2;
|
25
28
|
```
|
26
29
|
|
@@ -87,12 +90,6 @@ To run a specific test case, use minitest's `-n` option to run tests that match
|
|
87
90
|
TEST_FILES="test/cases/adapter_test.rb" TESTOPTS=`-n=/test_indexes/` bundle exec rake test
|
88
91
|
```
|
89
92
|
|
90
|
-
By default, tests will be run from the bundled version of Rails. To run against a local copy, set environemnt variable `RAILS_SOURCE`. Running against a local copy of Rails can be helpful when try to debug issues.
|
91
|
-
|
92
|
-
```bash
|
93
|
-
RAILS_SOURCE="path/to/local_copy" bundle exec rake test
|
94
|
-
```
|
95
|
-
|
96
93
|
`test/config.yml` assumes CockroachDB will be running at localhost:26257 with a root user. Make changes to `test/config.yml` as needed.
|
97
94
|
|
98
95
|
### Run Tests from a Backup
|
@@ -117,23 +114,6 @@ And the `activerecord_unittest` database will use the `RESTORE` command to load
|
|
117
114
|
|
118
115
|
# Improvements
|
119
116
|
|
120
|
-
|
121
|
-
## Support past Rails versions
|
122
|
-
|
123
|
-
Currently, only a beta version of Rails is tested. This means that the
|
124
|
-
adapter has been modified in to accommodate unreleased changes. In order
|
125
|
-
to run the tests for Rails 5.1 or 4.2, the test changes will need to be
|
126
|
-
cherry-picked back. Conflicts are mostly only expected for tests that
|
127
|
-
have not yet been added.
|
128
|
-
|
129
|
-
Sadly, this does mean that we will have to have multiple versions of the
|
130
|
-
driver for the multiple versions of Rails.
|
131
|
-
|
132
|
-
A proposal for the CockroachDB adapter versioning would be to follow
|
133
|
-
ActiveRecord minor versions. For example, if you use Rails 4.2.5, you
|
134
|
-
would specify the CockroachDB version `~> 4.2.0`.
|
135
|
-
|
136
|
-
|
137
117
|
## Running CI automatically
|
138
118
|
|
139
119
|
Currently the fork is set up to run using TeamCity only on the current
|
@@ -247,7 +227,7 @@ need to be cleaned up.
|
|
247
227
|
|
248
228
|
# Notes for the non-Rubyer
|
249
229
|
|
250
|
-
|
230
|
+
rbenv is an environment manager that lets you manage and swap between
|
251
231
|
multiple versions of Ruby and their dependencies.
|
252
232
|
|
253
233
|
bundle is dependency manager that uses a projects `Gemfile` (and often
|
data/Gemfile
CHANGED
@@ -1,60 +1,60 @@
|
|
1
|
-
|
2
|
-
source 'https://rubygems.org'
|
3
|
-
gemspec
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
6
|
-
gemspec path: ENV['RAILS_SOURCE']
|
7
|
-
else
|
8
|
-
def get_version_from_gemspec
|
9
|
-
gemspec = eval(File.read('activerecord-cockroachdb-adapter.gemspec'))
|
3
|
+
source "https://rubygems.org"
|
10
4
|
|
11
|
-
|
12
|
-
find { |dep| dep.name == 'activerecord' }.
|
13
|
-
requirement.
|
14
|
-
requirements.
|
15
|
-
first.
|
16
|
-
last
|
5
|
+
gemspec
|
17
6
|
|
18
|
-
major, minor, tiny, pre = gem_version.segments
|
19
7
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
8
|
+
module RailsTag
|
9
|
+
class << self
|
10
|
+
def call
|
11
|
+
req = gemspec_requirement
|
12
|
+
"v" + all_activerecord_versions.find { req.satisfied_by?(_1) }.version
|
13
|
+
rescue => e
|
14
|
+
warn "Unable to determine Rails version. Using last used. Error: #{e.message}"
|
15
|
+
lockfile = File.expand_path("Gemfile.lock", __dir__)
|
16
|
+
File.foreach(lockfile, chomp: true).find { _1[/tag: (.*)$/] }
|
17
|
+
Regexp.last_match(1)
|
24
18
|
end
|
25
|
-
end
|
26
19
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
find { |major, minor|
|
32
|
-
major == gemspec_major && (minor == gemspec_minor || gemspec_minor.nil?)
|
33
|
-
}.join(".")
|
34
|
-
end
|
20
|
+
def gemspec_requirement
|
21
|
+
File
|
22
|
+
.foreach(File.expand_path("activerecord-cockroachdb-adapter.gemspec", __dir__), chomp: true)
|
23
|
+
.find { _1[/add_dependency\s.activerecord.,\s.(.*)./] }
|
35
24
|
|
36
|
-
|
37
|
-
|
38
|
-
require 'yaml'
|
25
|
+
Gem::Requirement.new(Regexp.last_match(1))
|
26
|
+
end
|
39
27
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
28
|
+
def all_activerecord_versions
|
29
|
+
require 'net/http'
|
30
|
+
require 'yaml'
|
44
31
|
|
45
|
-
|
46
|
-
http
|
47
|
-
|
48
|
-
|
32
|
+
uri = URI.parse "https://rubygems.org/api/v1/versions/activerecord.yaml"
|
33
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
34
|
+
http.use_ssl = true
|
35
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
49
36
|
|
50
|
-
|
51
|
-
|
52
|
-
|
37
|
+
YAML.load(
|
38
|
+
http.request(Net::HTTP::Get.new(uri.request_uri)).body
|
39
|
+
).map { Gem::Version.new(_1["number"]) }
|
40
|
+
end
|
41
|
+
end
|
53
42
|
end
|
54
43
|
|
55
|
-
|
56
|
-
|
44
|
+
|
45
|
+
group :development, :test do
|
46
|
+
# We need to load the gem from git to have access to activerecord's test files.
|
47
|
+
# You can use `path: "some/local/rails"` if you want to test the gem against
|
48
|
+
# a specific rails codebase.
|
49
|
+
gem "rails", github: "rails/rails", tag: RailsTag.call
|
50
|
+
|
51
|
+
# Needed for the test suite
|
52
|
+
gem "msgpack", ">= 1.7.0"
|
53
|
+
|
54
|
+
gem "rake"
|
55
|
+
gem "debug"
|
57
56
|
gem "minitest-excludes", "~> 2.0.1"
|
57
|
+
gem "minitest-github_action_reporter", github: "BuonOmo/minitest-github_action_reporter", require: "minitest/github_action_reporter_plugin"
|
58
58
|
|
59
59
|
# Gems used by the ActiveRecord test suite
|
60
60
|
gem "bcrypt", "~> 3.1.18"
|
data/README.md
CHANGED
@@ -321,7 +321,7 @@ p modified_fac.parse_wkt(wkt)
|
|
321
321
|
#=> #<RGeo::Geographic::SphericalPolygonImpl>
|
322
322
|
```
|
323
323
|
|
324
|
-
Be careful when performing calculations on potentially invalid geometries, as the results might be nonsensical. For example, the area returned of an hourglass made of 2 equivalent triangles with a self-intersection in the middle is 0.
|
324
|
+
Be careful when performing calculations on potentially invalid geometries, as the results might be nonsensical. For example, the area returned of an hourglass made of 2 equivalent triangles with a self-intersection in the middle is 0.
|
325
325
|
|
326
326
|
Note that when using the `spherical_factory`, there is a chance that valid geometries will be interpreted as invalid due to floating point issues with small geometries.
|
327
327
|
|
data/Rakefile
CHANGED
@@ -4,14 +4,12 @@ require_relative 'test/support/paths_cockroachdb'
|
|
4
4
|
require_relative 'test/support/rake_helpers'
|
5
5
|
require_relative 'test/support/template_creator'
|
6
6
|
|
7
|
-
task test: ["test:cockroachdb"]
|
8
7
|
task default: [:test]
|
9
8
|
|
10
9
|
namespace :db do
|
11
10
|
task "create_test_template" do
|
12
11
|
ENV['DEBUG_COCKROACHDB_ADAPTER'] = "1"
|
13
12
|
ENV['COCKROACH_SKIP_LOAD_SCHEMA'] = "1"
|
14
|
-
ENV["ARCONN"] = "cockroachdb"
|
15
13
|
|
16
14
|
TemplateCreator.connect
|
17
15
|
require_relative 'test/cases/helper'
|
@@ -26,17 +24,9 @@ namespace :db do
|
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
t.verbose = false
|
35
|
-
end
|
36
|
-
|
37
|
-
task "cockroachdb:env" do
|
38
|
-
ENV["ARCONN"] = "cockroachdb"
|
39
|
-
end
|
27
|
+
Rake::TestTask.new do |t|
|
28
|
+
t.libs = ARTest::CockroachDB.test_load_paths
|
29
|
+
t.test_files = RakeHelpers.test_files
|
30
|
+
t.warning = !!ENV["WARNING"]
|
31
|
+
t.verbose = false
|
40
32
|
end
|
41
|
-
|
42
|
-
task 'test:cockroachdb' => 'test:cockroachdb:env'
|
@@ -1,9 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
|
6
|
-
require './lib/version.rb'
|
3
|
+
require_relative 'lib/version'
|
7
4
|
version = ActiveRecord::COCKROACH_DB_ADAPTER_VERSION
|
8
5
|
|
9
6
|
Gem::Specification.new do |spec|
|
@@ -17,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
17
14
|
spec.description = "Allows the use of CockroachDB as a backend for ActiveRecord and Rails apps."
|
18
15
|
spec.homepage = "https://github.com/cockroachdb/activerecord-cockroachdb-adapter"
|
19
16
|
|
20
|
-
spec.add_dependency "activerecord", "~> 7.0
|
17
|
+
spec.add_dependency "activerecord", "~> 7.1.0"
|
21
18
|
spec.add_dependency "pg", "~> 1.2"
|
22
19
|
spec.add_dependency "rgeo-activerecord", "~> 7.0.0"
|
23
20
|
|
data/bin/console
CHANGED
@@ -1,14 +1,34 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require "activerecord/cockroachdb"
|
3
|
+
$:.unshift(File.expand_path("../lib", __dir__))
|
5
4
|
|
6
|
-
#
|
7
|
-
#
|
5
|
+
# require "bundler/setup"
|
6
|
+
# Bundler.require :development
|
8
7
|
|
9
|
-
|
10
|
-
#
|
11
|
-
#
|
8
|
+
require "active_record"
|
9
|
+
# This allows playing with the rake task as well. Ex:
|
10
|
+
#
|
11
|
+
# ActiveRecord::Tasks::DatabaseTasks.
|
12
|
+
# structure_load(Post.connection_db_config, "awesome-file.sql")
|
13
|
+
require "active_record/connection_adapters/cockroachdb/database_tasks"
|
14
|
+
|
15
|
+
schema_kind = ENV.fetch("SCHEMA_KIND", "default")
|
16
|
+
|
17
|
+
system("cockroach sql --insecure --host=localhost:26257 --execute='drop database if exists ar_crdb_console'",
|
18
|
+
exception: true)
|
19
|
+
system("cockroach sql --insecure --host=localhost:26257 --execute='create database ar_crdb_console'",
|
20
|
+
exception: true)
|
21
|
+
|
22
|
+
ActiveRecord::Base.establish_connection(
|
23
|
+
#Alternative version: "cockroachdb://root@localhost:26257/ar_crdb_console"
|
24
|
+
adapter: "cockroachdb",
|
25
|
+
host: "localhost",
|
26
|
+
port: 26257,
|
27
|
+
user: "root",
|
28
|
+
database: "ar_crdb_console"
|
29
|
+
)
|
30
|
+
|
31
|
+
load "#{__dir__}/console_schemas/#{schema_kind}.rb"
|
12
32
|
|
13
33
|
require "irb"
|
14
34
|
IRB.start(__FILE__)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Post < ActiveRecord::Base
|
2
|
+
self.table_name = "bar.posts"
|
3
|
+
end
|
4
|
+
|
5
|
+
class Comment < ActiveRecord::Base
|
6
|
+
self.table_name = "foo.comments"
|
7
|
+
end
|
8
|
+
|
9
|
+
ActiveRecord::Schema.define do
|
10
|
+
create_schema("foo")
|
11
|
+
create_schema("bar")
|
12
|
+
create_table("bar.posts") do |t|
|
13
|
+
t.string :title
|
14
|
+
t.text :body
|
15
|
+
end
|
16
|
+
|
17
|
+
create_table("foo.comments") do |t|
|
18
|
+
t.integer :post_id
|
19
|
+
t.text :body
|
20
|
+
end
|
21
|
+
|
22
|
+
add_foreign_key "foo.comments", "bar.posts", column: "post_id"
|
23
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env zsh
|
2
|
+
|
3
|
+
set -eu
|
4
|
+
|
5
|
+
die() { echo "$0: $*" 1>&2 ; false; }
|
6
|
+
|
7
|
+
root_dir="$(dirname $(dirname "$0:A"))"
|
8
|
+
pid_file="$root_dir/tmp/cockroach.pid"
|
9
|
+
log_file="$root_dir/tmp/cockroachdb.log"
|
10
|
+
|
11
|
+
mkdir -p "$root_dir/tmp"
|
12
|
+
[[ -f "$pid_file" ]] && kill -9 $(cat "$pid_file")
|
13
|
+
rm -f "$pid_file"
|
14
|
+
|
15
|
+
if ! (( ${+commands[cockroach]} )); then
|
16
|
+
die 'the `cockroach` toolchain is not installed.
|
17
|
+
See https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html'
|
18
|
+
fi
|
19
|
+
|
20
|
+
cockroach start-single-node \
|
21
|
+
--insecure --store=type=mem,size=0.25 --advertise-addr=localhost --pid-file "$pid_file" \
|
22
|
+
&> "$log_file" &
|
23
|
+
|
24
|
+
until [[ -f "$pid_file" ]]; do
|
25
|
+
sleep 1
|
26
|
+
done
|
27
|
+
|
28
|
+
|
29
|
+
cat <<-SQL | cockroach sql --insecure --host=localhost:26257 > /dev/null
|
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
|
47
|
+
|
48
|
+
echo "CockroachDB started. PID: $(cat "$pid_file"). log: $log_file"
|
data/build/Dockerfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# This Dockerfile extends the Examples-ORM testing image in order to
|
2
2
|
# install specific dependencies required for ActiveRecord tests.
|
3
3
|
|
4
|
-
FROM
|
4
|
+
FROM us-east1-docker.pkg.dev/crl-ci-images/cockroach/example-orms-builder:20200413-1918
|
5
5
|
|
6
6
|
# Native dependencies for libxml-ruby and sqlite3.
|
7
7
|
RUN apt-get --allow-releaseinfo-change update -y && apt-get install -y \
|
data/build/teamcity-test.sh
CHANGED
@@ -70,12 +70,7 @@ run_cockroach
|
|
70
70
|
|
71
71
|
if ! (RUBYOPT="-W0" TESTOPTS="-v" bundle exec rake test); then
|
72
72
|
echo "Tests failed"
|
73
|
-
|
74
|
-
else
|
75
|
-
echo "Tests passed"
|
76
|
-
HAS_FAILED=0
|
73
|
+
exit 1
|
77
74
|
fi
|
78
75
|
|
79
|
-
|
80
|
-
exit 1
|
81
|
-
fi
|
76
|
+
echo "Tests passed"
|
@@ -22,6 +22,14 @@ module Arel # :nodoc:
|
|
22
22
|
module Visitors # :nodoc:
|
23
23
|
class CockroachDB < PostgreSQL # :nodoc:
|
24
24
|
include RGeo::ActiveRecord::SpatialToSql
|
25
|
+
|
26
|
+
def visit_Arel_Nodes_JoinSource(o, collector)
|
27
|
+
super
|
28
|
+
if o.aost
|
29
|
+
collector << " AS OF SYSTEM TIME '#{o.aost.iso8601}'"
|
30
|
+
end
|
31
|
+
collector
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|
27
35
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module ConnectionAdapters
|
3
3
|
module CockroachDB
|
4
|
-
|
4
|
+
class Column < PostgreSQL::Column
|
5
5
|
# most functions taken from activerecord-postgis-adapter spatial_column
|
6
6
|
# https://github.com/rgeo/activerecord-postgis-adapter/blob/master/lib/active_record/connection_adapters/postgis/spatial_column.rb
|
7
7
|
def initialize(name, default, sql_type_metadata = nil, null = true,
|
8
|
-
default_function = nil, collation: nil, comment: nil,
|
8
|
+
default_function = nil, collation: nil, comment: nil, identity: nil,
|
9
9
|
serial: nil, spatial: nil, generated: nil, hidden: nil)
|
10
10
|
@sql_type_metadata = sql_type_metadata
|
11
11
|
@geographic = !!(sql_type_metadata.sql_type =~ /geography\(/i)
|
@@ -30,7 +30,7 @@ module ActiveRecord
|
|
30
30
|
build_from_sql_type(sql_type_metadata.sql_type)
|
31
31
|
end
|
32
32
|
super(name, default, sql_type_metadata, null, default_function,
|
33
|
-
collation: collation, comment: comment, serial: serial, generated: generated)
|
33
|
+
collation: collation, comment: comment, serial: serial, generated: generated, identity: identity)
|
34
34
|
if spatial? && @srid
|
35
35
|
@limit = { srid: @srid, type: to_type_name(geometric_type) }
|
36
36
|
@limit[:has_z] = true if @has_z
|
@@ -53,10 +53,6 @@ module ActiveRecord
|
|
53
53
|
spatial? ? @limit : super
|
54
54
|
end
|
55
55
|
|
56
|
-
def virtual?
|
57
|
-
@generated.present?
|
58
|
-
end
|
59
|
-
|
60
56
|
def hidden?
|
61
57
|
@hidden
|
62
58
|
end
|
@@ -93,9 +89,5 @@ module ActiveRecord
|
|
93
89
|
end
|
94
90
|
end
|
95
91
|
end
|
96
|
-
|
97
|
-
class PostgreSQLColumn
|
98
|
-
prepend CockroachDB::PostgreSQLColumnMonkeyPatch
|
99
|
-
end
|
100
92
|
end
|
101
93
|
end
|
@@ -45,6 +45,14 @@ module ActiveRecord
|
|
45
45
|
def st_polygon(name, options = {})
|
46
46
|
column(name, :st_polygon, **options)
|
47
47
|
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def valid_column_definition_options
|
52
|
+
spatial = [:srid, :has_z, :has_m, :geographic, :spatial_type]
|
53
|
+
crdb = [:hidden]
|
54
|
+
super + spatial + crdb
|
55
|
+
end
|
48
56
|
end
|
49
57
|
end
|
50
58
|
|