activerecord-cockroachdb-adapter 6.1.11 → 7.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29c3318f817a9fd47781d39fe3c9ae0271341a3c6d19398e4f284de85417c024
4
- data.tar.gz: ceaef29be16168e8440a8beacae0b1c846d29093ea348c993d8ec25bebd43584
3
+ metadata.gz: c8f39021d1353c56c2830adac978ec3336f993bdb46e670f4c975be8d2c307c5
4
+ data.tar.gz: 8ea587bc12a5e5bc806901d28c7e67e9f63a0c2f5dfc769f2370ab4dd3f20c65
5
5
  SHA512:
6
- metadata.gz: 67952a7628ffc8031dc13d7ad9590a11998f254445f490f4cfa21ab23135d6a7882ed3e9eb36514da9e6d6f91a4cbc0b2ac1a3a4ee61835f7e50b558bdbe7d9f
7
- data.tar.gz: ef9ffcd4772e1c2593660c3e8ce55d2c30baaf32601ca945dcaa50cd668d30c197020bd5dc9cbf0ef5f55b0ec2145c89e3aebbc1f64f87cfbf5c295c3149a45b
6
+ metadata.gz: 6c7fca690e7203047ffeac709b9a62165c96f3ccb7ec26f3fe412daffc979f62ec392117912e15af15865aacf9f2b09bf2ff4d2efc155ee1f3dcbef1b2a213bb
7
+ data.tar.gz: 55cf42b3a055eabbec2045dac6650d50a96a085794dc2ef6bbb08efb44182daff7664720292f720099c3b08239edafbe1ae668779aa975426d9d8905fe98620b
data/CHANGELOG.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Changelog
2
2
 
3
- ## 6.1.11 - 2024-06-24
3
+ ## 7.0.0 - 2022-06-02
4
4
 
5
- - Add support for sql dump in rake tasks.
5
+ - Add support for Active Record 7.0.3
6
6
 
7
7
  ## 6.1.10 - 2022-05-06
8
8
 
data/Gemfile CHANGED
@@ -54,10 +54,12 @@ end
54
54
 
55
55
  group :development do
56
56
  gem "byebug"
57
- gem "minitest-excludes"
57
+ gem "minitest-excludes", "~> 2.0.1"
58
58
 
59
59
  # Gems used by the ActiveRecord test suite
60
- gem "bcrypt"
61
- gem "mocha"
62
- gem "sqlite3"
60
+ gem "bcrypt", "~> 3.1.18"
61
+ gem "mocha", "~> 1.14.0"
62
+ gem "sqlite3", "~> 1.4.4"
63
+
64
+ gem "minitest", "~> 5.15.0"
63
65
  end
data/README.md CHANGED
@@ -1,19 +1,21 @@
1
1
  # ActiveRecord CockroachDB Adapter
2
2
 
3
- CockroachDB adapter for ActiveRecord 5 and 6. This is a lightweight extension of the PostgreSQL adapter that establishes compatibility with [CockroachDB](https://github.com/cockroachdb/cockroach).
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).
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', '~> 6.1.0'
10
+ gem 'activerecord-cockroachdb-adapter', '~> 7.0.0'
11
11
  ```
12
12
 
13
13
  If you're using Rails 5.2, use the `5.2.x` versions of this gem.
14
14
 
15
15
  If you're using Rails 6.0, use the `6.0.x` versions of this gem.
16
16
 
17
+ If you're using Rails 7.0, use the `7.0.x` versions of this gem.
18
+
17
19
  In `database.yml`, use the following adapter setting:
18
20
 
19
21
  ```
@@ -17,10 +17,12 @@ Gem::Specification.new do |spec|
17
17
  spec.description = "Allows the use of CockroachDB as a backend for ActiveRecord and Rails apps."
18
18
  spec.homepage = "https://github.com/cockroachdb/activerecord-cockroachdb-adapter"
19
19
 
