Class: ActiveRecord::Tasks::ChronomodelDatabaseTasks

Inherits:
PostgreSQLDatabaseTasks
  • Object
show all
Defined in:
lib/active_record/tasks/chronomodel_database_tasks.rb

Instance Method Summary collapse

Instance Method Details

#data_dump(target) ⇒ Object


24
25
26
27
28
29
30
31
# File 'lib/active_record/tasks/chronomodel_database_tasks.rb', line 24

def data_dump(target)
  set_psql_env

  args = ['-c', '-f', target]
  args << configuration['database']

  run_cmd "pg_dump", args, 'dumping data'
end

#data_load(source) ⇒ Object


33
34
35
36
37
38
39
40
# File 'lib/active_record/tasks/chronomodel_database_tasks.rb', line 33

def data_load(source)
  set_psql_env

  args = ['-f', source]
  args << configuration['database']

  run_cmd "psql", args, 'loading data'
end

#structure_dump(*arguments) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_record/tasks/chronomodel_database_tasks.rb', line 5

def structure_dump(*arguments)

  with_chronomodel_schema_search_path do
    super(*arguments)
  end

  # The structure.sql includes CREATE SCHEMA statements, but as these are executed
  # when the connection to the database is established, a db:structure:load fails.
  #
  # This code adds the IF NOT EXISTS clause to CREATE SCHEMA statements as long as
  # it is not already present.
  #
  filename = arguments.first
  sql = File.read(filename).gsub(/CREATE SCHEMA (?!IF NOT EXISTS)/, '\&IF NOT EXISTS ')
  File.open(filename, 'w') { |file| file << sql }

  remove_sql_header_comments(filename)
end