Class: OsmImport::Target::PgTables

Inherits:
PgBase
  • Object
show all
Defined in:
lib/osm_import/target/pg_tables.rb

Defined Under Namespace

Classes: TargetTable

Constant Summary

Constants inherited from PgBase

OsmImport::Target::PgBase::GEOTYPES

Instance Attribute Summary

Attributes inherited from PgBase

#options

Instance Method Summary collapse

Methods inherited from PgBase

#geometry_type, #new_prefix, #prefix, #projection, #raw_prefix

Instance Method Details

#import(schema) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/osm_import/target/pg_tables.rb', line 5

def import(schema)
  conn = Connection.new options
  conn.exec "BEGIN TRANSACTION"

  puts "Dropping old tables:"

  schema.tables.each do |table|
    conn.exec "DROP TABLE IF EXISTS #{new_prefix}#{table.name}"
  end

  puts "Preparing target tables"

  tts = schema.tables.map{|table| TargetTable.new self, conn, table }

  puts "Creating tables and importing data:"

  tts.each do |tt|
    tt.create! # Create table
    tt.import! # Import data to it
  end

  puts "Deploy tables"
  tts.each do |tt|
    tt.deploy!
  end

  puts "Restoring geometry columns"
  conn.exec "TRUNCATE geometry_columns"
  conn.exec "SELECT probe_geometry_columns()"

  puts "Commiting"
  conn.exec "COMMIT"
  conn.close
end