PNixx / clickhouse-activerecord

A Ruby database ActiveRecord driver for ClickHouse
MIT License
192 stars 96 forks source link

Can't create signed Int32 in test environment #136

Closed tee0zed closed 1 month ago

tee0zed commented 3 months ago
class CreateEntries < ActiveRecord::Migration[7.1]
  def change
    create_table 'entries', id: false, null: false,
      options: 'MergeTree() PARTITION BY (partner_id, toYYYYMM(created_at)) ORDER BY (wallet_id, created_at)', force: :cascade do |t|
        t.uuid 'id', default: -> { 'generateUUIDv4()' }, null: false
        t.uuid 'partner_id', null: false
        t.uuid 'wallet_id', null: false
        t.uuid 'transaction_id', null: false
        t.string 'desc', limit: 128
        t.column 'available', 'Int32', null: false
        t.column 'hold', 'Int32', null: false
        t.column 'type', 'LowCardinality(String)', null: false
        t.column 'created_at', 'DateTime64', default: -> { "CAST(now(), 'DateTime64')" }, null: false
      end
  end
end
 RAILS_ENV=test rails db:clickhouse:drop
 RAILS_ENV=test rails db:clickhouse:create
 RAILS_ENV=test rails db:clickhouse:migrate

Then, somewhere in tests:


[1] pry(Wallets::Entry)> ClickHouseRecord.connection.execute('DESC TABLE entries')
=> {"meta"=>
  [{"name"=>"name", "type"=>"String"},
   {"name"=>"type", "type"=>"String"},
   {"name"=>"default_type", "type"=>"String"},
   {"name"=>"default_expression", "type"=>"String"},
   {"name"=>"comment", "type"=>"String"},
   {"name"=>"codec_expression", "type"=>"String"},
   {"name"=>"ttl_expression", "type"=>"String"}],
 "data"=>
  [["partner_id", "UUID", "", "", "", "", ""],
   ["wallet_id", "UUID", "", "", "", "", ""],
   ["transaction_id", "UUID", "", "", "", "", ""],
   ["desc", "Nullable(String)", "", "", "", "", ""],
   ["available", "UInt32", "", "", "", "", ""],
   ["hold", "UInt32", "", "", "", "", ""],
   ["type", "String", "", "", "", "", ""],
   ["created_at", "DateTime64(3)", "DEFAULT", "CAST(now(), 'DateTime64')", "", "", ""],
   ["id", "UUID", "", "", "", "", ""]]}
[2] pry(Wallets::Entry)> 

Somehow, there's no such issue with Int64 in test env, nor for the development environment with Int32

PNixx commented 1 month ago

Please, read README.md before create issues:

t.integer "available", unsigned: false, null: false
tee0zed commented 1 month ago

I think i tried it first, thx I'll check.