Migrating with loosing data

I have already created a migration. It adds 5 columns. Now I edit
migration file and enter 2 more column.

How can I remigrate so that 2 new columns would be added without loosing
data with db:migrate:reset?

On 04 Jul 2008, at 09:36, Vapor … wrote:

I have already created a migration. It adds 5 columns. Now I edit
migration file and enter 2 more column.

How can I remigrate so that 2 new columns would be added without
loosing
data with db:migrate:reset?

By putting it in a new migration file instead of adding it to an
already deployed one.

script/generate migration AddTwoMoreColumns

and then in the migration (assuming you are using Rails 2.1):

class AddTimeZoneToUser < ActiveRecord::Migration
def self.up
change_table :users do |t|
t.string :time_zone
t.belongs_to :role
end
end

def self.down
change_table :users do |t|
t.remove :time_zone
t.remove_belongs_to :role
end
end
end

(example taken from:
http://www.akitaonrails.com/2008/5/25/rolling-with-rails-2-1-the-first-full-tutorial-part-1)

Time to go pick up a book and start reading about how to use Rails.
The Rails Way would be a good start.

Best regards

Peter De Berdt

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs