Git Product home page Git Product logo

ddd1600 / database_to_database_json_transfer_semiautomatic_tools Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 116 KB

I plan on writing a gem which fully automates this task (transferring databases of information via json text output), but for now this is a set of ruby scripts which greatly facilitate the database to database transfer process, in this case via actual (JSON) text files, which are very handy for fail-safe backup purposes.

Ruby 100.00%

database_to_database_json_transfer_semiautomatic_tools's Introduction

These scripts, together, allow for a 5 minute beginning to end transfer process (including database creation) of all the data from one table in a source rails app to an identical table in a destination rails app. I plan on one day compiling all of this into a gem.

  1. add this line of code (or equiv) to both (source and destination) rails application’s config/application.rb files (this line adds the /lib folder and all included files and folders within)

    config.autoload_paths += Dir["#{config.root}/lib/**/"]
    
  2. add all of the scripts (except for example_migration.rb) included within to both rails applications in their lib folders.

  3. in the destination app, generate a model for every table you’d like to clone from the source app. this works best if you use the same model names in both.

  4. now to dump the json data, in the source app console (rails c), run ‘OutputRecordsToJsonText.go(ModelName.all)`for each table to be cloned, where ModelName is the model/models_table, and ’all’ is one of any rails calls you could make (the method simply takes an array of arrays and converts its directly into json)

  5. in the source application console, run: ‘PrepForExport.go(ModelName)` for each table you’d like to clone.

    • copy and paste each outputted array into the column migration you’ve generated in the destination app, and replace the code INSIDE the create_table block like so:

      ary = [[:id, "integer"], [:institution_id, "integer"], [:name, "text"], [:address, "text"], [:city, "text"], [:state, "text"], [:zip, "text"], [:phone, "text"], [:institution_opeid, "text"], [:institution_ipeds_unitid, "text"], [:web_address, "text"], [:created_at, "datetime"], [:updated_at, "datetime"], [:longitude, "float"], [:latitude, "float"], [:ipeds_unit_id, "integer"], [:ope_id, "integer"], [:zip_code, "integer"], [:total_enrollment_2011, "integer"], [:total_enrollment_2003, "integer"], [:pctg_total_enrollment_change, "float"], [:c_class, "boolean"], [:b_class, "boolean"], [:a_class, "boolean"], [:cc_class, "boolean"], [:bb_class, "boolean"], [:aa_class, "boolean"], [:ccc_class, "boolean"], [:bbb_class, "boolean"], [:aaa_class, "boolean"], [:endowment_2011, "integer"], [:endowment_2010, "integer"], [:endowment_2009, "integer"], [:endowment_2008, "integer"], [:endowment_2007, "integer"], [:endowment_2006, "integer"], [:endowment_2004, "integer"], [:endowment_2000, "integer"], [:endowment_1996, "integer"], [:endowment_1991, "integer"], [:endowment_1986, "integer"], [:endowment_1980, "integer"], [:private_school, "boolean"]]
      ary.each do |a|
        eval("t.#{a[1]} a[0]")
      end
      
  6. add any extra columns you’d like, and ‘rake db:migrate`. Check the schema.rb to make sure everything came out alright.

  7. copy and paste all of the JSON dumped into the lib/assets folder of your source app into the lib/assets folder of your destination app

  8. in the destination app rails console, run ‘LoadJsonToDatabase.go(ModelName)` for each

  9. You’re done!

Be on the lookout for a gem which further facilitates this process

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.