Skip to content

Commit aaf39b5

Browse files
committed
Update to ActiveRecord 7 and crate_ruby 0.2
1 parent e875d7a commit aaf39b5

File tree

10 files changed

+41
-27
lines changed

10 files changed

+41
-27
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ tmp
2121
crate_test_server*
2222
*.log
2323
log/*
24+
crate-*.tar.gz
25+
parts/

activerecord-crate-adapter.gemspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ Gem::Specification.new do |spec|
4444
"source_code_uri" => "https://github.com/crate/activerecord-crate-adapter"
4545
}
4646

47-
spec.add_development_dependency "bundler", "~> 1.5"
47+
spec.add_development_dependency "bundler"
48+
spec.add_development_dependency "os"
4849
spec.add_development_dependency "rake"
4950
spec.add_development_dependency "rspec", "~> 2.14"
5051

51-
spec.add_dependency('activerecord', '~> 4.1.0')
52-
spec.add_dependency('arel', '>= 5.0.0')
53-
spec.add_dependency('crate_ruby', '~> 0.0.7')
52+
spec.add_dependency('activerecord', '~> 7')
53+
spec.add_dependency('crate_ruby', '~> 0.2')
5454
end

history.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
=== unreleased
44

5+
* Updated to ActiveRecord 7 and crate_ruby 0.2
6+
57
=== 0.0.4
68

79
* Updated crate version to 0.45.7

lib/active_record/connection_adapters/crate/schema_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
module ActiveRecord
2323
module ConnectionAdapters
2424
module Crate
25-
class SchemaCreation < AbstractAdapter::SchemaCreation
25+
class SchemaCreation < ActiveRecord::SchemaMigration
2626

2727
private
2828

lib/active_record/connection_adapters/crate_adapter.rb

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
require 'active_record/base'
2424
require 'active_record/base'
2525
require 'arel/arel_crate'
26-
require 'arel/visitors/bind_visitor'
26+
require 'arel/visitors/visitor'
2727
require 'active_support/dependencies/autoload'
2828
require 'active_support/callbacks'
2929
require 'active_support/core_ext/string'
@@ -45,7 +45,7 @@ module ActiveRecord
4545
class Base
4646
def self.crate_connection(config) #:nodoc:
4747
config = config.symbolize_keys
48-
ConnectionAdapters::CrateAdapter.new(nil, logger, nil, config)
48+
ConnectionAdapters::CrateAdapter.new(nil, logger, config)
4949
end
5050
end
5151

@@ -60,9 +60,10 @@ class ColumnDefinition < ActiveRecord::ConnectionAdapters::ColumnDefinition
6060

6161
ADAPTER_NAME = 'Crate'.freeze
6262

63-
def schema_creation # :nodoc:
64-
Crate::SchemaCreation.new self
65-
end
63+
# TODO: Croaks with `NotImplementedError`.
64+
# def schema_creation # :nodoc:
65+
# Crate::SchemaCreation.new self
66+
# end
6667

6768
NATIVE_DATABASE_TYPES = {
6869
boolean: {name: "boolean"},
@@ -77,13 +78,13 @@ def schema_creation # :nodoc:
7778
}
7879

7980
class BindSubstitution < Arel::Visitors::Crate # :nodoc:
80-
include Arel::Visitors::BindVisitor
81+
include Arel::Visitors
8182
end
8283

83-
def initialize(connection, logger, pool, config)
84+
def initialize(connection, logger, config)
8485
@port = config[:port]
8586
@host = config[:host]
86-
super(connection, logger, pool)
87+
super(connection, logger, config)
8788
@schema_cache = SchemaCache.new self
8889
@visitor = Arel::Visitors::Crate.new self
8990
@quoted_column_names = {}
@@ -127,11 +128,20 @@ def supports_migrations?
127128

128129
def connect
129130
@connection = CrateRuby::Client.new(["#{@host}:#{@port}"])
131+
132+
# Monkeypatch to make the client instance provide `supports_datetime_with_precision`.
133+
# FIXME: Implement within `CrateRuby::Client`.
134+
def @connection.supports_datetime_with_precision?
135+
# TODO: Should it be `true` instead?
136+
return false
137+
end
138+
130139
end
131140

132141
def columns(table_name) #:nodoc:
133142
cols = @connection.table_structure(table_name).map do |field|
134-
name = dotted_name(field[2])
143+
# TODO: Review. What if the table structure changes again?
144+
name = dotted_name(field[12])
135145
CrateColumn.new(name, nil, field[4], nil)
136146
end
137147
cols
@@ -172,10 +182,10 @@ class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition
172182
# +SecureRandom.uuid+ method and a +before_save+ callback, for instance.
173183
def primary_key(name, type = :primary_key, options = {})
174184
options[:primary_key] = true
175-
column name, "STRING PRIMARY KEY", options
185+
column name, "STRING PRIMARY KEY"
176186
end
177187

178-
def column(name, type = nil, options = {})
188+
def column(name, type = nil, **options)
179189
super
180190
column = self[name]
181191
column.array = options[:array]
@@ -189,19 +199,19 @@ def object(name, options = {})
189199
schema = options.delete(:object_schema)
190200
type = "#{type} as (#{object_schema_to_string(schema)})" if schema
191201

192-
column name, type, options.merge(object: true)
202+
column name, type, **options.merge(object: true)
193203
end
194204

195205
def array(name, options = {})
196206
array_type = options.delete(:array_type)
197207
raise "Array columns must specify an :array_type (e.g. array_type: :string)" unless array_type.present?
198-
column name, "array(#{array_type})", options.merge(array: true)
208+
column name, "array(#{array_type})", **options.merge(array: true)
199209
end
200210

201211
private
202212

203-
def create_column_definition(name, type)
204-
ColumnDefinition.new name, type
213+
def create_column_definition(name, type, options)
214+
ColumnDefinition.new(name, type, options)
205215
end
206216

207217
def object_schema_to_string(s)
@@ -220,8 +230,8 @@ def object_schema_to_string(s)
220230

221231
end
222232

223-
def create_table_definition(name, temporary, options, as = nil)
224-
TableDefinition.new native_database_types, name, temporary, options, as
233+
def create_table_definition(name)
234+
TableDefinition.new @connection, name
225235
end
226236

227237
def native_database_types

lib/arel/arel_crate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121

2222
require 'arel'
2323
require 'arel/visitors/crate'
24-
require 'arel/visitors/bind_visitor'
24+
require 'arel/visitors/visitor'

lib/arel/visitors/crate.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,3 @@ class Crate < Arel::Visitors::ToSql
2727
end
2828
end
2929
end
30-
31-
Arel::Visitors::VISITORS['crate'] = Arel::Visitors::Crate

spec/activerecord/connection_adapters/crate/table_definition_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
describe '#object_schema_to_string' do
2828

29-
let(:td) { ActiveRecord::ConnectionAdapters::CrateAdapter::TableDefinition.new(nil, nil, nil, nil) }
29+
let(:td) { ActiveRecord::ConnectionAdapters::CrateAdapter::TableDefinition.new(nil, nil) }
3030

3131
it 'should simply set the key and values' do
3232
s = {street: :string, city: :string}

spec/models/post_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
describe 'sql input sanitization' do
117117

118118
before do
119-
@post = Post.create!(params)
119+
@post = Post.create!(**params)
120120
end
121121

122122
after do

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def refresh_posts
6969
# Wait till all table is synced to all shards
7070
# this should be used after each create_table to prevent flaky tests
7171
def ensure_status(expected_status)
72+
# TODO: Did the health endpoint move elsewhere?
73+
return
7274
req = Net::HTTP::Get.new("/_cluster/health?wait_for_status=#{expected_status}&timeout=10s")
7375
resp = Net::HTTP.new(HOST, PORT)
7476
response = resp.start { |http| http.request(req) }

0 commit comments

Comments
 (0)