<?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>I.NFECTIO.US: More Advanced Rails Schema Generation</title>
    <link>http://i.nfectio.us/articles/2006/03/05/more-advanced-rails-schema-generation</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>"Nothing in life is worth doing if you have no life while doing it"</description>
    <item>
      <title>More Advanced Rails Schema Generation</title>
      <description>&lt;p&gt;One of the problems I've seen with Rails as of late is that the database schemas for the unit tests get out of sync with each other.
As new features get added, some db_definitions get updated and others missed. The core group is well aware of this issue and DHH left a
challenge in a &lt;a href="http://dev.rubyonrails.org/ticket/3993"&gt;ticket&lt;/a&gt; I created to add missing table definitions from a previous changeset.&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
I decided I would take him up on his challenge and went to work. I printed off all the db schemas and started comparing them with each other,  highlighting where they differed.
This was my first indication as to the scope of this conversion.&lt;/p&gt;
&lt;br /&gt;
&lt;p&gt;
Since the purpose of converting over to using schema.rb is to maintain one schema for all the tests, it would be helpful if all the existing definitions were at least similar to begin with. Most of the differences can be fixed without issue. Converting a varchar(3000) field to text, or a timestamp to datetime is no big deal as far as the unittests are concerned.
The biggest road block is that some tables are defined using features that don't exist in AR::Schema. Features like foreign keys, arbitrary primary keys and sequences. User-defined column definitions is yet another example where AR::Schema isn't up to the job. For example, the Postgres tests use a table with geometric field types.&lt;/p&gt;
&lt;br /&gt;&lt;p&gt;I had a pretty good idea how to implement everything except for sequences, so I started coding and within a few hours had the test suite working with MySQL using schema.rb. Before I dove much further into making all the adapters work with schema.rb, I decided I
better get some feedback on whether these changes I was making to Rails schema generation would even be accepted into core. Unfortunately, I didn't get any feedback from the core developers.&lt;/p&gt;
&lt;br /&gt;&lt;p&gt;
I think the biggest issue they would raise is whether or not the SchemaDumper would be able dump these changes. The short answer is no, which coincidently, is 
probably the same answer my patch would get. So I scrapped my work on converting the unittests over but will consider making a plugin which adds this functionality (and much more) for more advanced schema generation/migrations. You just won't be able to dump your schema out into a schema.rb file.&lt;/p&gt;
&lt;br /&gt;&lt;p&gt; 
Let me know if you think this would be useful and I'll put something together.&lt;/p&gt;</description>
      <pubDate>Sun, 05 Mar 2006 00:17:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:516eaa9b3dc90c9131aebe1f57375f4d</guid>
      <author>Bob Silva</author>
      <link>http://i.nfectio.us/articles/2006/03/05/more-advanced-rails-schema-generation</link>
      <category>Ruby on Rails</category>
    </item>
    <item>
      <title>"More Advanced Rails Schema Generation" by Matt Scilipoti</title>
      <description>I am interested in this patch/plugin.  Since Migrations were first introduced, I have not had a reason to use the schema.rb.  Who does?  Why?  Should they be using Migrations instead?  It certainly is possible/probable that there is some Rails magic which requires the schema.rb.  If there is, should it be using schema.rb?  

All this being said, it sounds like this is exactly the sort of thing plugins are designed for.  Please share.  I would be happy to help upgrade the other Adapters, if required.</description>
      <pubDate>Sun, 08 Oct 2006 19:03:44 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:b6196ece-1474-46de-986e-59012b76cace</guid>
      <link>http://i.nfectio.us/articles/2006/03/05/more-advanced-rails-schema-generation#comment-180</link>
    </item>
  </channel>
</rss>
