diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-06-03 13:56:21 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-06-03 13:56:21 +0200 |
commit | 098bb63ae4acc349826ab84b3e1dff985e38609c (patch) | |
tree | aecd8f4d2e38812e421ad60a70ebcc204d62d9d9 | |
parent | ed1b747b85876122e0b7b11aaabcc877c6f819b9 (diff) | |
download | rails-098bb63ae4acc349826ab84b3e1dff985e38609c.tar.gz rails-098bb63ae4acc349826ab84b3e1dff985e38609c.tar.bz2 rails-098bb63ae4acc349826ab84b3e1dff985e38609c.zip |
pg, preserve point type when schema dumping.
6 files changed, 24 insertions, 11 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 9da1304953..d9065c7afc 100644 --- a/activerecord/CHANGELOG.md +++ b/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* diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb index f9531ddee3..9007bfb178 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/point.rb +++ b/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] == ')' 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 bcfd605165..deaea12408 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb @@ -67,6 +67,10 @@ module ActiveRecord def citext(name, options = {}) column(name, 'citext', options) end + + def point(name, options = {}) + column(name, 'point', 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 23c1a8de2f..61694674ab 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -103,7 +103,8 @@ module ActiveRecord uuid: { name: "uuid" }, json: { name: "json" }, ltree: { name: "ltree" }, - citext: { name: "citext" } + citext: { name: "citext" }, + point: { name: "point"} } OID = PostgreSQL::OID #:nodoc: diff --git a/activerecord/test/cases/adapters/postgresql/geometric_test.rb b/activerecord/test/cases/adapters/postgresql/geometric_test.rb index 89a72f08b4..46c7662879 100644 --- a/activerecord/test/cases/adapters/postgresql/geometric_test.rb +++ b/activerecord/test/cases/adapters/postgresql/geometric_test.rb @@ -15,9 +15,9 @@ class PostgresqlPointTest < ActiveRecord::TestCase @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 @@ class PostgresqlPointTest < ActiveRecord::TestCase 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 @@ class PostgresqlPointTest < ActiveRecord::TestCase 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 diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index 9602252b2e..ce2b06430b 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -62,7 +62,7 @@ class SchemaDumperTest < ActiveRecord::TestCase 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 |