[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Database migration

Jerry Jones

2/6/2007 1:40:00 AM

Beginner alert.....
I am working on a database migration. I am adding inventory items to
the table. I have the data, but for the life of me, I cannot remember
where to make this file. I remember how to run the migration etc.
So where do I put the

class AddUserTable < ActiveRecord::Migration
def self.up
create_table :users do |table|
table.column :name, :string
table.column :login, :string
table.column :password, :string, :limit => 32
table.column :email, :string
end
end

def self.down
drop_table :users
end
end

2 Answers

David Goodlad

2/6/2007 7:32:00 AM

0

On 2/5/07, Jerry Jones <cragmor@gmail.com> wrote:
> Beginner alert.....

Starting at the right place will probably help: rails-users for rails,
ruby-talk for ruby 'in general' :)

> I am working on a database migration. I am adding inventory items to
> the table. I have the data, but for the life of me, I cannot remember
> where to make this file. I remember how to run the migration etc.
> So where do I put the
>
> class AddUserTable < ActiveRecord::Migration
> def self.up
> create_table :users do |table|
> table.column :name, :string
> table.column :login, :string
> table.column :password, :string, :limit => 32
> table.column :email, :string
> end
> end
>
> def self.down
> drop_table :users
> end
> end

I'd suggest using the generator script to give you a good place to put
your migrations - in fact, it works well for almost every file that
you need to add. In this case:

/script/generate migration add_user_table

This would generate db/migrate/001_add_user_table.rb, into which you'd
place that code that you posted.

Dave

--
Dave Goodlad
dgoodlad@gmail.com or dave@goodlad.ca
http://david.g...

Mike Harris

2/6/2007 4:56:00 PM

0

Jerry Jones wrote:

> Beginner alert.....
> I am working on a database migration. I am adding inventory items to
> the table. I have the data, but for the life of me, I cannot remember
> where to make this file. I remember how to run the migration etc.
> So where do I put the
>
> class AddUserTable < ActiveRecord::Migration
> def self.up
> create_table :users do |table|
> table.column :name, :string
> table.column :login, :string
> table.column :password, :string, :limit => 32
> table.column :email, :string
> end
> end
>
> def self.down
> drop_table :users
> end
> end
>
>
The db\migrate folder. Make a migration with ruby script\generate
migration AddUserTable.

Read the docs (http://api.rubyo...) and please direct further
questions to the Rails mailing list.