20
- spec.add_dependency "activerecord", "~> 6.1"
20
+ spec.add_dependency "activerecord", "~> 7.0.3"
21
21
  spec.add_dependency "pg", "~> 1.2"
22
22
  spec.add_dependency "rgeo-activerecord", "~> 7.0.0"
23
23
 
24
+ spec.add_development_dependency "benchmark-ips", "~> 2.9.1"
25
+
24
26
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
25
27
  # to allow pushing to a single host or delete this section to allow pushing to any host.
26
28
  if spec.respond_to?(:metadata)
@@ -3,7 +3,7 @@
3
3
  set -euox pipefail
4
4
 
5
5
  # Download CockroachDB
6
- VERSION=v21.2.5
6
+ VERSION=v22.1.0
7
7
  wget -qO- https://binaries.cockroachdb.com/cockroach-$VERSION.linux-amd64.tgz | tar xvz
8
8
  readonly COCKROACH=./cockroach-$VERSION.linux-amd64/cockroach
9
9
 
@@ -35,6 +35,8 @@ run_cockroach() {
35
35
  cockroach sql --insecure -e 'CREATE DATABASE activerecord_unittest2;'
36
36
  cockroach sql --insecure -e 'SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;'
37
37
  cockroach sql --insecure -e 'SET CLUSTER SETTING sql.stats.histogram_collection.enabled = false;'
38
+ cockroach sql --insecure -e "SET CLUSTER SETTING jobs.retention_time = '180s';"
39
+ cockroach sql --insecure -e "SET CLUSTER SETTING sql.defaults.experimental_alter_column_type.enabled = 'true'"
38
40
 
39
41
  cockroach sql --insecure -e "ALTER RANGE default CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;"
40
42
  cockroach sql --insecure -e "ALTER TABLE system.public.jobs CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30;"
@@ -46,21 +48,14 @@ run_cockroach() {
46
48
  cockroach sql --insecure -e "SET CLUSTER SETTING kv.raft_log.disable_synchronization_unsafe = 'true'"
47
49
  cockroach sql --insecure -e "SET CLUSTER SETTING jobs.registry.interval.cancel = '180s';"
48
50
  cockroach sql --insecure -e "SET CLUSTER SETTING jobs.registry.interval.gc = '30s';"
49
- cockroach sql --insecure -e "SET CLUSTER SETTING jobs.retention_time = '15s';"
50
- cockroach sql --insecure -e "SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;"
51
51
  cockroach sql --insecure -e "SET CLUSTER SETTING kv.range_split.by_load_merge_delay = '5s';"
52
52
 
53
- # Enable when we test with v22.1.
54
- # cockroach sql --insecure -e "SET CLUSTER SETTING sql.catalog.unsafe_skip_system_config_trigger.enabled = true;"
55
-
56
53
  # Enable experimental features.
57
54
  cockroach sql --insecure -e "SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true';"
58
- cockroach sql --insecure -e "SET CLUSTER SETTING sql.defaults.datestyle.enabled = true"
59
- cockroach sql --insecure -e "SET CLUSTER SETTING sql.defaults.intervalstyle.enabled = true;"
60
55
  }
61
56
 
62
57
  # Install ruby dependencies.
63
- gem install bundler:2.1.4
58
+ gem install bundler:2.3.14
64
59
  bundle install
65
60
 
66
61
  run_cockroach
@@ -12,7 +12,8 @@ module ActiveRecord
12
12
  {
13
13
  read_committed: "READ COMMITTED",
14
14
  repeatable_read: "REPEATABLE READ",
15
- serializable: "SERIALIZABLE"
15
+ serializable: "SERIALIZABLE",
16
+ read_uncommitted: "READ UNCOMMITTED"
16
17
  }
17
18
  end
18
19
 
@@ -5,43 +5,7 @@ module ActiveRecord
5
5
  module CockroachDB
6
6
  class DatabaseTasks < ActiveRecord::Tasks::PostgreSQLDatabaseTasks
7
7
  def structure_dump(filename, extra_flags=nil)
8
- if extra_flags
9
- raise "No flag supported yet, please raise an issue if needed. " \
10
- "https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/new"
11
- end
12
-
13
- case ActiveRecord::Base.dump_schemas
14
- when :all, String
15
- raise "Custom schemas are not supported in CockroachDB. " \
16
- "See https://github.com/cockroachdb/cockroach/issues/26443."
17
- when :schema_search_path
18
- if configuration_hash[:schema_search_path]
19
- raise "Custom schemas are not supported in CockroachDB. " \
20
- "See https://github.com/cockroachdb/cockroach/issues/26443."
21
- end
22
- end
23
-
24
- conn = ActiveRecord::Base.connection
25
- File.open(filename, "w") do |file|
26
- %w(SCHEMAS TYPES).each do |object_kind|
27
- ActiveRecord::Base.connection.execute("SHOW CREATE ALL #{object_kind}").each_row { file.puts _1 }
28
- end
29
-
30
- ignore_tables = ActiveRecord::SchemaDumper.ignore_tables.to_set
31
-
32
- conn.execute("SHOW CREATE ALL TABLES").each_row do |(sql)|
33
- if sql.start_with?("CREATE")
34
- table_name = sql[/CREATE TABLE (?:.*?\.)?\"?(.*?)[\" ]/, 1]
35
- next if ignore_tables.member?(table_name)
36
- elsif sql.start_with?("ALTER")
37
- table_name = sql[/ALTER TABLE (?:.*?\.)?\"?(.*?)[\" ]/, 1]
38
- ref_table_name = sql[/REFERENCES (?:.*?\.)?\"?(.*?)[\" ]/, 1]
39
- next if ignore_tables.member?(table_name) || ignore_tables.member?(ref_table_name)
40
- end
41
-
42
- file.puts sql
43
- end
44
- end
8
+ raise "db:structure:dump is unimplemented. See https://github.com/cockroachdb/activerecord-cockroachdb-adapter/issues/2"
45
9
  end
46
10
 
47
11
  def structure_load(filename, extra_flags=nil)
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ module CockroachDB
6
+ module OID
7
+ module DateTime
8
+ protected
9
+
10
+ # override
11
+ # Uses CockroachDBAdapter instead of PostgreSQLAdapter
12
+ def real_type_unless_aliased(real_type)
13
+ ActiveRecord::ConnectionAdapters::CockroachDBAdapter.datetime_type == real_type ? :datetime : real_type
14
+ end
15
+ end
16
+
17
+ PostgreSQL::OID::DateTime.prepend(DateTime)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -2,8 +2,6 @@ module ActiveRecord
2
2
  module ConnectionAdapters
3
3
  module CockroachDB
4
4
  module Quoting
5
- private
6
-
7
5
  # CockroachDB does not allow inserting integer values into string
8
6
  # columns, but ActiveRecord expects this to work. CockroachDB will
9
7
  # however allow inserting string values into integer columns. It will
@@ -19,7 +17,7 @@ module ActiveRecord
19
17
  # (https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary)
20
18
  # but when creating objects, using RGeo features is more convenient than
21
19
  # converting to WKB, so this does it automatically.
22
- def _quote(value)
20
+ def quote(value)
23
21
  if value.is_a?(Numeric)
24
22
  "'#{quote_string(value.to_s)}'"
25
23
  elsif RGeo::Feature::Geometry.check_type(value)
@@ -20,17 +20,31 @@ module ActiveRecord
20
20
 
21
21
  yield
22
22
 
23
- foreign_keys.each do |foreign_key|
24
- begin
25
- add_foreign_key(foreign_key.from_table, foreign_key.to_table, **foreign_key.options)
26
- rescue ActiveRecord::StatementInvalid => error
27
- if error.cause.class == PG::DuplicateObject
28
- # This error is safe to ignore because the yielded caller
29
- # already re-added the foreign key constraint.
30
- else
31
- raise error
23
+ # Prefixes and suffixes are added in add_foreign_key
24
+ # in AR7+ so we need to temporarily disable them here,
25
+ # otherwise prefixes/suffixes will be erroneously added.
26
+ old_prefix = ActiveRecord::Base.table_name_prefix
27
+ old_suffix = ActiveRecord::Base.table_name_suffix
28
+
29
+ ActiveRecord::Base.table_name_prefix = ""
30
+ ActiveRecord::Base.table_name_suffix = ""
31
+
32
+ begin
33
+ foreign_keys.each do |foreign_key|
34
+ begin
35
+ add_foreign_key(foreign_key.from_table, foreign_key.to_table, **foreign_key.options)
36
+ rescue ActiveRecord::StatementInvalid => error
37
+ if error.cause.class == PG::DuplicateObject
38
+ # This error is safe to ignore because the yielded caller
39
+ # already re-added the foreign key constraint.
40
+ else
41
+ raise error
42
+ end
32
43
  end
33
44
  end
45
+ ensure
46
+ ActiveRecord::Base.table_name_prefix = old_prefix
47
+ ActiveRecord::Base.table_name_suffix = old_suffix
34
48
  end
35
49
  end
36
50
  end
@@ -18,7 +18,9 @@ require "active_record/connection_adapters/cockroachdb/setup"
18
18
  require "active_record/connection_adapters/cockroachdb/oid/type_map_initializer"
19
19
  require "active_record/connection_adapters/cockroachdb/oid/spatial"
20
20
  require "active_record/connection_adapters/cockroachdb/oid/interval"
21
+ require "active_record/connection_adapters/cockroachdb/oid/date_time"
21
22
  require "active_record/connection_adapters/cockroachdb/arel_tosql"
23
+ require_relative "../migration/cockroachdb/compatibility"
22
24
  require_relative "../../version"
23
25
 
24
26
  # Run to ignore spatial tables that will break schemna dumper.
@@ -215,6 +217,10 @@ module ActiveRecord
215
217
  false
216
218
  end
217
219
 
220
+ def supports_deferrable_constraints?
221
+ false
222
+ end
223
+
218
224
  # This is hardcoded to 63 (as previously was in ActiveRecord 5.0) to aid in
219
225
  # migration from PostgreSQL to CockroachDB. In practice, this limitation
220
226
  # is arbitrary since CockroachDB supports index name lengths and table alias
@@ -293,8 +299,20 @@ module ActiveRecord
293
299
  false
294
300
  end
295
301
 
296
- private
302
+ # override
303
+ # The PostgreSQLAdapter uses syntax for an anonymous function
304
+ # (DO $$) that CockroachDB does not support.
305
+ #
306
+ # Given a name and an array of values, creates an enum type.
307
+ def create_enum(name, values)
308
+ sql_values = values.map { |s| "'#{s}'" }.join(", ")
309
+ query = <<~SQL
310
+ CREATE TYPE IF NOT EXISTS \"#{name}\" AS ENUM (#{sql_values});
311
+ SQL
312
+ exec_query(query)
313
+ end
297
314
 
315
+ class << self
298
316
  def initialize_type_map(m = type_map)
299
317
  %w(
300
318
  geography
@@ -341,10 +359,13 @@ module ActiveRecord
341
359
  # lookups on PG
342
360
  Type::DecimalWithoutScale.new(precision: precision)
343
361
  else
344
- OID::Decimal.new(precision: precision, scale: scale)
362
+ ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Decimal.new(precision: precision, scale: scale)
345
363
  end
346
364
  end
347
365
  end
366
+ end
367
+
368
+ private
348
369
 
349
370
  # Configures the encoding, verbosity, schema search path, and time zone of the connection.
350
371
  # This is called by #connect and should not be called manually.
@@ -366,7 +387,7 @@ module ActiveRecord
366
387
  # If using Active Record's time zone support configure the connection to return
367
388
  # TIMESTAMP WITH ZONE types in UTC.
368
389
  unless variables["timezone"]
369
- if ActiveRecord::Base.default_timezone == :utc
390
+ if ActiveRecord.default_timezone == :utc
370
391
  variables["timezone"] = "UTC"
371
392
  elsif @local_tz
372
393
  variables["timezone"] = @local_tz
@@ -0,0 +1,28 @@
1
+ require "active_record/migration"
2
+ require "active_record/migration/compatibility"
3
+
4
+ module ActiveRecord
5
+ class Migration
6
+ module CockroachDB
7
+ module Compatibility
8
+ module V7_0Patch
9
+ # Override. Use "CockroachDB" instead of "PostgreSQL"
10
+ def compatible_timestamp_type(type, connection)
11
+ if connection.adapter_name == "CockroachDB"
12
+ # For Rails <= 6.1, :datetime was aliased to :timestamp
13
+ # See: https://github.com/rails/rails/blob/v6.1.3.2/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L108
14
+ # From Rails 7 onwards, you can define what :datetime resolves to (the default is still :timestamp)
15
+ # See `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type`
16
+ type.to_sym == :datetime ? :timestamp : type
17
+ else
18
+ type
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ prepend_mod = ActiveRecord::Migration::CockroachDB::Compatibility::V7_0Patch
28
+ ActiveRecord::Migration::Compatibility::V6_1::PostgreSQLCompat.singleton_class.prepend(prepend_mod)
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecord
4
- COCKROACH_DB_ADAPTER_VERSION = "6.1.11"
4
+ COCKROACH_DB_ADAPTER_VERSION = "7.0.0"
5
5
  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: 6.1.11
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cockroach Labs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-24 00:00:00.000000000 Z
11
+ date: 2022-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '6.1'
19
+ version: 7.0.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '6.1'
26
+ version: 7.0.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pg
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 7.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: benchmark-ips
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.9.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.9.1
55
69
  description: Allows the use of CockroachDB as a backend for ActiveRecord and Rails
56
70
  apps.
57
71
  email:
@@ -82,6 +96,7 @@ files:
82
96
  - lib/active_record/connection_adapters/cockroachdb/column_methods.rb
83
97
  - lib/active_record/connection_adapters/cockroachdb/database_statements.rb
84
98
  - lib/active_record/connection_adapters/cockroachdb/database_tasks.rb
99
+ - lib/active_record/connection_adapters/cockroachdb/oid/date_time.rb
85
100
  - lib/active_record/connection_adapters/cockroachdb/oid/interval.rb
86
101
  - lib/active_record/connection_adapters/cockroachdb/oid/spatial.rb
87
102
  - lib/active_record/connection_adapters/cockroachdb/oid/type_map_initializer.rb
@@ -96,6 +111,7 @@ files:
96
111
  - lib/active_record/connection_adapters/cockroachdb/transaction_manager.rb
97
112
  - lib/active_record/connection_adapters/cockroachdb/type.rb
98
113
  - lib/active_record/connection_adapters/cockroachdb_adapter.rb
114
+ - lib/active_record/migration/cockroachdb/compatibility.rb
99
115
  - lib/activerecord-cockroachdb-adapter.rb
100
116
  - lib/version.rb
101
117
  homepage: https://github.com/cockroachdb/activerecord-cockroachdb-adapter
@@ -118,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
134
  - !ruby/object:Gem::Version
119
135
  version: '0'
120
136
  requirements: []
121
- rubygems_version: 3.4.9
137
+ rubygems_version: 3.1.6
122
138
  signing_key:
123
139
  specification_version: 4
124
140
  summary: CockroachDB adapter for ActiveRecord.