From 84c84289e89a3f434e8b79b3ca8aada45d9b3d58 Mon Sep 17 00:00:00 2001 From: Ying Tsen Hong Date: Wed, 17 Feb 2010 03:58:34 +0800 Subject: [PATCH] Adding support to create a Test PostGIS database; from git://github.com/melriffe/spatial_adapter.git --- README.rdoc | 9 +++++++++ lib/postgis_adapter.rb | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/README.rdoc b/README.rdoc index f9d22f2..ab01cea 100644 --- a/README.rdoc +++ b/README.rdoc @@ -48,6 +48,15 @@ Rails: script/plugin install git://github.com/nofxx/postgis_adapter.git +====== PostGIS SQL Scripts +This is only for PostgreSQL databases: + +Place the following scripts in a folder named 'spatial' under the 'db' folder; For example: + RAILS_ROOT/db/spatial/lwpostgis.sql + RAILS_ROOT/db/spatial/spatial_ref_sys + +These will be used when creating the Test database when running the Rake Test tasks. These scripts should have been installed when the PostGIS libraries were installed. Online reference: http://postgis.refractions.net/ + == How to Use diff --git a/lib/postgis_adapter.rb b/lib/postgis_adapter.rb index d6c3c92..cacef47 100644 --- a/lib/postgis_adapter.rb +++ b/lib/postgis_adapter.rb @@ -102,6 +102,17 @@ def self.sanitize_sql_hash_for_conditions(attrs, table_name = quoted_table_name) 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/lwpostgis.sql` + `psql -d #{configuration["test"]["database"]} -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)