<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: migration code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 00:37:37 GMT</pubDate>
    <description>DZone Snippets: migration code</description>
    <item>
      <title>Converting Mysql Tables in InnoDB</title>
      <link>http://snippets.dzone.com/posts/show/4327</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class ConvertMysqlToInnodb &lt; ActiveRecord::Migration&lt;br /&gt; def self.up&lt;br /&gt;   config = ActiveRecord::Base.configurations&lt;br /&gt;   begin&lt;br /&gt;     STDERR.puts "Migrating all existing tables to InnoDB"&lt;br /&gt;     schema = []&lt;br /&gt;     select_all('SHOW TABLES').inject([]) do |schema, table|&lt;br /&gt;       schema &lt;&lt; "ALTER TABLE #{table.to_a.first.last} ENGINE=InnoDB"&lt;br /&gt;     end&lt;br /&gt;     schema.each { |line| execute line }&lt;br /&gt;   end if config[RAILS_ENV]['adapter'] == 'mysql' unless $schema_generator&lt;br /&gt; end&lt;br /&gt;source http://trac.typosphere.org/browser/trunk/db/migrate/015_convert_mysql_to_innodb.rb&lt;br /&gt;&lt;br /&gt; def self.down&lt;br /&gt;   # don't do anything&lt;br /&gt;   # this is a one-way migration, but it's not "irreversable"&lt;br /&gt;   # because it doesn't change any code logic&lt;br /&gt; end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 19 Jul 2007 12:43:43 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4327</guid>
      <author>Mickael (Mickael)</author>
    </item>
    <item>
      <title>rails generator syntax</title>
      <link>http://snippets.dzone.com/posts/show/2800</link>
      <description>// generate application&lt;br /&gt;&lt;code&gt;&lt;br /&gt;rails projectname&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;// generate migration.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ruby script/generate migration migration_name&lt;br /&gt;ruby script/generate migration add_price&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;// generate model&lt;br /&gt;// we can give a list of columns and types&lt;br /&gt;// :string, :text, :integer, :decimal, :float, :date, ...&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ruby script/generate model model_name&lt;br /&gt;ruby script/generate model user name:string hashed_password:string salt:string&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;// generate controller&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ruby script/generate controller controller_name method_name(s)&lt;br /&gt;ruby script/generate controller store index&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;// generate scaffold&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ruby script/generate scaffold model_name controller_name&lt;br /&gt;ruby script/generate scaffold product admin&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 08 Oct 2006 18:52:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2800</guid>
      <author>ovhaag (Oliver Haag)</author>
    </item>
    <item>
      <title>tip: recover from failed rails 'down' migration</title>
      <link>http://snippets.dzone.com/posts/show/1772</link>
      <description>From: http://jamis.jamisbuck.org/articles/2005/12/14/two-tips-for-working-with-databases-in-rails&lt;br /&gt;&lt;br /&gt;The second tip is handy when you&#8217;re working on a migration. I find that the process (for me) works like this:&lt;br /&gt;&lt;br /&gt;    * Create the migration and run it.&lt;br /&gt;    * Discover I forgot something.&lt;br /&gt;    * Migrate down to the previous schema version.&lt;br /&gt;    * Change the migration and run it again.&lt;br /&gt;&lt;br /&gt;(Repeat as necessary.) However, being the imperfect programmer that I am, I find that I often implement the #down method incorrectly, forgetting to drop a table or remove a column. Thus, when I try to run the migration again, it fails saying that the table/column already exists.&lt;br /&gt;&lt;br /&gt;Using script/console and ActiveRecord::Schema, it becomes a cinch to clean up the artifacts:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ActiveRecord::Schema.define do&lt;br /&gt;    drop_table :foos&lt;br /&gt;    remove_column :bars, :blitz&lt;br /&gt;    remove_column :bars, :things&lt;br /&gt;  end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 26 Mar 2006 02:53:55 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1772</guid>
      <author>MattScilipoti (Matt Scilipoti)</author>
    </item>
  </channel>
</rss>
