clickhouse-activerecord
clickhouse-activerecord copied to clipboard
Problem with Nullable Int data (is out of range for ActiveModel::Type::Integer with limit 0 bytes)
Hello I use ruby-3.1.2, rails 7.0.3 and clickhouse-activerecord gem version 0.5.8
My migration:
def up
execute <<~SQL
CREATE TABLE if not exists events
(
value_int Nullable(Int32),
created_at DateTime,
updated_at DateTime
)
engine = Log
SQL
end
def down
execute <<~SQL
drop table events
SQL
end
On console I tried to creating new record:
3.1.2 :003 > Event.create(value_int: 10)
/home/ruslan/.rvm/gems/ruby-3.1.2/gems/activemodel-7.0.3/lib/active_model/type/integer.rb:52:in `ensure_in_range': 10 is out of range for ActiveModel::Type::Integer with limit 0 bytes (ActiveModel::RangeError)
How resolve this problem?
I try create empty project using rails 6.1.6 . Create simple model with one integer not null (Nullable) field. Everything works without problems. Problem with relation rails 7.0.3.
ah, same problem, rails 7.0.3
I fix the problem by changing gem 'activerecord', '7.0.3' to gem 'activerecord', '6.1.6'
(it's not a rails project. I am using activerecord directly to connect PostgreSQL + ClickHouse to do some data analytic work. read some data from PostgreSQL and put the result into ClickHouse)
In rails 7, connection adapter methods :extract_limit, :extract_scale, :extract_precision, :initialize_type_map should be a class methods instead of instance ones. Creating explicit type map like
class ClickhouseAdapter < AbstractAdapter
...
class << self
def extract_limit
...
end
def extract_scale
...
end
def extract_precision
...
end
def initialize_type_map(m)
...
end
end
CH_TYPE_MAP = Type::TypeMap.new.tap { |m| initialize_type_map(m) }
def type_map = CH_TYPE_MAP
end
Solves the issue at the first glance. Will check it out in details