Skip to content

Commit

Permalink
applied sexy migrations patch from kashif
Browse files Browse the repository at this point in the history
git-svn-id: http://georuby.rubyforge.org/svn/SpatialAdapter/trunk/spatial_adapter@106 7a115c08-5c0b-0410-86fa-965754e9f858
  • Loading branch information
sabman committed Feb 5, 2008
1 parent 32003dc commit 81900f0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
14 changes: 13 additions & 1 deletion lib/post_gis_adapter.rb
Expand Up @@ -3,6 +3,7 @@
require 'common_spatial_adapter'

include GeoRuby::SimpleFeatures
include SpatialAdapter

#tables to ignore in migration : relative to PostGIS management of geometric columns
ActiveRecord::SchemaDumper.ignore_tables << "spatial_ref_sys" << "geometry_columns"
Expand Down Expand Up @@ -310,7 +311,7 @@ class PostgreSQLTableDefinition < TableDefinition
attr_reader :geom_columns

def column(name, type, options = {})
unless @base.geometry_data_types[type].nil?
unless @base.geometry_data_types[type.to_sym].nil?
geom_column = PostgreSQLColumnDefinition.new(@base,name, type)
geom_column.null = options[:null]
geom_column.srid = options[:srid] || -1
Expand All @@ -323,6 +324,17 @@ def column(name, type, options = {})
super(name,type,options)
end
end

SpatialAdapter.geometry_data_types.keys.each do |column_type|
class_eval <<-EOV
def #{column_type}(*args)
options = args.extract_options!
column_names = args
column_names.each { |name| column(name, '#{column_type}', options) }
end
EOV
end
end

class PostgreSQLColumnDefinition < ColumnDefinition
Expand Down
4 changes: 2 additions & 2 deletions test/find_postgis_test.rb
Expand Up @@ -11,8 +11,8 @@ class FindPostgisTest < Test::Unit::TestCase
def setup
ActiveRecord::Schema.define() do
create_table "parks", :force => true do |t|
t.column "data" , :string, :limit => 100
t.column "geom", :point,:null=>false,:srid=>123
t.string "data", :limit => 100
t.point "geom", :null=>false,:srid=>123
end
add_index "parks","geom",:spatial=>true,:name => "example_spatial_index"
end
Expand Down
18 changes: 9 additions & 9 deletions test/migration_postgis_test.rb
Expand Up @@ -21,9 +21,9 @@ def test_creation_modification
#create a table with a geometric column
ActiveRecord::Schema.define do
create_table "parks", :force => true do |t|
t.column "data" , :string, :limit => 100
t.column "value", :integer
t.column "geom", :polygon, :null=>false, :srid => 555 , :with_z => true,:with_m => true
t.string "data", :limit => 100
t.integer "value"
t.polygon "geom", :null=>false, :srid => 555 , :with_z => true,:with_m => true
end
end

Expand Down Expand Up @@ -115,10 +115,10 @@ def test_creation_modification
def test_keyword_column_name
ActiveRecord::Schema.define do
create_table "parks", :force => true do |t|
t.column "data" , :string, :limit => 100
t.column "value", :integer
t.string "data", :limit => 100
t.integer "value"
#location is a postgreSQL keyword and is surrounded by double-quotes ("") when appearing in constraint descriptions ; tests a bug corrected in version 39
t.column "location", :point,:null=>false,:srid => 0, :with_m => true, :with_z => true
t.point "location", :null=>false,:srid => 0, :with_m => true, :with_z => true
end
end

Expand All @@ -144,9 +144,9 @@ def test_dump
#Force the creation of a table
ActiveRecord::Schema.define do
create_table "parks", :force => true do |t|
t.column "data" , :string, :limit => 100
t.column "value", :integer
t.column "geom", :multi_polygon,:null=>false,:srid => 0, :with_m => true, :with_z => true
t.string "data" , :limit => 100
t.integer "value"
t.multi_polygon "geom", :null=>false,:srid => 0, :with_m => true, :with_z => true
end

add_index "parks","geom",:spatial=>true,:name => "example_spatial_index"
Expand Down
36 changes: 16 additions & 20 deletions test/schema/schema_postgis.rb
Expand Up @@ -4,66 +4,62 @@
ActiveRecord::Schema.define() do

create_table "table_points", :force => true do |t|
t.column "data", :string
t.column "geom", :point, :null=>false
t.string "data"
t.point "geom", :null=>false
end

create_table "table_keyword_column_points", :force => true do |t|
t.column "location", :point, :null => false
t.point "location", :null => false
end

create_table "table_line_strings", :force => true do |t|
t.column "value", :integer
t.column "geom", :line_string, :null=>false
t.integer "value"
t.line_string "geom", :null=>false
end

create_table "table_polygons", :force => true do |t|
t.column "geom", :polygon, :null=>false
t.polygon "geom", :null=>false
end

create_table "table_multi_points", :force => true do |t|
t.column "geom", :multi_point, :null=>false
t.multi_point "geom", :null=>false
end

create_table "table_multi_line_strings", :force => true do |t|
t.column "geom", :multi_line_string, :null=>false
t.multi_line_string "geom", :null=>false
end

create_table "table_multi_polygons", :force => true do |t|
t.column "geom", :multi_polygon, :null=>false
t.multi_polygon "geom", :null=>false
end

create_table "table_geometries", :force => true do |t|
t.column "geom", :geometry, :null=>false
t.geometry "geom", :null=>false
end

create_table "table_geometry_collections", :force => true do |t|
t.column "geom", :geometry_collection, :null=>false
t.geometry_collection "geom", :null=>false
end

create_table "table3dz_points", :force => true do |t|
t.column "data", :string
t.column "geom", :point, :null => false , :with_z => true
t.point "geom", :null => false , :with_z => true
end

create_table "table3dm_points", :force => true do |t|
t.column "geom", :point, :null => false , :with_m => true
t.point "geom", :null => false , :with_m => true
end

create_table "table4d_points", :force => true do |t|
t.column "geom", :point, :null => false, :with_m => true, :with_z => true
t.point "geom", :null => false, :with_m => true, :with_z => true
end

create_table "table_srid_line_strings", :force => true do |t|
t.column "geom", :line_string, :null => false , :srid => 123
t.line_string "geom", :null => false , :srid => 123
end

create_table "table_srid4d_polygons", :force => true do |t|
t.column "geom", :polygon, :with_m => true, :with_z => true, :srid => 123
t.polygon "geom", :with_m => true, :with_z => true, :srid => 123
end

end




0 comments on commit 81900f0

Please sign in to comment.