Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registering Types not working? #374

Open
kjanoudi opened this issue Aug 7, 2023 · 0 comments
Open

Registering Types not working? #374

kjanoudi opened this issue Aug 7, 2023 · 0 comments

Comments

@kjanoudi
Copy link

kjanoudi commented Aug 7, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant