Top Level Namespace
Defined Under Namespace
Modules: Mina
Instance Method Summary collapse
- #backup_tables(table_names) ⇒ Object
- #db_archive ⇒ Object
- #db_credentials(local: false) ⇒ Object
- #db_file ⇒ Object
- #restore_tables ⇒ Object
- #tweak_tables(table_names) ⇒ Object
Instance Method Details
#backup_tables(table_names) ⇒ Object
47 48 49 50 51 |
# File 'lib/mina/db_sync/tasks.rb', line 47 def backup_tables(table_names) db_credentials command %{pg_dump --format=c --no-owner #{tweak_tables(table_names)} $DATABASE > #{db_file}} command "gzip -f #{db_file}" end |
#db_archive ⇒ Object
59 60 61 62 |
# File 'lib/mina/db_sync/tasks.rb', line 59 def db_archive return 'dump.db.gz' if fetch(:local_run) "#{fetch(:shared_path)}/dump.db.gz" end |
#db_credentials(local: false) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 ⇒ Object
64 65 66 67 |
# File 'lib/mina/db_sync/tasks.rb', line 64 def db_file return 'dump.db' if fetch(:local_run) "#{fetch(:shared_path)}/dump.db" end |
#restore_tables ⇒ Object
53 54 55 56 57 |
# File 'lib/mina/db_sync/tasks.rb', line 53 def restore_tables db_credentials command %{gunzip -f #{db_archive}} command %{pg_restore --no-owner --username=$USERNAME --clean --dbname=$DATABASE #{db_file}} end |
#tweak_tables(table_names) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mina/db_sync/tasks.rb', line 69 def tweak_tables(table_names) if table_names.to_a.empty? STDOUT.write "Tables to get: " tables = STDIN.gets.strip else tables = table_names.to_a.join(' ') end tables.split(' ').map { |table| "--table=#{table}" }.join(' ') end |