<?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>P(failure &#124; big_shot_present) = .9 &#187; Databases</title>
	<atom:link href="http://blog.e-thang.net/category/databases/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.e-thang.net</link>
	<description>If even 1 person reads this, I will consider that a success</description>
	<lastBuildDate>Wed, 19 Oct 2011 14:52:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>When having trouble installing the mysql gem on OSX</title>
		<link>http://blog.e-thang.net/2010/04/21/when-having-trouble-installing-the-mysql-gem-on-osx/</link>
		<comments>http://blog.e-thang.net/2010/04/21/when-having-trouble-installing-the-mysql-gem-on-osx/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 18:33:09 +0000</pubDate>
		<dc:creator>e-thang</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[mysql gem]]></category>

		<guid isPermaLink="false">http://blog.e-thang.net/?p=89</guid>
		<description><![CDATA[And you get an error like: *** extconf.rb failed *** Go read: http://blog.bmn.name/2008/02/rails-gem-install-mysql-throws-error-extconfrb-failed]]></description>
			<content:encoded><![CDATA[<p>And you get an error like:</p>
<p>*** extconf.rb failed ***</p>
<p>Go read:</p>
<p><a href="http://blog.bmn.name/2008/02/rails-gem-install-mysql-throws-error-extconfrb-failed">http://blog.bmn.name/2008/02/rails-gem-install-mysql-throws-error-extconfrb-failed</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.e-thang.net/2010/04/21/when-having-trouble-installing-the-mysql-gem-on-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Renaming a database in Rails</title>
		<link>http://blog.e-thang.net/2009/12/14/renaming-a-database-in-rails/</link>
		<comments>http://blog.e-thang.net/2009/12/14/renaming-a-database-in-rails/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 17:09:15 +0000</pubDate>
		<dc:creator>e-thang</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[myql]]></category>
		<category><![CDATA[rename database]]></category>

		<guid isPermaLink="false">http://blog.e-thang.net/?p=54</guid>
		<description><![CDATA[Hooray for a non-rant post! The heart of this method works outside of Rails, but there&#8217;s one particular convenience method that Rails provides.  Find some way to mimic that behavior, and the rest would apply.  Also, this is a MySQL-specific solution.  I haven&#8217;t tried it with any other DB systems. We &#8220;rename&#8221; a database by [...]]]></description>
			<content:encoded><![CDATA[<p>Hooray for a non-rant post!</p>
<p>The heart of this method works outside of Rails, but there&#8217;s one particular convenience method that Rails provides.  Find some way to mimic that behavior, and the rest would apply.  Also, this is a MySQL-specific solution.  I haven&#8217;t tried it with any other DB systems.</p>
<p>We &#8220;rename&#8221; a database by moving all of its tables into a new database.  We do so via <a title="MySQL RENAME TABLE Syntax" href="http://dev.mysql.com/doc/refman/5.0/en/rename-table.html">MySQL&#8217;s RENAME TABLE command</a>.  Basically, create an empty database with the new name.  We then use our ActiveRecord connection&#8217;s &#8220;tables&#8221; method to loop over all the tables in our database, executing a RENAME TABLE from the old to the new with each iteration.  &#8220;Tables&#8221; is the convenience method I mentioned above. Encapsulating this in a method we get:</p>
<pre>def rename_database(old_db_name, new_db_name)
    ActiveRecord::Base.connection.execute "CREATE DATABASE #{new_db_name}"
    ActiveRecord::Base.connection.tables.each do |table|
        ActiveRecord::Base.connection.execute
            "RENAME TABLE #{old_db_name}.#{table} TO #{new_db_name}.#{table}"
    end
    ActiveRecord::Base.connection.execute "DROP DATABASE #{old_db_name}"
end</pre>
<p>Error checking is left as an (important!) exercise to the reader.  Also, you may prefer to monkey patch this into ActiveRecord itself as opposed to some odd method floating around in global space.</p>
<p>This presupposes that the new database destination will be on the same server.</p>
<p>Another way to rename a database is to mysqldump the old one to a file and then reimport it to the renamed database.  The method presented in this article is advantageous if your database has a large amount of data.  Renaming a table is almost instant.  <strong>Dumping millions of rows and reimporting them is not so instant.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.e-thang.net/2009/12/14/renaming-a-database-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

