my face
About Me

Published Posts

All Posts

New Post


View by Tag:

interviewing, code, testing, philosophy, blog, wantmyjob, virtualization, railsmud, heroku, ruby, published, neoarchaeology, railsgame, rails, juggernaut, astrino, cheaptoad, shannaspizza, mongodb, refactorit, devise, rvm, passenger, jruby, programming, vagrant, chef, railsframe, business, codefolio


Online Portfolio

Resume

Profile on LinkedIn

Recommend me on WorkingWithRails: Recommend Me

Re-Import from WordPress

Posted: 2 years ago (2009-04-23 21:43:06 UTC )

I imported a bunch of posts from WordPress. Then, I destroyed my database utterly. Luckily, that has been an excellent chance to go back and fix some bugs in the import... *grin*

Last time, I didn't set the created_at field for the imported blog posts. That meant that they all showed up after everything else I'd written, but they also all showed up within the same couple of seconds. Blog imports are quick. That gave me an excellent chance to debug my sort condition for ordering posts in this blog, since I rolled my own quick pagination code...

So this time, I re-imported everything and set the created_at field to the original post time, and the updated_at field to when I imported them into this blog. The comments are lost, but there weren't many anyway. I'll call it the price of progress -- and of writing the code to more of my own tools.

The import script I used was an opportunity to learn very basic DataMapper. It worked well, but I had to set the default string size. In ActiveRecord, the default string size is 255 for the adapters I looked at, including MySQL and SQLite. In DataMapper, it seems to be 50. In both, it's probably safer to just set it manually... *sigh*

The import script was also a good opportunity to learn REXML. Pretty simple. I'm told that REXML is very slow, but I was importing what, 30 or 40 entries? It literally takes less than two seconds for the whole script to run, so REXML is fine for a project of this size. And hey, it was already installed and has a really simple interface.

Here's the script I used. Because this app currently uses SQLite, I could just copy the database over, import the new items into it, and copy it back. With MySQL, you could point the script at your main database, but then I hope you've backed up recently...

Previous: And then... / Next: Juggernaut test

Edit | Destroy | See All Posts

blog comments powered by Disqus