Class: ActiveRecord::Tasks::PostgreSQLDatabaseTasks
Overview
Constant Summary
collapse
- DEFAULT_ENCODING =
ENV["CHARSET"] || "utf8"
- ON_ERROR_STOP_1 =
"ON_ERROR_STOP=1"
"--"
Instance Method Summary
collapse
#charset, #check_current_protected_environment!, #collation, #initialize, using_database_configurations?
Instance Method Details
#create(connection_already_established = false) ⇒ Object
12
13
14
15
16
|
# File 'lib/active_record/tasks/postgresql_database_tasks.rb', line 12
def create(connection_already_established = false)
establish_connection(public_schema_config) unless connection_already_established
connection.create_database(db_config.database, configuration_hash.merge(encoding: encoding))
establish_connection
end
|
#drop ⇒ Object
18
19
20
21
|
# File 'lib/active_record/tasks/postgresql_database_tasks.rb', line 18
def drop
establish_connection(public_schema_config)
connection.drop_database(db_config.database)
end
|
#purge ⇒ Object
23
24
25
26
27
|
# File 'lib/active_record/tasks/postgresql_database_tasks.rb', line 23
def purge
ActiveRecord::Base.connection_handler.clear_active_connections!(:all)
drop
create true
end
|
#structure_dump(filename, extra_flags) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/active_record/tasks/postgresql_database_tasks.rb', line 29
def structure_dump(filename, )
search_path = \
case ActiveRecord.dump_schemas
when :schema_search_path
configuration_hash[:schema_search_path]
when :all
nil
when String
ActiveRecord.dump_schemas
end
args = ["--schema-only", "--no-privileges", "--no-owner"]
args.concat(["--file", filename])
args.concat(Array()) if
unless search_path.blank?
args += search_path.split(",").map do |part|
"--schema=#{part.strip}"
end
end
ignore_tables = ActiveRecord::SchemaDumper.ignore_tables
if ignore_tables.any?
ignore_tables = connection.data_sources.select { |table| ignore_tables.any? { |pattern| pattern === table } }
args += ignore_tables.flat_map { |table| ["-T", table] }
end
args << db_config.database
run_cmd("pg_dump", *args)
(filename)
File.open(filename, "a") { |f| f << "SET search_path TO #{connection.schema_search_path};\n\n" }
end
|
#structure_load(filename, extra_flags) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/active_record/tasks/postgresql_database_tasks.rb', line 63
def structure_load(filename, )
args = ["--set", ON_ERROR_STOP_1, "--quiet", "--no-psqlrc", "--output", File::NULL]
args.concat(Array()) if
args.concat(["--file", filename])
args << db_config.database
run_cmd("psql", *args)
end
|