{"id":588,"date":"2007-02-07T20:24:15","date_gmt":"2007-02-08T01:24:15","guid":{"rendered":"http:\/\/blogs.law.harvard.edu\/hoanga\/2007\/02\/07\/migrating-instiki-from-one-database-ty"},"modified":"2007-02-16T18:26:02","modified_gmt":"2007-02-16T23:26:02","slug":"migrating-instiki-from-one-database-type-to-another","status":"publish","type":"post","link":"https:\/\/archive.blogs.harvard.edu\/hoanga\/2007\/02\/07\/migrating-instiki-from-one-database-type-to-another\/","title":{"rendered":"Migrating instiki from one database type to another"},"content":{"rendered":"<h3>The Rant<\/h3>\n<p><a href=\"http:\/\/instiki.org\">Instiki<\/a> is one of the premier wikis for <a href=\"http:\/\/www.rubyonrails.org\">Ruby on Rails<\/a> which is another way of saying the other rails-based solutions don&#8217;t look that great so far from what I&#8217;ve seen.  Here is an except from the instiki website:<\/p>\n<blockquote><p>\n   1.  Download<br \/>\n   2. Run \u201cinstiki\u201d with Ruby 1.8.4 or greater. (on windows, that\u2019s instiki.cmd)<br \/>\n   3. Chuckle\u2026 There Is No Step Three\u2122! \ud83d\ude42 (See note) \n<\/p><\/blockquote>\n<p>Yeah, nice and simple&#8230; <b>to install<\/b>.   Here&#8217;s some facts that instiki DOESN&#8217;T tell you without digging around:<\/p>\n<ul>\n<li>It uses <a href=\"http:\/\/www.sqlite.org\">sqlite<\/a> as its database backend to store all wiki information (except images and file uploads).<\/li>\n<li>It&#8217;s NOT Rails 1.2.x ready<\/li>\n<li>It was written BEFORE ActiveRecord and was migrated to ActiveRecord later<\/li>\n<li>You can export your data but have no way to import your data easily (more later)<\/li>\n<li>The documentation from a USER perspective is pretty sparse<\/li>\n<li>Active development seems to be moving at a snail&#8217;s crawl<\/li>\n<\/ul>\n<p>So what does this all mean?  Well, if you want to migrate your <a href=\"http:\/\/instiki.org\">instiki<\/a> instance to a different instance you&#8217;d like to think you have a couple of options.<\/p>\n<ol>\n<li>Just copy the whole application to the new server, kickstart done <em>(This works)<\/em><\/li>\n<li>Dump out the wiki in some export friendly format and re-import it back in<\/li>\n<\/ol>\n<p>Option #1 works quite well however if you want to switch database backends you&#8217;re stuck with option #2.  However save yourself hours of time (I didn&#8217;t) and <b>DON&#8217;T<\/b> try the following things (unless you&#8217;re a rails god.  In which case why are you reading this?)<\/p>\n<ul>\n<li>Try exporting the wiki in textile format and importing it&#8230;.  oops import is busted.  A stub is there (http:\/\/localhost:2500\/wiki\/import) but it is definitely broken<\/li>\n<li>Dump the sqlite database with sqlite utilities then re-import them into target database.  This doesn&#8217;t work with MySQL as far as I know.  I bet it&#8217;s broken with Postgresql too<\/li>\n<li>Look at the <a href=\"http:\/\/dev.instiki.org\/log\/instiki\/trunk\/app\/controllers\/file_controller.rb\">source code<\/a><br \/>\nto find where the issue might be.   Don&#8217;t worry, even the changelogs say import is busted and there is no other sign of some way to input data easily<\/li>\n<li>Write some tool to import textile in.  That would require reading the APIs, right?  bleh<\/li>\n<li>Write some sort of ActiveRecord translator?  Well sort of&#8230; but it&#8217;d be nice if there was a tool available.  And if you&#8217;re not a rails guru you&#8217;re sort of screwed in this case.<\/li>\n<\/ul>\n<p>Now I&#8217;m sure <a href=\"http:\/\/www.loudthinking.com\/\">DHH<\/a> (the creator of instiki) will grumble about something about this not being &#8216;appropriate&#8217; for its original intentions and blah-blah.  Gee that&#8217;s nice.  Maybe you better put that down in the caveats, before I commit a whole bunch of data into it.<\/p>\n<h3>The Fix<\/h3>\n<p>Okay, enough ranting about half-baked Open Source Rails apps.  Here&#8217;s the fix.<\/p>\n<h5>1. Add plugin script to instiki app<\/h5>\n<p>Most normal rails app will include a file called plugin inside $RAILS_ROOT\/script\/plugin.   Unfortunately, instiki doesn&#8217;t include it.  Luckily the script is really small since it just calls out to the rails framework to handle most of the hardwork.  So try this:<\/p>\n<blockquote>\n<pre>\r\n$ echo \"\r\n#!\/usr\/bin\/env ruby\r\nrequire File.dirname(__FILE__) + '\/..\/config\/boot'\r\nrequire 'commands\/plugin'\r\n\" &gt;&gt; $INSTIKI_HOME\/script\/plugins\r\n$ chmod +x $INSTIKI_HOME\/script\/plugin  # Make it executable\r\n<\/pre>\n<\/blockquote>\n<h5>2. Install the <a href=\"http:\/\/svn.toolbocks.com\/plugins\/manage_fixtures\/\">manage_fixtures<\/a> plugin<\/h5>\n<p>\nI&#8217;m afraid I don&#8217;t have time to explain what a <a href=\"http:\/\/wiki.rubyonrails.org\/rails\/pages\/ActiveRecordYamlFixtures\">Rails Fixture<\/a> is in this post but just think of it as a portable way of representing data going into a database for rails.  It works well but don&#8217;t try hundreds of megabytes of data.\n<\/p>\n<p>\nI also won&#8217;t go much into <a href=\"http:\/\/wiki.rubyonrails.org\/rails\/pages\/Plugins\">rails plugins<\/a> except to say it&#8217;s a way of extending a rails application with more functionality (probably for a Rails developer rather than an end user of the application).   We&#8217;re going to use a really sweet tool called <a href=\"http:\/\/svn.toolbocks.com\/plugins\/manage_fixtures\/\">manage_fixtures<\/a> which allows us to move around data between different databases with ease (assuming the rails app isn&#8217;t doing weird SQL crap).\n<\/p>\n<blockquote>\n<pre>\r\n$ cd $INSTIKI_HOME\r\n$ script\/plugin discover    # Hit enter a gazillion times\r\n$ script\/plugin install manage_fixtures\r\n<\/pre>\n<\/blockquote>\n<h5>3. Export the data into fixtures<\/h5>\n<p>The following will export all your db entries as fixtures into <em>$INSTIKI_HOME\/test\/fixtures<\/em>.  You need to set the RAILS_ENV to production because by default it will try to use the development database.<\/p>\n<blockquote>\n<pre>\r\n$ cd $INSTIKI_HOME         # You SHOULD be here anyways\r\n$ RAILS_ENV='production' rake  db:fixtures:export_all\r\n<\/pre>\n<\/blockquote>\n<h5>4. Change the database connection to desired<\/h5>\n<p>Now change the file in <em>$INSTIKI_HOME\/config\/databases.yml<\/em> from:<\/p>\n<blockquote>\n<pre>\r\nproduction:\r\n  adapter: sqlite3\r\n  database: db\/production.db.sqlite3\r\n<\/pre>\n<\/blockquote>\n<p>to the following (adjust mysql parameters to suit your setup)<\/p>\n<blockquote>\n<pre>\r\nproduction:\r\n  adapter: mysql\r\n  host: localhost\r\n  database: instiki\r\n  username: root\r\n  password:\r\n<\/pre>\n<\/blockquote>\n<h5>4. Create database and the appropriate tables<\/h5>\n<p>The following commands will create a database named instiki (or whatever you put in databases.yml) and make sure the database schema in the database matches instiki&#8217;s schema.<\/p>\n<blockquote>\n<pre>\r\n$ echo \"create database instiki\" | mysql -u root\r\n$ RAILS_ENV='production' rake migrate\r\n<\/pre>\n<\/blockquote>\n<h5>5. Finally re-import the data from fixtures<\/h5>\n<p>Whew!  Finally we can re-import the data into MySQL (or whatever) and continue on using instiki for something.<\/p>\n<blockquote>\n<pre>\r\n$  RAILS_ENV='production' rake db:fixtures:import_all\r\n<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>The Rant Instiki is one of the premier wikis for Ruby on Rails which is another way of saying the other rails-based solutions don&#8217;t look that great so far from what I&#8217;ve seen. Here is an except from the instiki website: 1. Download 2. Run \u201cinstiki\u201d with Ruby 1.8.4 or greater. (on windows, that\u2019s instiki.cmd) [&hellip;]<\/p>\n","protected":false},"author":703,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1216,1215,615,260],"tags":[],"class_list":["post-588","post","type-post","status-publish","format-standard","hentry","category-fixes","category-gripe","category-ruby","category-tech"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/posts\/588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/users\/703"}],"replies":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/comments?post=588"}],"version-history":[{"count":0,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/posts\/588\/revisions"}],"wp:attachment":[{"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/media?parent=588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/categories?post=588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/hoanga\/wp-json\/wp\/v2\/tags?post=588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}