activerecord-cockroachdb-adapter 7.0.3 → 7.1.1

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.
@@ -3,6 +3,23 @@
3
3
  module ActiveRecord
4
4
  class Relation
5
5
  module QueryMethodsExt
6
+ def aost!(time) # :nodoc:
7
+ unless time.nil? || time.is_a?(Time)
8
+ raise ArgumentError, "Unsupported argument type: #{time} (#{time.class})"
9
+ end
10
+
11
+ @aost = time
12
+ self
13
+ end
14
+
15
+ # Set system time for the current query. Using
16
+ # `.aost(nil)` resets.
17
+ #
18
+ # See cockroachlabs.com/docs/stable/as-of-system-time
19
+ def aost(time)
20
+ spawn.aost!(time)
21
+ end
22
+
6
23
  def from!(...) # :nodoc:
7
24
  @force_index = nil
8
25
  @index_hint = nil
@@ -59,8 +76,19 @@ module ActiveRecord
59
76
  self
60
77
  end
61
78
 
79
+ def show_create
80
+ quoted_table = connection.quote_table_name self.table_name
81
+ connection.select_one("show create table #{quoted_table}")["create_statement"]
82
+ end
83
+
62
84
  private
63
85
 
86
+ def build_arel(...)
87
+ arel = super
88
+ arel.aost(@aost) if @aost.present?
89
+ arel
90
+ end
91
+
64
92
  def from_clause_is_a_table_name?
65
93
  # if empty, we are just dealing with the current table.
66
94
  return true if from_clause.empty?
@@ -94,5 +122,5 @@ module ActiveRecord
94
122
  # as ancestor. That is how active_record is doing is as well.
95
123
  #
96
124
  # @see https://github.com/rails/rails/blob/914130a9f/activerecord/lib/active_record/querying.rb#L23
97
- Querying.delegate(:force_index, :index_hint, to: :all)
125
+ Querying.delegate(:force_index, :index_hint, :aost, :show_create, to: :all)
98
126
  end
@@ -0,0 +1,28 @@
1
+ module Arel
2
+ module Nodes
3
+ module JoinSourceExt
4
+ def initialize(...)
5
+ super
6
+ @aost = nil
7
+ end
8
+
9
+ def hash
10
+ [*super, aost].hash
11
+ end
12
+
13
+ def eql?(other)
14
+ super && aost == other.aost
15
+ end
16
+ alias_method :==, :eql?
17
+ end
18
+ JoinSource.attr_accessor :aost
19
+ JoinSource.prepend JoinSourceExt
20
+ end
21
+ module SelectManagerExt
22
+ def aost(time)
23
+ @ctx.source.aost = time
24
+ nil
25
+ end
26
+ end
27
+ SelectManager.prepend SelectManagerExt
28
+ end
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 = "7.0.3"
4
+ COCKROACH_DB_ADAPTER_VERSION = "7.1.1"
5
5
  end
data/setup.sql ADDED
@@ -0,0 +1,18 @@
1
+ -- https://www.cockroachlabs.com/docs/stable/local-testing.html
2
+ SET CLUSTER SETTING kv.range_merge.queue_interval = '50ms';
3
+ SET CLUSTER SETTING jobs.registry.interval.gc = '30s';
4
+ SET CLUSTER SETTING jobs.registry.interval.cancel = '180s';
5
+ SET CLUSTER SETTING jobs.retention_time = '15s';
6
+ SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;
7
+ SET CLUSTER SETTING kv.range_split.by_load_merge_delay = '5s';
8
+ ALTER RANGE default CONFIGURE ZONE USING "gc.ttlseconds" = 600;
9
+ ALTER DATABASE system CONFIGURE ZONE USING "gc.ttlseconds" = 600;
10
+
11
+ CREATE DATABASE activerecord_unittest;
12
+ CREATE DATABASE activerecord_unittest2;
13
+
14
+ SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;
15
+ SET CLUSTER SETTING sql.stats.histogram_collection.enabled = false;
16
+
17
+ SET CLUSTER SETTING sql.defaults.experimental_alter_column_type.enabled = 'true';
18
+ SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true';
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: 7.0.3
4
+ version: 7.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cockroach Labs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-23 00:00:00.000000000 Z
11
+ date: 2024-05-04 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: 7.0.3
19
+ version: 7.1.0
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: 7.0.3
26
+ version: 7.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pg
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -74,6 +74,7 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
+ - ".editorconfig"
77
78
  - ".github/workflows/ci.yml"
78
79
  - ".github/workflows/docker.yml"
79
80
  - ".gitignore"
@@ -87,6 +88,8 @@ files:
87
88
  - Rakefile
88
89
  - activerecord-cockroachdb-adapter.gemspec
89
90
  - bin/console
91
+ - bin/console_schemas/default.rb
92
+ - bin/console_schemas/schemas.rb
90
93
  - bin/setup
91
94
  - bin/start-cockroachdb
92
95
  - build/Dockerfile
@@ -103,7 +106,6 @@ files:
103
106
  - lib/active_record/connection_adapters/cockroachdb/oid/date_time.rb
104
107
  - lib/active_record/connection_adapters/cockroachdb/oid/interval.rb
105
108
  - lib/active_record/connection_adapters/cockroachdb/oid/spatial.rb
106
- - lib/active_record/connection_adapters/cockroachdb/oid/type_map_initializer.rb
107
109
  - lib/active_record/connection_adapters/cockroachdb/quoting.rb
108
110
  - lib/active_record/connection_adapters/cockroachdb/referential_integrity.rb
109
111
  - lib/active_record/connection_adapters/cockroachdb/schema_creation.rb
@@ -118,7 +120,9 @@ files:
118
120
  - lib/active_record/migration/cockroachdb/compatibility.rb
119
121
  - lib/active_record/relation/query_methods_ext.rb
120
122
  - lib/activerecord-cockroachdb-adapter.rb
123
+ - lib/arel/nodes/join_source_ext.rb
121
124
  - lib/version.rb
125
+ - setup.sql
122
126
  homepage: https://github.com/cockroachdb/activerecord-cockroachdb-adapter
123
127
  licenses:
124
128
  - Apache-2.0
@@ -1,26 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module CockroachDB
4
- module OID
5
- module TypeMapInitializer
6
- # override
7
- # Replaces the query with a faster version that doesn't rely on the
8
- # use of 'array_in(cstring,oid,integer)'::regprocedure.
9
- def query_conditions_for_initial_load
10
- known_type_names = @store.keys.map { |n| "'#{n}'" }
11
- known_type_types = %w('r' 'e' 'd')
12
- <<~SQL % [known_type_names.join(", "), known_type_types.join(", ")]
13
- WHERE
14
- t.typname IN (%s)
15
- OR t.typtype IN (%s)
16
- OR (t.typarray = 0 AND t.typcategory='A')
17
- OR t.typelem != 0
18
- SQL
19
- end
20
- end
21
-
22
- PostgreSQL::OID::TypeMapInitializer.prepend(TypeMapInitializer)
23
- end
24
- end
25
- end
26
- end