aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-06-03 16:17:59 +0200
committerYves Senn <yves.senn@gmail.com>2014-06-03 16:17:59 +0200
commitfcd5e56b862ffea9a8c1cea0c622472c5346474b (patch)
tree8fad1200ad20cc9d913163eafeb261d18c4afc41 /activerecord/lib/active_record
parent51f247107f63b8c6c3a2ba689d26b3ed51237ab2 (diff)
downloadrails-fcd5e56b862ffea9a8c1cea0c622472c5346474b.tar.gz
rails-fcd5e56b862ffea9a8c1cea0c622472c5346474b.tar.bz2
rails-fcd5e56b862ffea9a8c1cea0c622472c5346474b.zip
pg, preserve type when schema dumping bit and bit varying columns.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid.rb1
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/bit.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb13
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb8
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb6
5 files changed, 31 insertions, 3 deletions
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