activerecord-cockroachdb-adapter 0.2.2 → 5.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c39398a79fef87dc0b0cde4cf0558ca1820005a5
4
- data.tar.gz: e18cf876bd4be4886a9429b55c5a82704c80d957
2
+ SHA256:
3
+ metadata.gz: b2292eb1fe9b5352ccb2a135ee1681b342403f086d38d5c78f354d97008097fe
4
+ data.tar.gz: 7b144a460690d0a6eab7d827eb1e297c67f94be4191d8c949f33d74e90050a88
5
5
  SHA512:
6
- metadata.gz: 60bcfd758fad44e6f3922896301f2c750d53b310879d525b8f70274838a1639a722614a2b9ad5e6f2db2e9e429b0c2b1f80adfd9d3c69473e00b4c6b8dad481c
7
- data.tar.gz: 3ef108048920f4708465cebda053a2681420bf77da6b0a7ab036ff6a3f1c42060620d6c53bb21a4df9384e6b4f0ee2f0b0a14fadfef57e884c25bc1fb86d21b9
6
+ metadata.gz: 6424288bb2dce9c2a530f3d2b0edd303c156fdd8dd85822756f9953ca7ebaff4cc32fed8cc233c580e570f561797d38ca741837edeccf5c4e95639b7e2dab816
7
+ data.tar.gz: 0d69e3fbf8e5809429608bbd292269affc21d88afcd7687a26443e6bbb55754bd623ba4d62da484a1ad4415f6633ba9f49eb57ba1e7d54ba632d3fc30e922eaa
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
File without changes
@@ -0,0 +1,220 @@
1
+ # Getting started
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
+ ## Setup and running tests
17
+
18
+ In CockroachDB, create two databases to be used by the ActiveRecord test suite:
19
+ activerecord_unittest and activerecord_unittest2.
20
+
21
+ ```sql
22
+ CREATE DATABASE activerecord_unittest;
23
+
24
+ CREATE DATABASE activerecord_unittest2;
25
+ ```
26
+
27
+ It is best to have a Ruby environment manager installed, such as
28
+ [rvm](https://rvm.io/), as Rails has varying Ruby version requirements.
29
+ If you are using rvm, you then install and use the required Ruby
30
+ version. The current tests use Rails 5.2.0 beta and Ruby >= 2.2.2.
31
+
32
+ (Alternatively, one can use `./docker.sh build/teamcity-test.sh` to run
33
+ tests similarily to TeamCity. The database is destroyed between each
34
+ test file.)
35
+
36
+
37
+ ```bash
38
+ rvm install 2.2.5
39
+ # This only makes Ruby 2.2.5 active for the length of the terminal session.
40
+ rvm use 2.2.5
41
+ ```
42
+
43
+ Using [bundler](http://bundler.io/), install the dependancies of Rails.
44
+
45
+ ```bash
46
+ bundle install
47
+ ```
48
+
49
+ Then, to run the full test suite with an active CockroachDB instance:
50
+
51
+ ```bash
52
+ bundle exec rake test
53
+ ```
54
+
55
+ To run specific ActiveRecord tests, set environemnt variable `TEST_FILES_AR`. For example, to run ActiveRecord tests `test/cases/associations_test.rb` and `test/cases/ar_schema_test.rb.rb`
56
+
57
+ ```bash
58
+ TEST_FILES_AR="test/cases/associations_test.rb,test/cases/ar_schema_test.rb" bundle exec rake test
59
+ ```
60
+
61
+ To run specific CockroachDB Adapter tests, set environemnt variable `TEST_FILES`. For example, to run CockroachDB Adpater tests `test/cases/adapter_test.rb` and `test/cases/associations/left_outer_join_association_test.rb`
62
+
63
+ ```bash
64
+ TEST_FILES="test/cases/adapter_test.rb,test/cases/associations/left_outer_join_association_test.rb" bundle exec rake test
65
+ ```
66
+
67
+ 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
68
+
69
+ ```bash
70
+ TEST_FILES="test/cases/adapter_test.rb" TESTOPTS=`-n=/test_indexes/` bundle exec rake test
71
+ ```
72
+
73
+ 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.
74
+
75
+ ```bash
76
+ RAILS_SOURCE="path/to/local_copy" bundle exec rake test
77
+ ```
78
+
79
+ `test/config.yml` assumes CockroachDB will be running at localhost:26257 with a root user. Make changes to `test/config.yml` as needed.
80
+
81
+ # Improvements
82
+
83
+
84
+ ## Support past Rails versions
85
+
86
+ Currently, only a beta version of Rails is tested. This means that the
87
+ adapter has been modified in to accomodate unreleased changes. In order
88
+ to run the tests for Rails 5.1 or 4.2, the test changes will need to be
89
+ cherry-picked back. Conflicts are mostly only expected for tests that
90
+ have not yet been added.
91
+
92
+ Sadly, this does mean that we will have to have multiple versions of the
93
+ driver for the multiple versions of Rails.
94
+
95
+ A proposal for the CockroachDB adapter versioning would be to follow
96
+ ActiveRecord minor versions. For example, if you use Rails 4.2.5, you
97
+ would specify the CockroachDB version `~> 4.2.0`.
98
+
99
+
100
+ ## Running CI automatically
101
+
102
+ Currently the fork is set up to run using TeamCity only on the current
103
+ master branch, with an alpha build of CockroachDB. it would be even
104
+ better to be able to test multiple versions of the adapter, and do so
105
+ against different versions of CockroachDB.
106
+
107
+
108
+ ## Adding feature support
109
+
110
+ As CockroachDB improves, so do the features that can be supported in
111
+ ActiveRecord. Many of them are gated by conditions the
112
+ CockroachDBAdapter has overrided. As these features are completed, these
113
+ gates should be toggled. Something that would help this process would be
114
+ linking those issues back to this adapter so that part of the feature
115
+ completing includes updating the adapter.
116
+
117
+
118
+ ## Execute only tests that run with a connection
119
+
120
+ I have not investigated if this is already possible, but I would assume
121
+ no.
122
+
123
+ A possible way to approach this would be to add a shim to cause any
124
+ tests that use it to fail, and grep the tests that pass and then skip
125
+ them.
126
+
127
+ ## Publishing to Rubygems
128
+
129
+ TODO: Expand on this. Jordan is likely the only person with publishing
130
+ credentials. I'm not sure if there is anything else other than:
131
+
132
+ ```
133
+ gem build ...
134
+ gem publish <output file>
135
+ ```
136
+
137
+
138
+ # Notes
139
+
140
+ When executing the test suite, each test file will reload fixtures. This
141
+ drops and creates about 200 tables (2 databases, 100 tables each).
142
+ Currently there are performance problems that rise from having lots of
143
+ table descriptors around, [cockroachdb/cockroach#20753]. At best, we can
144
+ run test files individually, clear out the CockroachDB data, and restart
145
+ the node to alleviate this.
146
+
147
+ Currently, annotations have been added to test files to indicate if it
148
+ is failing, and some brief details on why. Any annotated failures have
149
+ been skipped right now for further investigation. The pattern is the
150
+ following:
151
+
152
+ `# FILE(OK)` indicates that the file is currently passing, with no skips
153
+ required.
154
+
155
+ `# FILE(BAD)` indicates that there are failures that have been skipped.
156
+ These skips will look like `skip(reason) if current_adapter?(:CockroachDBAdapter)`.
157
+
158
+ `# FILE(BROKEN)` indicates that there are failures that have not been
159
+ skipped. This is often done if the entirety of a test file is
160
+ unsupported.
161
+
162
+ `# FILE(NOT DONE)` indicates files that have not yet been executed,
163
+ cleaned up, or skipped until passing.
164
+
165
+ The purpose of these was to make the tests grep-able while going through
166
+ all the failures.
167
+
168
+
169
+ [cockroachdb/cockroach#20753]: https://github.com/cockroachdb/cockroach/issues/20753#issuecomment-352810425
170
+
171
+
172
+ ## Tracked test failures
173
+
174
+ Some of the skipped failures are:
175
+
176
+ - `default:` key is not working for columns in table schema
177
+ definitions. This causes tests to fail due to unexpected data.
178
+
179
+ - `array:` key is not working for columns in table schema definitions.
180
+
181
+ - `"Salary is not appearing in list"` is being raised in a number of
182
+ places. Likely during fixture setup.
183
+
184
+ - `sum` function seems to result in a different type in ActiveRecord.
185
+ Instead of returning a Ruby `int`, it returns a Ruby `string`. It
186
+ appears that MySQL2 also does this. A suspected cause might be how
187
+ `Decimal` is handled if `sum` consumes integers and return a
188
+ decimal.
189
+
190
+ - Potentially fork the PostgreSQL::SchemaDumper to handle anything
191
+ specific to CockroachDB, like primary keys or bigints.
192
+
193
+ - You can call `@connection.create_table(..., id: :bigint)`, but this
194
+ will not changes things for CockroachDB (I think...), so it would be
195
+ not allowed. Even better, our adapter could interpret this and
196
+ generate the appropriate explicit pkey column. Not sure what string
197
+ pkeys look like...
198
+
199
+ - `string` types are introspected to `text` types.
200
+
201
+ - A user can do an update, delete, and insert on views.
202
+
203
+ - Postgres specific bit strings are not properly supported.
204
+
205
+ Grepping for `FIXME(joey)`, `TODO(joey)`, and `NOTE(joey)` will yeild
206
+ most of the touchpoints including test failures and temporary monkey
207
+ patches. Some monkey patches were made directly to Rails, which will
208
+ need to be cleaned up.
209
+
210
+
211
+ # Notes for the non-Rubyer
212
+
213
+ rvm is an environment manager that lets you manage and swap between
214
+ multiple verisons of Ruby and their dependancies.
215
+
216
+ bundle is dependancy manager that uses a projects `Gemfile` (and often
217
+ `<project>.gemspec`) to manage and load dependancies and their required
218
+ versions. When using projects commands are prefixed with
219
+ `bundle exec ...`. Bundle will ensure that all depenedncies are fetched
220
+ and used.
data/Gemfile CHANGED
@@ -1,4 +1,63 @@
1
+ require 'openssl'
1
2
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in activerecord-cockroachdb-adapter.gemspec
4
3
  gemspec
4
+
5
+ if ENV['RAILS_SOURCE']
6
+ gemspec path: ENV['RAILS_SOURCE']
7
+ else
8
+ def get_version_from_gemspec
9
+ gemspec = eval(File.read('activerecord-cockroachdb-adapter.gemspec'))
10
+
11
+ gem_version = gemspec.dependencies.
12
+ find { |dep| dep.name == 'activerecord' }.
13
+ requirement.
14
+ requirements.
15
+ first.
16
+ last
17
+
18
+ major, minor, tiny, pre = gem_version.segments
19
+
20
+ if pre
21
+ gem_version.to_s
22
+ else
23
+ find_latest_matching_version(major, minor)
24
+ end
25
+ end
26
+
27
+ def find_latest_matching_version(gemspec_major, gemspec_minor)
28
+ all_activerecord_versions.
29
+ reject { |version| version["prerelease"] }.
30
+ map { |version| version["number"].split(".").map(&:to_i) }.
31
+ find { |major, minor|
32
+ major == gemspec_major && (minor == gemspec_minor || gemspec_minor.nil?)
33
+ }.join(".")
34
+ end
35
+
36
+ def all_activerecord_versions
37
+ require 'net/http'
38
+ require 'yaml'
39
+
40
+ uri = URI.parse "https://rubygems.org/api/v1/versions/activerecord.yaml"
41
+ http = Net::HTTP.new(uri.host, uri.port)
42
+ http.use_ssl = true
43
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
44
+
45
+ YAML.load(
46
+ http.request(Net::HTTP::Get.new(uri.request_uri)).body
47
+ )
48
+ end
49
+
50
+ # Get Rails from source beacause the gem doesn't include tests
51
+ version = ENV['RAILS_VERSION'] || get_version_from_gemspec
52
+ gem 'rails', git: "https://github.com/rails/rails.git", tag: "v#{version}"
53
+ end
54
+
55
+ group :development do
56
+ gem "byebug"
57
+ gem "minitest-excludes"
58
+
59
+ # Gems used by the ActiveRecord test suite
60
+ gem "bcrypt"
61
+ gem "mocha"
62
+ gem "sqlite3"
63
+ end
data/README.md CHANGED
@@ -1,19 +1,29 @@
1
1
  # ActiveRecord CockroachDB Adapter
2
2
 
3
- CockroachDB adapter for ActiveRecord 5. This is a lightweight extension of the PostgreSQL adapter that establishes compatibility with [CockroachDB](https://github.com/cockroachdb/cockroach).
3
+ CockroachDB adapter for ActiveRecord 4 and 5. This is a lightweight extension of the PostgreSQL adapter that establishes compatibility with [CockroachDB](https://github.com/cockroachdb/cockroach).
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your project's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'activerecord-cockroachdb-adapter', '~> 0.2.2'
10
+ gem 'activerecord-cockroachdb-adapter', '~> 5.2.0'
11
11
  ```
12
12
 
13
+ If you're using Rails 4.x, use the `0.1.x` versions of this gem.
14
+
13
15
  In `database.yml`, use the following adapter setting:
14
16
 
15
17
  ```
16
18
  development:
17
19
  adapter: cockroachdb
18
20
  port: 26257
21
+ host: <hostname>
22
+ user: <username>
19
23
  ```
24
+
25
+
26
+ ## Modifying the adapter?
27
+
28
+ See [CONTRIBUTING.md](/CONTRIBUTING.md) for more details on setting up
29
+ the environment and making modifications.
data/Rakefile CHANGED
@@ -1,10 +1,22 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
+ require_relative 'test/support/paths_cockroachdb'
4
+ require_relative 'test/support/rake_helpers'
3
5
 
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList['test/**/*_test.rb']
6
+ task test: ["test:cockroachdb"]
7
+ task default: [:test]
8
+
9
+ namespace :test do
10
+ Rake::TestTask.new("cockroachdb") do |t|
11
+ t.libs = ARTest::CockroachDB.test_load_paths
12
+ t.test_files = test_files
13
+ t.warning = !!ENV["WARNING"]
14
+ t.verbose = false
15
+ end
16
+
17
+ task "cockroachdb:env" do
18
+ ENV["ARCONN"] = "cockroachdb"
19
+ end
8
20
  end
9
21
 
10
- task :default => :test
22
+ task 'test:cockroachdb' => 'test:cockroachdb:env'
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "activerecord-cockroachdb-adapter"
7
- spec.version = "0.2.2"
7
+ spec.version = "5.2.1"
8
8
  spec.licenses = ["Apache-2.0"]
9
9
  spec.authors = ["Cockroach Labs"]
10
10
  spec.email = ["cockroach-db@googlegroups.com"]
@@ -13,8 +13,8 @@ Gem::Specification.new do |spec|
13
13
  spec.description = "Allows the use of CockroachDB as a backend for ActiveRecord and Rails apps."
14
14
  spec.homepage = "https://github.com/cockroachdb/activerecord-cockroachdb-adapter"
15
15
 
16
- spec.add_dependency "activerecord", "~> 5.1", ">= 5.1.1"
17
- spec.add_dependency "pg", ">= 0.20", "< 0.22"
16
+ spec.add_dependency "activerecord", "~> 5.2"
17
+ spec.add_dependency "pg", ">= 0.20"
18
18
 
19
19
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
20
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -31,8 +31,4 @@ Gem::Specification.new do |spec|
31
31
  spec.bindir = "exe"
32
32
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
33
  spec.require_paths = ["lib"]
34
-
35
- spec.add_development_dependency "bundler", "~> 1.14"
36
- spec.add_development_dependency "rake", "~> 10.0"
37
- spec.add_development_dependency "minitest", "~> 5.0"
38
34
  end
@@ -0,0 +1,17 @@
1
+ # This Dockerfile extends the Examples-ORM testing image in order to
2
+ # install specific dependencies required for ActiveRecord tests.
3
+
4
+ FROM cockroachdb/example-orms-builder:20200413-1918
5
+
6
+ # Native dependencies for libxml-ruby and sqlite3.
7
+ RUN apt-get update -y && apt-get install -y \
8
+ libxslt-dev \
9
+ libxml2-dev \
10
+ libsqlite3-dev \
11
+ && rm -rf /var/lib/apt/lists/*
12
+
13
+ # Ruby testing dependencies.
14
+ RUN gem install bundle rake
15
+
16
+ # Add global Gem binaries to the path.
17
+ ENV PATH /usr/local/lib/ruby/gems/2.4.0::$PATH
@@ -0,0 +1,28 @@
1
+ default_connection: cockroachdb
2
+
3
+ with_manual_interventions: false
4
+
5
+ connections:
6
+ cockroachdb:
7
+ arunit:
8
+ database: activerecord_unittest
9
+ host: localhost
10
+ port: 26257
11
+ user: root
12
+ requiressl: disable
13
+ min_messages: warning
14
+ arunit_without_prepared_statements:
15
+ database: activerecord_unittest
16
+ host: localhost
17
+ port: 26257
18
+ user: root
19
+ requiressl: disable
20
+ min_messages: warning
21
+ prepared_statements: false
22
+ arunit2:
23
+ database: activerecord_unittest2
24
+ host: localhost
25
+ port: 26257
26
+ user: root
27
+ requiressl: disable
28
+ min_messages: warning
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -euo pipefail
4
+
5
+ readonly urlfile=cockroach-url
6
+
7
+ # Start a CockroachDB server, wait for it to become ready, and arrange for it to
8
+ # be force-killed when the script exits.
9
+ rm -f "$urlfile"
10
+ # Clean out a past CockroachDB instance. This happens if a build was
11
+ # canceled on an agent.
12
+ rm -rf $HOME/tmp/rails &
13
+ # Start CockroachDB.
14
+ cockroach quit --insecure || true
15
+ cockroach start --insecure --host=localhost --listening-url-file="$urlfile" --store=path=$HOME/tmp/rails &
16
+ trap "echo 'Exit routine: Killing CockroachDB.' && kill -9 $! &> /dev/null" EXIT
17
+ for i in {0..3}
18
+ do
19
+ [[ -f "$urlfile" ]] && break
20
+ backoff=$((2 ** i))
21
+ echo "server not yet available; sleeping for $backoff seconds"
22
+ sleep $backoff
23
+ done
24
+
25
+ # Target the Rails dependency file.
26
+ export BUNDLE_GEMFILE=$(pwd)/rails/Gemfile
27
+
28
+ # Run the tests.
29
+ cp build/config.teamcity.yml rails/activerecord/test/config.yml
30
+ echo "Rebuilding database"
31
+ (cd rails/activerecord && bundle exec rake db:cockroachdb:rebuild)
32
+ echo "Starting tests"
33
+ (cd rails/activerecord && bundle exec rake test:cockroachdb TESTFILES=$1)
34
+
35
+ # Attempt a clean shutdown for good measure. We'll force-kill in the atexit
36
+ # handler if this fails.
37
+ cockroach quit --insecure
38
+ trap - EXIT