Class: ActiveRecord::Tasks::ChronomodelDatabaseTasks

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

Constant Summary collapse

CHRONOMODEL_SCHEMAS =
[
  ChronoModel::Adapter::TEMPORAL_SCHEMA,
  ChronoModel::Adapter::HISTORY_SCHEMA
].freeze

Instance Method Summary collapse

Instance Method Details

#data_dump(target) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/active_record/tasks/chronomodel_database_tasks.rb', line 29

def data_dump(target)
  psql_env

  args = ['-c', '-f', target.to_s]
  args << chronomodel_configuration[:database]

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

#data_load(source) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/active_record/tasks/chronomodel_database_tasks.rb', line 38

def data_load(source)
  psql_env

  args = ['-f', source]
  args << chronomodel_configuration[:database]

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

#structure_dump(*arguments) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_record/tasks/chronomodel_database_tasks.rb', line 11

def structure_dump(*arguments)
  if schema_search_path.present?
    with_chronomodel_schema_search_path { super }
  else
    super
  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 }
end