Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pg, preserve point type when schema dumping.

  • Loading branch information...
commit 098bb63ae4acc349826ab84b3e1dff985e38609c 1 parent ed1b747
@senny senny authored
View
4 activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Preserve type when dumping PostgreSQL point types.
+
+ *Yves Senn*
+
* New records remain new after YAML serialization.
*Sean Griffin*
View
6 activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb
@@ -2,7 +2,11 @@ module ActiveRecord
module ConnectionAdapters
module PostgreSQL
module OID # :nodoc:
- class Point < Type::String
+ class Point < Type::Value
+ def type
+ :point
+ end
+
def type_cast(value)
if ::String === value
if value[0] == '(' && value[-1] == ')'
View
4 activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb
@@ -67,6 +67,10 @@ def json(name, options = {})
def citext(name, options = {})
column(name, 'citext', options)
end
+
+ def point(name, options = {})
+ column(name, 'point', options)
+ end
end
class ColumnDefinition < ActiveRecord::ConnectionAdapters::ColumnDefinition
View
3  activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -103,7 +103,8 @@ class PostgreSQLAdapter < AbstractAdapter
uuid: { name: "uuid" },
json: { name: "json" },
ltree: { name: "ltree" },
- citext: { name: "citext" }
+ citext: { name: "citext" },
+ point: { name: "point"}
}
OID = PostgreSQL::OID #:nodoc:
View
16 activerecord/test/cases/adapters/postgresql/geometric_test.rb
@@ -15,9 +15,9 @@ def setup
@connection = ActiveRecord::Base.connection
@connection.transaction do
@connection.create_table('postgresql_points') do |t|
- t.column :x, :point
- t.column :y, :point, default: [12.2, 13.3]
- t.column :z, :point, default: "(14.4,15.5)"
+ t.point :x
+ t.point :y, default: [12.2, 13.3]
+ t.point :z, default: "(14.4,15.5)"
end
end
end
@@ -28,9 +28,9 @@ def setup
def test_column
column = PostgresqlPoint.columns_hash["x"]
- assert_equal :string, column.type
+ assert_equal :point, column.type
assert_equal "point", column.sql_type
- assert column.text?
+ assert_not column.text?
assert_not column.number?
assert_not column.binary?
assert_not column.array
@@ -48,9 +48,9 @@ def test_default
def test_schema_dumping
output = dump_table_schema("postgresql_points")
- assert_match %r{t\.string\s+"x"$}, output
- assert_match %r{t\.string\s+"y",\s+default: \[12\.2, 13\.3\]$}, output
- assert_match %r{t\.string\s+"z",\s+default: \[14\.4, 15\.5\]$}, output
+ assert_match %r{t\.point\s+"x"$}, output
+ assert_match %r{t\.point\s+"y",\s+default: \[12\.2, 13\.3\]$}, output
+ assert_match %r{t\.point\s+"z",\s+default: \[14\.4, 15\.5\]$}, output
end
def test_roundtrip
View
2  activerecord/test/cases/schema_dumper_test.rb
@@ -62,7 +62,7 @@ def test_types_line_up
next if column_set.empty?
lengths = column_set.map do |column|
- if match = column.match(/t\.(?:integer|decimal|float|datetime|timestamp|time|date|text|binary|string|boolean|uuid)\s+"/)
+ if match = column.match(/t\.(?:integer|decimal|float|datetime|timestamp|time|date|text|binary|string|boolean|uuid|point)\s+"/)
match[0].length
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.