<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kartar.Net &#187; sqlite3</title>
	<atom:link href="http://www.kartar.net/category/sqlite3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kartar.net</link>
	<description>the truth about a man lies in what he hides</description>
	<lastBuildDate>Fri, 30 Jul 2010 00:25:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Migrating a Rails database from Sqlite3 to MySQL</title>
		<link>http://www.kartar.net/2008/08/migrating-a-rails-database-from-sqlite3-to-mysql/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=migrating-a-rails-database-from-sqlite3-to-mysql</link>
		<comments>http://www.kartar.net/2008/08/migrating-a-rails-database-from-sqlite3-to-mysql/#comments</comments>
		<pubDate>Sun, 24 Aug 2008 15:14:02 +0000</pubDate>
		<dc:creator>kartar</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[puppet]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[redmine]]></category>
		<category><![CDATA[sqlite]]></category>
		<category><![CDATA[sqlite3]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[is]]></category>
		<category><![CDATA[on]]></category>
		<category><![CDATA[recon]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[So when I first looked at <a href="http://www.redmine.org">Redmine</a> I ran it up and used Sqlite3 as the database back-end.  Then when I migrated our Trac data I just left Sqlite3 as the back-end database and migrated our data to that.  With that startling being of forthought aside, I always had the view the database should be MySQL because well:

a) I know it 
b) I like it
c) It's probably more scalable (IMHO)

So today I actually sat down to do the migration piece.  I dumped out the sqlite3 database and tried to do some manual/scripted edits to convert it to something MySQL would import.  Epic Fail.  

So I tried the <a href="http://agilewebdevelopment.com/plugins/manage_fixtures>manage_fixtures plug-in</a> to try to output the data as a test fixture and then re-import to another database.  Partial success but some bad data in there somewhere because Redmine went a-o-t in fairly short order after I tested it.

Finally, me and Google stumbled across this nifty plug-in called <a href="http://blog.heroku.com/archives/2007/11/23/yamldb_for_databaseindependent_data_dumps/">YAMLdb</a> that abstracts database exports using YAML.  A quick installation, some edits to config/database.yml, a rake db:dump and rake db:load and the data was moved:

... Create our database ...
<code>
$ sudo mysql -p
mysql> create database redmine character set utf8;
</code>
... Grant privs to your chosen user ...
<code>
mysql> GRANT ...
</code>
... Configure a test database for our new MySQL database ...
<code>
$ vim config/database.yml
</code>
.. install the plugin ...
<code>
$ sudo script/plugin install http://opensource.heroku.com/svn/rails_plugins/yaml_db
</code>
... Dump out the current production database ...
<code>
$ sudo rake db:dump RAILS_ENV=production
</code>
... Load the freshly created db/data.yml file into our test database ...
<code>
$ sudo rake db:load RAILS_ENV=test
</code>
... Reconfigure the application to point to the new MySQL database as production ...
<code>
$ vim config/database.yml
</code>
... Start Redmine ...
<code>
$ sudo /etc/init.d/mongrel_cluster start
</code>

Had one bad field I had to do some manual editing too - still not quite sure what was wrong with the field but whatever I did fixed it - but otherwise very smooth.

Started up and now Redmine runs perfectly with MySQL as the back-end!  ]]></description>
			<content:encoded><![CDATA[<p>So when I first looked at <a href="http://www.redmine.org">Redmine</a> I ran it up and used Sqlite3 as the database back-end.  Then when I migrated our Trac data I just left Sqlite3 as the back-end database and migrated our data to that.  With that startling lack of forethought aside, I always had the view the database should be MySQL because well:</p>
<p>a) I know it<br />
b) I like it<br />
c) It&#8217;s probably more scalable (IMHO)</p>
<p>So today I actually sat down to do the migration piece.  I dumped out the sqlite3 database and tried to do some manual/scripted edits to convert it to something MySQL would import.  Epic Fail.</p>
<p>So I tried the <a href="http://blog.heroku.com/archives/2007/11/23/yamldb_for_databaseindependent_data_dumps/">YAMLdb</a> that abstracts database exports using YAML.  A quick installation, some edits to config/database.yml, a rake db:dump and rake db:load and the data was moved:</p>
<p>&#8230; Create our database &#8230;<br />
<code><br />
$ sudo mysql -p<br />
mysql&gt; create database redmine character set utf8;<br />
</code><br />
&#8230; Grant privs to your chosen user &#8230;<br />
<code><br />
mysql&gt; GRANT ...<br />
</code><br />
&#8230; Configure a test database for our new MySQL database &#8230;<br />
<code><br />
$ vim config/database.yml<br />
</code><br />
.. for Rails version 2.1 and later install the plugin &#8230;<br />
<code><br />
$ sudo script/plugin install </code><code><a href="http://www.kartar.net/tag/git/" class="st_tag internal_tag" rel="tag" title="Posts tagged with git">git</a>://<a href="http://www.kartar.net/tag/github/" class="st_tag internal_tag" rel="tag" title="Posts tagged with github">github</a>.com/adamwiggins/yaml_db.<a href="http://www.kartar.net/tag/git/" class="st_tag internal_tag" rel="tag" title="Posts tagged with git">git</a><br />
</code><br />
.. for Rails versions less than 2.1 use &#8230;<code></code><br />
<code><br />
$ sudo script/plugin install http://<a href="http://www.kartar.net/tag/github/" class="st_tag internal_tag" rel="tag" title="Posts tagged with github">github</a>.com/adamwiggins/yaml_db.<a href="http://www.kartar.net/tag/git/" class="st_tag internal_tag" rel="tag" title="Posts tagged with git">git</a><br />
</code><br />
&#8230; Dump out the current production database &#8230;<br />
<code><br />
$ sudo rake db:dump RAILS_ENV=production<br />
</code><br />
&#8230; Load the freshly created db/data.yml file into our test database &#8230;<br />
<code><br />
$ sudo rake db:load RAILS_ENV=test<br />
</code><br />
&#8230; Reconfigure the application to point to the new MySQL database as production &#8230;<br />
<code><br />
$ vim config/database.yml<br />
</code><br />
&#8230; Start Redmine &#8230;<br />
<code><br />
$ sudo /etc/init.d/mongrel_cluster start<br />
</code></p>
<p>Had one bad field I had to do some manual editing too &#8211; still not quite sure what was wrong with the field but whatever I did fixed it &#8211; but otherwise very smooth.</p>
<p>Started up and now Redmine runs perfectly with MySQL as the back-end!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kartar.net/2008/08/migrating-a-rails-database-from-sqlite3-to-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
