<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Robby on Rails: Tag fusefs</title>
    <link>http://www.robbyonrails.com/articles/tag/fusefs</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>thoughts.sort_by{|t| t[:topic]}.collect </description>
    <item>
      <title>Migrating from MySQL to PostgreSQL in 60 seconds (with Rails)</title>
      <description>&lt;p&gt;I do quite a few MySQL to PostgreSQL migrations for clients of &lt;a href="http://www.planetargon.com"&gt;&lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt;&lt;/a&gt; and over the years I have gone through different methods of handling this procedure. Typically, it involved exporting data, re-importing it through some shell script that does its best to take into consideration the slight differences between the two databases.&lt;/p&gt;


	&lt;p&gt;While working on a recent project that was to be migrated from &lt;a href="http://sql-info.de/mysql/gotchas.html"&gt;MySQL&lt;/a&gt; to &lt;a href="http://www.postgresql.org"&gt;PostgreSQL&lt;/a&gt;, but after some &lt;a href="http://www.refactoringrails.com"&gt;Refactoring&lt;/a&gt; had been done to the code base. I had been meaning to spend a few hours coming up with some simplified process of taking data from MySQL and replicating it to a new PostgreSQL database, while maintaining  referential integrity.&lt;/p&gt;


	&lt;p&gt;My original idea was to build a script that referenced two seperate databases and then copied data out and inserted it into the new db after performing a few data changes. This seemed like too much work and I knew that I should be able to harness the power of Ruby and Rails in my process. My next thought? &lt;a href="http://redhanded.hobix.com/inspect/railsfsAfterACoupleMinutesOfToolingWithFuseWhoa.html"&gt;RailsFS&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;In a &lt;strong&gt;perfect&lt;/strong&gt; world, I would mount one instance of the application with a mysql database and another with a postgresql database&amp;#8230; and just copy the yaml files to the postgresql and bam, it&amp;#8217;d work, right? Well, it doesn&amp;#8217;t quite work that way. So, I ruled out that idea.&lt;/p&gt;


	&lt;p&gt;Then I had another idea. I would build a task in my Rakefile that&amp;#8230; imported each of those &lt;span class="caps"&gt;YAML&lt;/span&gt; files into PostgreSQL!&lt;/p&gt;


	&lt;p&gt;We can now type in the following commands:&lt;/p&gt;


This first creates my PostgreSQL database tables using Migrations.
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;rake&lt;/span&gt; &lt;span class="ident"&gt;migrate&lt;/span&gt; &lt;span class="constant"&gt;VERSION&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt;&lt;span class="number"&gt;1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;then&amp;#8230;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;rake&lt;/span&gt; &lt;span class="ident"&gt;mysql2pgsql&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;code&gt;mysql2pgsql&lt;/code&gt; runs&amp;#8230;and approx 60 seconds later, I had an exact copy of the MySQL database in PostgreSQL. 

But wait! PostgreSQL has &lt;span class="caps"&gt;SEQUENCES&lt;/span&gt;&amp;#8230; so I then run:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;rake&lt;/span&gt; &lt;span class="ident"&gt;migrate&lt;/span&gt; &lt;span class="constant"&gt;VERSION&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt;&lt;span class="number"&gt;2&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;...and my &lt;span class="caps"&gt;SEQUENCES&lt;/span&gt; are &lt;span class="caps"&gt;ALTER&lt;/span&gt;&amp;#8217;d.&lt;/p&gt;


	&lt;p&gt;Yes, I will post some code in the near future. But all I am doing is basically running through all the &lt;span class="caps"&gt;YAML&lt;/span&gt; files that are available from RailsFS and adding them into the new database. It automatically figures out the model name&amp;#8230;and is fairly generic at the moment. However, I&amp;#8217;d like to spend a bit more time stress-testing it before I post it. :-)&lt;/p&gt;


	&lt;p&gt;I want to try to work on a RailsFS-less version as well so that I can run this on my PowerBook.&lt;/p&gt;


	&lt;p&gt;Until next time&amp;#8230; have fun!&lt;/p&gt;
</description>
      <pubDate>Sat, 29 Oct 2005 14:23:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:b1064070f97315072ad3be65a29dc575</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/10/29/migrating-from-mysql-to-postgresql-in-60-seconds-with-rails</link>
      <category>Ruby on Rails</category>
      <category>PostgreSQL</category>
      <category>rails</category>
      <category>activerecord</category>
      <category>postgresql</category>
      <category>mysql</category>
      <category>fusefs</category>
    </item>
    <item>
      <title>Rails meets FuseFS</title>
      <description>&lt;p&gt;_why has &lt;a href="http://redhanded.hobix.com/inspect/railsfsAfterACoupleMinutesOfToolingWithFuseWhoa.html"&gt;posted an entry&lt;/a&gt; on his blog which shows how to use the &lt;a href="http://rubyforge.org/projects/fusefs"&gt;Ruby FuseFS&lt;/a&gt; library to&amp;#8230; mount Active Record.&lt;/p&gt;


&lt;code&gt;
&lt;pre&gt;
railsmnt]$ cat contact_type/1
--- !ruby/object:ContactType
attributes:
  name: Client
  id: "1" 

 railsmnt]$ for i in `ls`; do echo $i; done
contact
contact_type
&lt;/pre&gt;
&lt;/code&gt;

	&lt;p&gt;Umm&amp;#8230; I am&amp;#8230; I dunno&amp;#8230; (wow)&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ve used FuseFS for mounting &lt;span class="caps"&gt;SSH&lt;/span&gt;&amp;#8230; but found myself using &lt;span class="caps"&gt;SSHFS&lt;/span&gt; as a better alternative.&lt;/p&gt;


	&lt;p&gt;But&amp;#8230; to mount Rails? This could get interesting.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;UPDATE&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;A screenshot while browsing the directory with Konqueror&amp;#8230;and opening the record with Kedit.&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://www.robbyrussell.com/albums/Desktops/railsfs.jpg"&gt;&lt;img src="http://www.robbyrussell.com/albums/Desktops/railsfs.sized.jpg" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;&lt;span class="caps"&gt;UPDATE&lt;/span&gt; #2&lt;/strong&gt;
If you&amp;#8217;re hosting at &lt;a href="http://www.planetargon.com/"&gt;&lt;span class="caps"&gt;PLANET ARGON&lt;/span&gt;&lt;/a&gt;, you can try this out with your account. Both, &lt;span class="caps"&gt;FUSE&lt;/span&gt; and Ruby-FuseFS are installed on all the servers.&lt;/p&gt;
</description>
      <pubDate>Wed, 21 Sep 2005 15:28:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:2be081b80bf04178fb8f56c9578a73d0</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2005/09/21/rails-meets-fusefs</link>
      <category>fusefs</category>
      <category>rails</category>
      <category>activerecord</category>
    </item>
  </channel>
</rss>
