lib/postgis_adapter.rb in postgis_adapter-0.7.8 vs lib/postgis_adapter.rb in postgis_adapter-0.7.9
- old
+ new
@@ -3,25 +3,25 @@
#
#
# Code from
# http://georuby.rubyforge.org Spatial Adapter
#
-require 'activerecord'
+require 'active_record'
require 'active_record/connection_adapters/postgresql_adapter'
require 'geo_ruby'
require 'postgis_adapter/common_spatial_adapter'
-require 'postgis_functions'
-require 'postgis_functions/common'
-require 'postgis_functions/class'
-require 'postgis_functions/bbox'
+require 'postgis_adapter/functions'
+require 'postgis_adapter/functions/common'
+require 'postgis_adapter/functions/class'
+require 'postgis_adapter/functions/bbox'
require 'postgis_adapter/acts_as_geom'
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"
+ActiveRecord::SchemaDumper.ignore_tables.concat %w{ spatial_ref_sys geometry_columns geography_columns }
#add a method to_yaml to the Geometry class which will transform a geometry in a form suitable to be used in a YAML file (such as in a fixture)
GeoRuby::SimpleFeatures::Geometry.class_eval do
def to_fixture_format
as_hex_ewkb
@@ -100,10 +100,29 @@
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
include SpatialAdapter
+ # SCHEMA STATEMENTS ========================================
+
+ alias :original_recreate_database :recreate_database
+ def recreate_database(configuration, enc_option)
+ `dropdb -U "#{configuration["test"]["username"]}" #{configuration["test"]["database"]}`
+ `createdb #{enc_option} -U "#{configuration["test"]["username"]}" #{configuration["test"]["database"]}`
+ `createlang -U "#{configuration["test"]["username"]}" plpgsql #{configuration["test"]["database"]}`
+ `psql -d #{configuration["test"]["database"]} -f db/spatial/postgis.sql`
+ `psql -d #{configuration["test"]["database"]} -f db/spatial/spatial_ref_sys.sql`
+ end
+
+ alias :original_create_database :create_database
+ def create_database(name, options = {})
+ original_create_database(name, options = {})
+ `createlang plpgsql #{name}`
+ `psql -d #{name} -f db/spatial/postgis.sql`
+ `psql -d #{name} -f db/spatial/spatial_ref_sys.sql`
+ end
+
alias :original_native_database_types :native_database_types
def native_database_types
original_native_database_types.update(geometry_data_types)
end
@@ -246,20 +265,20 @@
ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new(name, default, type, notnull == "f")
end
end
end
-# # For version of Rails where exists disable_referential_integrity
+ # For version of Rails where exists disable_referential_integrity
if self.instance_methods.include? "disable_referential_integrity"
#Pete Deffendol's patch
alias :original_disable_referential_integrity :disable_referential_integrity
def disable_referential_integrity(&block) #:nodoc:
- ignore_tables = %w{ geometry_columns spatial_ref_sys geography_columns }
- execute(tables.select { |name| !ignore_tables.include?(name) }.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
+ ignore_tables = %w{ geometry_columns spatial_ref_sys } # geography_columns + views
+ execute(tables.select { |name| !ignore_tables.include?(name) }.map { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";"))
yield
ensure
- execute(tables.select { |name| !ignore_tables.include?(name)}.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
+ execute(tables.select { |name| !ignore_tables.include?(name)}.map { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";"))
end
end
private
@@ -287,11 +306,11 @@
#check the presence of z and m
raw_geom_info.convert!
end
raw_geom_infos
- rescue => e
- nil
+ rescue => e
+ nil
end
end
module ActiveRecord