ReefPointsBlog

Rails 4.0 Sneak Peek: Expanded ActiveRecord Support for PostgreSQL Datatypes

Dan McClain

This week, I had a pull request accepted into Rails which adds support for PostgreSQL's MACADDR, INET, and CIDR datatypes. In Rails 4.0, the following migration will be supported:

1
2
3
4
5
create_table :network_types do |t|
  t.cidr :cidr_address
  t.inet :ip_address
  t.macaddr :mac_address
end

Also, the schema dumper supports these types as well (previously they would appear as string types in the schema.rb file).

ActiveRecord will also cast the values of the INET and CIDR types to Ruby's IPAddr, while MACADDR will continue to be converted to a string.