class Object
Public Instance Methods
backup_command(table_names)
click to toggle source
# File lib/mina/db_sync/tasks.rb, line 93 def backup_command(table_names) if postgres? command %{pg_dump --format=c --no-owner #{tweak_tables(table_names)} $DATABASE > #{db_file}} return end if mysql? command %{mysqldump -u$USERNAME --password="$PASSWORD" $DATABASE #{tweak_tables(table_names)} > #{db_file}} end end
backup_tables(table_names)
click to toggle source
# File lib/mina/db_sync/tasks.rb, line 47 def backup_tables(table_names) db_credentials backup_command(table_names) command "gzip -f #{db_file}" end
db_archive()
click to toggle source
# File lib/mina/db_sync/tasks.rb, line 60 def db_archive return 'dump.db.gz' if fetch(:local_run) "#{fetch(:shared_path)}/dump.db.gz" end
db_credentials(local: false)
click to toggle source
# File lib/mina/db_sync/tasks.rb, line 33 def db_credentials(local: false) if fetch(:local_run) db = 'config/database.yml' db_type = 'development' else db = fetch(:shared_path) + '/config/database.yml' db_type = 'production' end %w(username password database).each do |val| command %{#{val.upcase}=$(ruby -ryaml -e 'puts YAML.load_file("#{db}")["#{db_type}"]["#{val}"]')} end end
db_file()
click to toggle source
# File lib/mina/db_sync/tasks.rb, line 65 def db_file return 'dump.db' if fetch(:local_run) "#{fetch(:shared_path)}/dump.db" end
mysql?()
click to toggle source
# File lib/mina/db_sync/tasks.rb, line 89 def mysql? fetch(:db_sync_database) == 'mysql' end
postgres?()
click to toggle source
# File lib/mina/db_sync/tasks.rb, line 85 def postgres? fetch(:db_sync_database) == 'postgres' end
restore_command()
click to toggle source
# File lib/mina/db_sync/tasks.rb, line 104 def restore_command if postgres? command %{pg_restore --no-owner --username=$USERNAME --clean --dbname=$DATABASE #{db_file}} return end if mysql? command %{mysql -u$USERNAME --password="$PASSWORD" $DATABASE < #{db_file}} end end
restore_tables()
click to toggle source
# File lib/mina/db_sync/tasks.rb, line 53 def restore_tables db_credentials command %{gunzip -f #{db_archive}} restore_command command %{rm #{db_file}} unless fetch(:db_sync_debug) end
tweak_tables(table_names)
click to toggle source
# File lib/mina/db_sync/tasks.rb, line 70 def tweak_tables(table_names) if table_names.to_a.empty? STDOUT.write "Enter table name(s), separated by a space: " tables = STDIN.gets.strip else tables = table_names.to_a.join(' ') end return tables if mysql? if postgres? return tables.split(' ').map { |table| "--table=#{table}" }.join(' ') end end