Permalink
Browse files

Import data without clearing everything first (Closes #83)

  • Loading branch information...
stanguy committed Apr 4, 2012
1 parent da70700 commit 69af06c8c4dcbda861af801dd418a41a279a8458
Showing with 22 additions and 1 deletion.
  1. +22 −1 lib/tasks/import.rake
View
@@ -3,7 +3,7 @@ require 'gtfs/rennes'
require 'gtfs/stlo'
namespace :stargtfs do
- desc "tamere"
+ desc "Import a number of agencies"
task :import, [:agencies] => :environment do|t,args|
args.with_defaults( :agencies => 'rennes:stlo' )
Importers = {
@@ -19,4 +19,25 @@ namespace :stargtfs do
end
end
end
+
+ desc "Import default agencies while running"
+ task :parallel_import => :environment do
+ current_schema = "s" + Time.now.to_i.to_s
+ conn = ActiveRecord::Base.connection
+ target_schema = conn.current_schema
+ if target_schema == "public"
+ puts "Wrong schema base"
+ next
+ end
+ if conn.schema_exists? current_schema
+ conn.execute "DROP SCHEMA " + current_schema + " CASCADE"
+ end
+ conn.execute "CREATE SCHEMA " + current_schema
+ conn.schema_search_path= current_schema + ",public"
+ Rake::Task["db:schema:load"].invoke
+ Rake::Task["stargtfs:import"].invoke
+ conn.execute "DROP SCHEMA " + target_schema + " CASCADE"
+ conn.execute "ALTER SCHEMA " + current_schema + " RENAME TO " + target_schema
+ end
+
end

0 comments on commit 69af06c

Please sign in to comment.