activerecord-cockroachdb-adapter 0.1.1 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/activerecord-cockroachdb-adapter.gemspec +3 -2
- data/lib/active_record/connection_adapters/cockroachdb_adapter.rb +50 -25
- metadata +17 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6fb41a73e2d9ae7c9fb88f2094d14dc7b018a94
|
4
|
+
data.tar.gz: 5fb0b0933595b1a631b3318941b4f47b79a5b854
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 255858d824d22098be889a190b25454222868ee021da95ae639bd75d8e131c27ecd62a71d5f0b414ebcf414ad621daef709b1a79dc75f64683c943ceb9cb8829
|
7
|
+
data.tar.gz: 6b5aff467669c95beeced14051c17361f01e14f042f6d54c4edd2e094d4cc6c3a73bb3a80918e0b27752873300c0367f4ef4e76bd5020fc379b45d90599084f0
|
data/README.md
CHANGED
@@ -1,19 +1,23 @@
|
|
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.
|
10
|
+
gem 'activerecord-cockroachdb-adapter', '~> 0.2.2'
|
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
|
```
|
@@ -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.1.
|
7
|
+
spec.version = "0.1.5"
|
8
8
|
spec.licenses = ["Apache-2.0"]
|
9
9
|
spec.authors = ["Cockroach Labs"]
|
10
10
|
spec.email = ["cockroach-db@googlegroups.com"]
|
@@ -13,7 +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", "~>
|
16
|
+
spec.add_dependency "activerecord", "~> 4.2"
|
17
|
+
spec.add_dependency "pg", "0.20"
|
17
18
|
|
18
19
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
20
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
@@ -12,12 +12,13 @@ module ActiveRecord
|
|
12
12
|
conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
|
13
13
|
conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
|
14
14
|
|
15
|
-
# Forward only valid config params to
|
16
|
-
valid_conn_param_keys =
|
15
|
+
# Forward only valid config params to PG::Connection.connect.
|
16
|
+
valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
|
17
17
|
conn_params.slice!(*valid_conn_param_keys)
|
18
18
|
|
19
|
-
# The postgres drivers don't allow the creation of an unconnected
|
20
|
-
# so just pass a nil connection object for the
|
19
|
+
# The postgres drivers don't allow the creation of an unconnected
|
20
|
+
# PG::Connection object, so just pass a nil connection object for the
|
21
|
+
# time being.
|
21
22
|
ConnectionAdapters::CockroachDBAdapter.new(nil, logger, conn_params, config)
|
22
23
|
end
|
23
24
|
end
|
@@ -25,6 +26,37 @@ end
|
|
25
26
|
|
26
27
|
class ActiveRecord::ConnectionAdapters::CockroachDBAdapter < ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
|
27
28
|
ADAPTER_NAME = "CockroachDB".freeze
|
29
|
+
|
30
|
+
# Note that in the migration from ActiveRecord 5.0 to 5.1, the
|
31
|
+
# `extract_schema_qualified_name` method was aliased in the PostgreSQLAdapter.
|
32
|
+
# To ensure backward compatibility with both <5.1 and 5.1, we rename it here
|
33
|
+
# to use the same original `Utils` module.
|
34
|
+
Utils = ActiveRecord::ConnectionAdapters::PostgreSQL::Utils
|
35
|
+
|
36
|
+
def supports_json?
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
40
|
+
def supports_ddl_transactions?
|
41
|
+
false
|
42
|
+
end
|
43
|
+
|
44
|
+
def supports_extensions?
|
45
|
+
false
|
46
|
+
end
|
47
|
+
|
48
|
+
def supports_ranges?
|
49
|
+
false
|
50
|
+
end
|
51
|
+
|
52
|
+
def supports_materialized_views?
|
53
|
+
false
|
54
|
+
end
|
55
|
+
|
56
|
+
def supports_pg_crypto_uuid?
|
57
|
+
false
|
58
|
+
end
|
59
|
+
|
28
60
|
def indexes(table_name, name = nil) # :nodoc:
|
29
61
|
# The PostgreSQL adapter uses a correlated subquery in the following query,
|
30
62
|
# which CockroachDB does not yet support. That portion of the query fetches
|
@@ -37,7 +69,7 @@ class ActiveRecord::ConnectionAdapters::CockroachDBAdapter < ActiveRecord::Conne
|
|
37
69
|
MSG
|
38
70
|
end
|
39
71
|
|
40
|
-
table = extract_schema_qualified_name(table_name.to_s)
|
72
|
+
table = Utils.extract_schema_qualified_name(table_name.to_s)
|
41
73
|
|
42
74
|
result = query(<<-SQL, "SCHEMA")
|
43
75
|
SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid), t.oid,
|
@@ -85,8 +117,7 @@ class ActiveRecord::ConnectionAdapters::CockroachDBAdapter < ActiveRecord::Conne
|
|
85
117
|
|
86
118
|
|
87
119
|
def primary_keys(table_name)
|
88
|
-
|
89
|
-
name = extract_schema_qualified_name(table_name.to_s)
|
120
|
+
name = Utils.extract_schema_qualified_name(table_name.to_s)
|
90
121
|
select_values(<<-SQL.strip_heredoc, "SCHEMA")
|
91
122
|
SELECT column_name
|
92
123
|
FROM information_schema.key_column_usage kcu
|
@@ -101,23 +132,17 @@ class ActiveRecord::ConnectionAdapters::CockroachDBAdapter < ActiveRecord::Conne
|
|
101
132
|
SQL
|
102
133
|
end
|
103
134
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
AND a.attnum > 0 AND NOT a.attisdropped
|
116
|
-
ORDER BY a.attnum
|
117
|
-
end_sql
|
118
|
-
end
|
119
|
-
|
120
|
-
private def extract_schema_qualified_name(*args)
|
121
|
-
ActiveRecord::ConnectionAdapters::PostgreSQL::Utils.extract_schema_qualified_name(*args)
|
135
|
+
# This is hardcoded to 63 (as previously was in ActiveRecord 5.0) to aid in
|
136
|
+
# migration from PostgreSQL to Cockroachdb. In practice, this limitation
|
137
|
+
# is arbitrary since CockroachDB supports index name lengths and table alias
|
138
|
+
# lengths far greater than this value. For the time being though, we match
|
139
|
+
# the original behavior for PostgreSQL to simplify migrations.
|
140
|
+
#
|
141
|
+
# Note that in the migration to ActiveRecord 5.1, this was changed in
|
142
|
+
# PostgreSQLAdapter to use `SHOW max_identifier_length` (which does not
|
143
|
+
# exist in CockroachDB). Therefore, we have to redefine this here.
|
144
|
+
def table_alias_length
|
145
|
+
63
|
122
146
|
end
|
147
|
+
alias index_name_length table_alias_length
|
123
148
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-cockroachdb-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cockroach Labs
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,20 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 5.0.1
|
19
|
+
version: '4.2'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
30
|
-
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pg
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.20'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
31
39
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
40
|
+
version: '0.20'
|
33
41
|
- !ruby/object:Gem::Dependency
|
34
42
|
name: bundler
|
35
43
|
requirement: !ruby/object:Gem::Requirement
|