From fcd5e56b862ffea9a8c1cea0c622472c5346474b Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Tue, 3 Jun 2014 16:17:59 +0200 Subject: pg, preserve type when schema dumping bit and bit varying columns. --- .../lib/active_record/connection_adapters/postgresql/oid.rb | 1 + .../active_record/connection_adapters/postgresql/oid/bit.rb | 6 +++++- .../connection_adapters/postgresql/oid/bit_varying.rb | 13 +++++++++++++ .../connection_adapters/postgresql/schema_definitions.rb | 8 ++++++++ .../active_record/connection_adapters/postgresql_adapter.rb | 6 ++++-- 5 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 activerecord/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb index 2494e19f84..33a98b4fcb 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb @@ -2,6 +2,7 @@ require 'active_record/connection_adapters/postgresql/oid/infinity' require 'active_record/connection_adapters/postgresql/oid/array' require 'active_record/connection_adapters/postgresql/oid/bit' +require 'active_record/connection_adapters/postgresql/oid/bit_varying' require 'active_record/connection_adapters/postgresql/oid/bytea' require 'active_record/connection_adapters/postgresql/oid/cidr' require 'active_record/connection_adapters/postgresql/oid/date' diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb index dc077993c5..3073f8ff30 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb @@ -2,7 +2,11 @@ module ActiveRecord module ConnectionAdapters module PostgreSQL module OID # :nodoc: - class Bit < Type::String + class Bit < Type::Value + def type + :bit + end + def type_cast(value) if ::String === value case value diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb new file mode 100644 index 0000000000..054af285bb --- /dev/null +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb @@ -0,0 +1,13 @@ +module ActiveRecord + module ConnectionAdapters + module PostgreSQL + module OID # :nodoc: + class BitVarying < OID::Bit + def type + :bit_varying + end + end + end + end + end +end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb index deaea12408..ca2966466c 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb @@ -71,6 +71,14 @@ module ActiveRecord def point(name, options = {}) column(name, 'point', options) end + + def bit(name, options) + column(name, 'bit', options) + end + + def bit_varying(name, options) + column(name, 'bit varying', options) + end end class ColumnDefinition < ActiveRecord::ConnectionAdapters::ColumnDefinition diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 61694674ab..c900d61390 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -104,7 +104,9 @@ module ActiveRecord json: { name: "json" }, ltree: { name: "ltree" }, citext: { name: "citext" }, - point: { name: "point"} + point: { name: "point"}, + bit: { name: "bit"}, + bit_varying: { name: "bit varying" } } OID = PostgreSQL::OID #:nodoc: @@ -434,7 +436,7 @@ module ActiveRecord m.alias_type 'bpchar', 'varchar' m.register_type 'bool', Type::Boolean.new m.register_type 'bit', OID::Bit.new - m.alias_type 'varbit', 'bit' + m.register_type 'varbit', OID::BitVarying.new m.alias_type 'timestamptz', 'timestamp' m.register_type 'date', OID::Date.new m.register_type 'time', OID::Time.new -- cgit v1.2.3