RSS RSS feed
November 08, 2009
Hot Topics:

JRuby on Rails with Nine Lives: Running a JRuby on Rails Application on Tomcat

  • July 31, 2007
  • By Dominic Da Silva
  • Send Email »
  • More Articles »

Creating Your Migration

You will use Rails Migrations to manage the creation and deletion of the database table that you are going to use to manage your Guitars from your app. Your table is going to conveniently be named guitars. Run the following from the railswartest direcrory:

jruby script/generate migration add_a_new_table

This will create the db/migrate/001_add_guitar_table.rb file:



Click here for a larger image.

Figure 10: Creating our add_guitar_table migration

This file contains a Ruby class named AddGuitarTable that extends Rails' ActiveRecord::Migration class. Edit this file to contain the following:

class AddGuitarTable < ActiveRecord::Migration
   def self.up
      create_table :guitars do |table|
         table.column :make,  :string, :null => false
         table.column :model, :string, :null => false
         table.column :color, :string, :null => false
      end
   end

   def self.down
      drop_table :guitars
   end
end



Click here for a larger image.

Figure 11: AddGuitarTable migration class

Now, run the migration:

jruby -S rake db:migrate



Click here for a larger image.

Figure 12: Running your migration to create the guitars table

Running MySQL Query Browser confirms that the guitars table has been created by the migration:



Click here for a larger image.

Figure 13: Empty guitars table in MySQL

1 2 3 4 5 6 7 8




Networking Solutions





Partners

  • Partner With Us














More for Developers

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs