Class: ActiveRecord::ConnectionAdapters::PostGISAdapter::PostGISDatabaseTasks

Inherits:
Tasks::PostgreSQLDatabaseTasks
  • Object
show all
Defined in:
lib/active_record/connection_adapters/postgis_adapter/rails4/postgis_database_tasks.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(config_) ⇒ PostGISDatabaseTasks

Returns a new instance of PostGISDatabaseTasks.



10
11
12
13
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/postgis_database_tasks.rb', line 10

def initialize(config_)
  super
  ensure_installation_configs
end

Instance Method Details

#create(master_established_ = false) ⇒ Object

Overridden to set the database owner and call setup_gis



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/postgis_database_tasks.rb', line 33

def create(master_established_=false)
  establish_master_connection unless master_established_
  extra_configs_ = {'encoding' => encoding}
  extra_configs_['owner'] = username if has_su?
  connection.create_database(configuration['database'], configuration.merge(extra_configs_))
  setup_gis
rescue ::ActiveRecord::StatementInvalid => error_
  if /database .* already exists/ === error_.message
    raise ::ActiveRecord::Tasks::DatabaseAlreadyExists
  else
    raise
  end
end

#setup_gisObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/postgis_database_tasks.rb', line 16

def setup_gis
  establish_su_connection
  setup_gis_schemas
  if script_dir
    setup_gis_from_script_dir
  elsif extension_names
    setup_gis_from_extension
  end
  if has_su? && (script_dir || extension_names)
    setup_gis_grant_privileges
  end
  establish_connection(configuration)
end

#structure_dump(filename_) ⇒ Object

Overridden to remove postgis schema



50
51
52
53
54
55
56
57
58
59
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/postgis_database_tasks.rb', line 50

def structure_dump(filename_)
  set_psql_env
  search_path_ = search_path.dup
  search_path_.delete('postgis')
  search_path_ = ['public'] if search_path_.length == 0
  search_path_clause_ = search_path_.map{ |part_| "--schema=#{::Shellwords.escape(part_)}" }.join(' ')
  command_ = "pg_dump -i -s -x -O -f #{::Shellwords.escape(filename_)} #{search_path_clause_} #{::Shellwords.escape(configuration['database'])}"
  raise 'Error dumping database' unless ::Kernel.system(command_)
  ::File.open(filename_, "a") { |f_| f_ << "SET search_path TO #{ActiveRecord::Base.connection.schema_search_path};\n\n" }
end