BUGFIX: restore wasn't working when not using multisite in production

This commit is contained in:
Régis Hanol 2014-02-20 18:42:17 +01:00
parent b696c96a19
commit 1f90f3044f
4 changed files with 21 additions and 30 deletions

View File

@ -94,6 +94,7 @@ module BackupRestore
-- move all "source" tables to "destination" schema -- move all "source" tables to "destination" schema
FOR row IN SELECT tablename FROM pg_tables WHERE schemaname = '#{source}' FOR row IN SELECT tablename FROM pg_tables WHERE schemaname = '#{source}'
LOOP LOOP
EXECUTE 'DROP TABLE IF EXISTS #{destination}.' || quote_ident(row.tablename) || ' CASCADE;';
EXECUTE 'ALTER TABLE #{source}.' || quote_ident(row.tablename) || ' SET SCHEMA #{destination};'; EXECUTE 'ALTER TABLE #{source}.' || quote_ident(row.tablename) || ' SET SCHEMA #{destination};';
END LOOP; END LOOP;
END$$; END$$;
@ -104,8 +105,8 @@ module BackupRestore
def self.database_configuration def self.database_configuration
if Rails.env.production? if Rails.env.production?
conn = RailsMultisite::ConnectionManagement db = ActiveRecord::Base.connection_pool.spec.config
db_conf = DatabaseConfiguration.new(conn.current_host, conn.current_username, conn.current_password, conn.current_db) db_conf = DatabaseConfiguration.new(db["host"], db["username"], db["password"], db["database"])
else else
db = Rails.configuration.database_configuration[Rails.env] db = Rails.configuration.database_configuration[Rails.env]
db_conf = DatabaseConfiguration.new(db["host"], db["username"], db["password"], db["database"]) db_conf = DatabaseConfiguration.new(db["host"], db["username"], db["password"], db["database"])

View File

@ -156,16 +156,17 @@ module Export
password_argument = "PGPASSWORD=#{db_conf.password}" if db_conf.password.present? 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 [ password_argument, # pass the password to pg_dump (if any)
"pg_dump", # the pg_dump command "pg_dump", # the pg_dump command
"--schema=public", # only public schema "--schema=public", # only public schema
"--file='#{@dump_filename}'", # output to the dump.sql file "--file='#{@dump_filename}'", # output to the dump.sql file
"--no-owner", # do not output commands to set ownership of objects "--no-owner", # do not output commands to set ownership of objects
"--no-privileges", # prevent dumping of access privileges "--no-privileges", # prevent dumping of access privileges
"--verbose", # specifies verbose mode "--verbose", # specifies verbose mode
host_argument, # the hostname to connect to host_argument, # the hostname to connect to (if any)
"--username=#{db_conf.username}", # the username to connect as username_argument, # the username to connect as (if any)
db_conf.database # the name of the database to dump db_conf.database # the name of the database to dump
].join(" ") ].join(" ")
end end

View File

@ -204,14 +204,15 @@ module Import
password_argument = "PGPASSWORD=#{db_conf.password}" if db_conf.password.present? 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 "psql", # the psql command
"--dbname='#{db_conf.database}'", # connect to database *dbname* "--dbname='#{db_conf.database}'", # connect to database *dbname*
"--file='#{@dump_filename}'", # read the dump "--file='#{@dump_filename}'", # read the dump
"--single-transaction", # all or nothing (also runs COPY commands faster) "--single-transaction", # all or nothing (also runs COPY commands faster)
host_argument, # the hostname to connect to host_argument, # the hostname to connect to (if any)
"--username=#{db_conf.username}" # the username to connect as username_argument # the username to connect as (if any)
].join(" ") ].join(" ")
end end

View File

@ -80,19 +80,7 @@ module RailsMultisite
def self.current_hostname def self.current_hostname
config = ActiveRecord::Base.connection_pool.spec.config config = ActiveRecord::Base.connection_pool.spec.config
config[:host_names].nil? ? current_host : config[:host_names].first config[:host_names].nil? ? config[: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]
end end
def self.clear_settings! def self.clear_settings!