TracksApp / tracks

Tracks is a GTD™ web application, built with Ruby on Rails
https://www.getontracks.org/
GNU General Public License v2.0
1.18k stars 538 forks source link

Guide for implementing YAML import #2441

Open mattr- opened 4 years ago

mattr- commented 4 years ago

I just moved hosting providers for my Tracks instance, and exported YAML, and reimported it. Since YAML import isn't implemented, I had to do it by hand from a console. If this functionality is desired, here is some notes about how I did it:


Rails' autoloading was fun here, perhaps because i did this in a development environment console rather than a production console? Not sure. Either way, I had to require a bunch of model classes before the YAML would even parse correctly when loaded from disk.


Import order:

For referential integrity purposes, the ordering is pretty important, since there's all sorts of ids in the yaml export. The order above allowed me to import everything keep everything linked properly.


When load in the YAML, you get actual objects. Calling save on them does nothing though, because ActiveRecord thinks they're not needing to be saved. I had to use create with the attributes with something like:

yaml["contexts"].each { |item| Context.create(item.attributes) }

One of the reasons this was so successful is because i have a single user instances of tracks that isn't very busy. We'd have to make serious considerations for things like multiple users, different ids for model data, etc.

Feel free to close this after reading. I just wanted to share the information. :smiley:

ZeiP commented 4 years ago

I think this is a valid issue, it'd be good to have better import capabilities for our own exports. Thanks for the good start!