Module: MysqlToPgDump::TasksHelper
- Defined in:
- lib/mysql_to_pg_dump/tasks_helper.rb
Instance Method Summary collapse
- #clean_database ⇒ Object
- #data_already_pulled? ⇒ Boolean
- #db_tables ⇒ Object
- #dev ⇒ Object
- #file_to_save(table_name, location) ⇒ Object
- #login_to_mysql ⇒ Object
- #production ⇒ Object
- #psql_import_query(table_name) ⇒ Object
- #server_addr_input ⇒ Object
- #show_db_info(env) ⇒ Object
- #sql_select(table_name) ⇒ Object
- #uniq_dir_location ⇒ Object
- #uniq_string ⇒ Object
Instance Method Details
#clean_database ⇒ Object
24 25 26 27 |
# File 'lib/mysql_to_pg_dump/tasks_helper.rb', line 24 def clean_database task_names = %w(db:drop db:create db:migrate) task_names.each { |t| Rake::Task[t].invoke } end |
#data_already_pulled? ⇒ Boolean
10 11 12 13 14 15 16 |
# File 'lib/mysql_to_pg_dump/tasks_helper.rb', line 10 def data_already_pulled? if %x{ls tmp}.split("\n").include? 'db_server_data' %x(ls tmp/db_server_data).split("\n").size == db_tables.size else false end end |
#db_tables ⇒ Object
44 45 46 |
# File 'lib/mysql_to_pg_dump/tasks_helper.rb', line 44 def db_tables ActiveRecord::Base.connection.tables - ['schema_migrations'] end |
#dev ⇒ Object
62 63 64 |
# File 'lib/mysql_to_pg_dump/tasks_helper.rb', line 62 def dev show_db_info 'development' end |
#file_to_save(table_name, location) ⇒ Object
36 37 38 |
# File 'lib/mysql_to_pg_dump/tasks_helper.rb', line 36 def file_to_save table_name, location "#{location}/#{production['database']}_#{table_name}.csv" end |
#login_to_mysql ⇒ Object
29 30 31 32 33 34 |
# File 'lib/mysql_to_pg_dump/tasks_helper.rb', line 29 def login_to_mysql "mysql " \ "--user=#{production['username']} " \ "--password=#{production['password']} " \ "#{production['database']}" end |
#production ⇒ Object
66 67 68 |
# File 'lib/mysql_to_pg_dump/tasks_helper.rb', line 66 def production show_db_info 'production' end |
#psql_import_query(table_name) ⇒ Object
18 19 20 21 22 |
# File 'lib/mysql_to_pg_dump/tasks_helper.rb', line 18 def psql_import_query table_name "\\copy #{table_name} from " \ "'tmp/db_server_data/#{production['database']}_#{table_name}.csv' " \ "delimiter E'\\t' null as 'NULL' csv header" end |
#server_addr_input ⇒ Object
5 6 7 8 |
# File 'lib/mysql_to_pg_dump/tasks_helper.rb', line 5 def server_addr_input printf "Enter server address like '[email protected]': " STDIN.gets.strip end |
#show_db_info(env) ⇒ Object
58 59 60 |
# File 'lib/mysql_to_pg_dump/tasks_helper.rb', line 58 def show_db_info env Rails.application.config.database_configuration[env] end |
#sql_select(table_name) ⇒ Object
40 41 42 |
# File 'lib/mysql_to_pg_dump/tasks_helper.rb', line 40 def sql_select table_name "SELECT * FROM #{table_name};" end |
#uniq_dir_location ⇒ Object
48 49 50 |
# File 'lib/mysql_to_pg_dump/tasks_helper.rb', line 48 def uniq_dir_location "app/current/tmp/db_server_data/#{uniq_string}" end |
#uniq_string ⇒ Object
52 53 54 55 56 |
# File 'lib/mysql_to_pg_dump/tasks_helper.rb', line 52 def uniq_string s = "" 20.times { s << ('0'..'9').to_a.sample } s end |