instacart / makara

A Read-Write Proxy for Connections; Also provides an ActiveRecord adapter.
http://tech.taskrabbit.com/
MIT License
928 stars 170 forks source link

Registering Types not working? #374

Open kjanoudi opened 1 year ago

kjanoudi commented 1 year ago

Hello,

In my project, i must manually add the following code:

https://github.com/rails/rails/blob/593893c901f87b4ed205751f72df41519b4d2da3/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L1045

ActiveRecord::Type.add_modifier({array: true}, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array, adapter: :postgresql_makara)
ActiveRecord::Type.add_modifier({range: true}, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Range, adapter: :postgresql_makara)
ActiveRecord::Type.register(:bit, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Bit, adapter: :postgresql_makara)
ActiveRecord::Type.register(:bit_varying, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::BitVarying, adapter: :postgresql_makara)
ActiveRecord::Type.register(:binary, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Bytea, adapter: :postgresql_makara)
ActiveRecord::Type.register(:cidr, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Cidr, adapter: :postgresql_makara)
ActiveRecord::Type.register(:date, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Date, adapter: :postgresql_makara)
ActiveRecord::Type.register(:datetime, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime, adapter: :postgresql_makara)
ActiveRecord::Type.register(:decimal, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Decimal, adapter: :postgresql_makara)
ActiveRecord::Type.register(:enum, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Enum, adapter: :postgresql_makara)
ActiveRecord::Type.register(:hstore, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Hstore, adapter: :postgresql_makara)
ActiveRecord::Type.register(:inet, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Inet, adapter: :postgresql_makara)
ActiveRecord::Type.register(:interval, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Interval, adapter: :postgresql_makara)
ActiveRecord::Type.register(:jsonb, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb, adapter: :postgresql_makara)
ActiveRecord::Type.register(:money, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Money, adapter: :postgresql_makara)
ActiveRecord::Type.register(:point, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Point, adapter: :postgresql_makara)
ActiveRecord::Type.register(:legacy_point, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::LegacyPoint, adapter: :postgresql_makara)
ActiveRecord::Type.register(:uuid, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Uuid, adapter: :postgresql_makara)
ActiveRecord::Type.register(:vector, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Vector, adapter: :postgresql_makara)
ActiveRecord::Type.register(:xml, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Xml, adapter: :postgresql_makara)

In order to have these custom postgresql types continue to be supported when using makara. If i do not, then it does not recognize the types as working for the makara version of the postgresql adapter. Is this a common issue? Is it something wrong with my configuration?

Here's an example:

Discount.rb:

jsonb_accessor :options, eligibleItemIds: [:integer, {array: true, default: []}]
irb(main):010:0> Discount.first
/3.0.4/lib/ruby/gems/3.0.0/gems/activemodel-7.0.4/lib/active_model/type/value.rb:8:in `initialize’: unknown keyword: :array (ArgumentError)

> ActiveRecord::Type.add_modifier({array: true}, ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array, adapter: :postgresql_makara)

irb(main):010:0> Discount.first
=> #<Discount:0x000000012c15b9b8
 id: 1,
 code: "abc",
 deleted_at: nil,
 options: {"eligibleItemIds"=>[]},
 eligibleItemIds: []>

Thank you