BUGFIX: restore wasn't working when not using multisite in production
This commit is contained in:
parent
b696c96a19
commit
1f90f3044f
|
@ -94,6 +94,7 @@ module BackupRestore
|
|||
-- move all "source" tables to "destination" schema
|
||||
FOR row IN SELECT tablename FROM pg_tables WHERE schemaname = '#{source}'
|
||||
LOOP
|
||||
EXECUTE 'DROP TABLE IF EXISTS #{destination}.' || quote_ident(row.tablename) || ' CASCADE;';
|
||||
EXECUTE 'ALTER TABLE #{source}.' || quote_ident(row.tablename) || ' SET SCHEMA #{destination};';
|
||||
END LOOP;
|
||||
END$$;
|
||||
|
@ -104,8 +105,8 @@ module BackupRestore
|
|||
|
||||
def self.database_configuration
|
||||
if Rails.env.production?
|
||||
conn = RailsMultisite::ConnectionManagement
|
||||
db_conf = DatabaseConfiguration.new(conn.current_host, conn.current_username, conn.current_password, conn.current_db)
|
||||
db = ActiveRecord::Base.connection_pool.spec.config
|
||||
db_conf = DatabaseConfiguration.new(db["host"], db["username"], db["password"], db["database"])
|
||||
else
|
||||
db = Rails.configuration.database_configuration[Rails.env]
|
||||
db_conf = DatabaseConfiguration.new(db["host"], db["username"], db["password"], db["database"])
|
||||
|
|
|
@ -155,18 +155,19 @@ module Export
|
|||
db_conf = BackupRestore.database_configuration
|
||||
|
||||
password_argument = "PGPASSWORD=#{db_conf.password}" if db_conf.password.present?
|
||||
host_argument = "--host=#{db_conf.host}" if db_conf.host.present?
|
||||
host_argument = "--host=#{db_conf.host}" if db_conf.host.present?
|
||||
username_argument = "--username=#{db_conf.username}" if db_conf.username.present?
|
||||
|
||||
[ password_argument, # pass the password to pg_dump
|
||||
"pg_dump", # the pg_dump command
|
||||
"--schema=public", # only public schema
|
||||
"--file='#{@dump_filename}'", # output to the dump.sql file
|
||||
"--no-owner", # do not output commands to set ownership of objects
|
||||
"--no-privileges", # prevent dumping of access privileges
|
||||
"--verbose", # specifies verbose mode
|
||||
host_argument, # the hostname to connect to
|
||||
"--username=#{db_conf.username}", # the username to connect as
|
||||
db_conf.database # the name of the database to dump
|
||||
[ password_argument, # pass the password to pg_dump (if any)
|
||||
"pg_dump", # the pg_dump command
|
||||
"--schema=public", # only public schema
|
||||
"--file='#{@dump_filename}'", # output to the dump.sql file
|
||||
"--no-owner", # do not output commands to set ownership of objects
|
||||
"--no-privileges", # prevent dumping of access privileges
|
||||
"--verbose", # specifies verbose mode
|
||||
host_argument, # the hostname to connect to (if any)
|
||||
username_argument, # the username to connect as (if any)
|
||||
db_conf.database # the name of the database to dump
|
||||
].join(" ")
|
||||
end
|
||||
|
||||
|
|
|
@ -203,15 +203,16 @@ module Import
|
|||
db_conf = BackupRestore.database_configuration
|
||||
|
||||
password_argument = "PGPASSWORD=#{db_conf.password}" if db_conf.password.present?
|
||||
host_argument = "--host=#{db_conf.host}" if db_conf.host.present?
|
||||
host_argument = "--host=#{db_conf.host}" if db_conf.host.present?
|
||||
username_argument = "--username=#{db_conf.username}" if db_conf.username.present?
|
||||
|
||||
[ password_argument, # pass the password to psql
|
||||
[ password_argument, # pass the password to psql (if any)
|
||||
"psql", # the psql command
|
||||
"--dbname='#{db_conf.database}'", # connect to database *dbname*
|
||||
"--file='#{@dump_filename}'", # read the dump
|
||||
"--single-transaction", # all or nothing (also runs COPY commands faster)
|
||||
host_argument, # the hostname to connect to
|
||||
"--username=#{db_conf.username}" # the username to connect as
|
||||
host_argument, # the hostname to connect to (if any)
|
||||
username_argument # the username to connect as (if any)
|
||||
].join(" ")
|
||||
end
|
||||
|
||||
|
|
|
@ -80,19 +80,7 @@ module RailsMultisite
|
|||
|
||||
def self.current_hostname
|
||||
config = ActiveRecord::Base.connection_pool.spec.config
|
||||
config[:host_names].nil? ? current_host : config[:host_names].first
|
||||
end
|
||||
|
||||
def self.current_host
|
||||
ActiveRecord::Base.connection_pool.spec.config[:host]
|
||||
end
|
||||
|
||||
def self.current_username
|
||||
ActiveRecord::Base.connection_pool.spec.config[:username]
|
||||
end
|
||||
|
||||
def self.current_password
|
||||
ActiveRecord::Base.connection_pool.spec.config[:password]
|
||||
config[:host_names].nil? ? config[:host] : config[:host_names].first
|
||||
end
|
||||
|
||||
def self.clear_settings!
|
||||
|
|
Loading…
Reference in New Issue