rails-migrations

Managing Rails Migrations for different branches on the same machine

I'm a one-man-band at the company I work for. I develop a Rails application for internal use within the company. Since the beginning of the project I have used SVN for source control and done most, but not all, development in trunk. Occasionally, when I have had very significant changes to make, I have branched and made the changes mergi...

varchar Migration question for Ruby on Rails

I have created a new table including a column "note". The default is varchar(255) I believe but I wish to have this column be a text area vs. a field and to allow more data. I imagine that I would make this change in ActiveRecord::Migration file but I am curious as to the format. Do I simply change the varchar(255) to varchar(1000) for e...

mysql missing field after running rails db migration

i have a rails migration: >> cat db/migrate/20091126031039_create_cards.rb class CreateCards < ActiveRecord::Migration def self.up create_table :cards do |t| t.string :number_hash t.int :number t.string :name t.string :type t.string :expiration t.int :sec_code t.timestamps end end ...

Importing redefined SQL data from old app to new one.

Hi, I've nearly finished rewriting (with some new features) my Symfony (left a bit bad taste in mounth) application into Rails. There is some amount of data which I need to import from my old application into the new Rails app. Problem is that schema was dramatically changed and some foreign key values should be updated. I am wonder...

How to drop columns using Rails migration

What's the syntax for dropping a database table column through a Rails migration? ...

Putting update logic in your migrations

A couple of times I've been in the situation where I've wanted to refactor the design of some model and have ended up putting update logic in migrations. However, as far as I've understood, this is not good practice (especially since you are encouraged to use your schema file for deployment, and not your migrations). How do you deal with...

Foreign Key Relationship in Rails

Hi...I am a beginner in Rails and I read that the Rails enforces the foreign key relationships at the model level and also at the database level in the migration file, while creating the table. Is it really necessary and what kind of advantage does it provide ...

Shortcut for rake db:migrate:down for ruby-on-rails

Hi, I want to know if there is a short way to do the migrations down equivalent to rake db:migrate (for the migrations up). Instead of doing : rake db:migrate:up VERSION=1, rake db:migrate:up VERSION=2, ... we can do : rake db:migrate! But for : rake db:migrate:down VERSION=10, rake db:migrate:down VERSION=..., rake db:migrate:down VERS...

Rolling up Migrations?

As I understand it the point of migrations is so you can revert the database back to a known state during the last stages of development. Right now I'm still "fleshing" out my first Rails app and I'm wondering if its ok to roll up my migrations into bigger ones rather than dozens of changes. ...

In Rails, saving value of type String to a datetime column just saves nil. Why?

I came across this idiosyncrasy while testing my validations. With a migration defined as follows: create_table :time_windows do |t| t.datetime :window_begin, :null => true t.datetime :window_end, :null => true end in irb >> t = TimeWindow.new({:window_begin => Time.now, :window_end => "not a time"}) => #<TimeWindow id: nil, win...

Rails migrations - look for changes in old migrations?

If I have two migrations, mig1 and mig2, I run rake db:migrate, then I go back to mig1 and change the default value of a column, will this change be reflected when I run rake db:migrate again? Or do I have to make a new migration just for that column to make the change? ...

How to do database migration Rails3 + datamapper

I used dm-rails gem that allows datamapper to hook into rails-3 ,generated a scaffold and a migration file ,did rake db:migrate for database migration but nothing happens no error no migration, can any one suggest me how to run migrations with datamapper and rails-3. ...

Rails 3 Add Foreign Key in Migration Problems

Does anyone know of a way to create a foreign key in Rails 3 using migrations? ...

How can you get a sql script of changes from Rails migrations (for MySQL)?

I've seen http://github.com/muness/migration_sql_generator, but it doesn't work properly with MySQL for certain important operations. Is there any other way we can capture the sql generated during a rails migration? The reason I'm asking is that I cannot run the migrations on the production server since it is maintained by technical sup...

How do I fix a broken rails db migration

As a direct result of my own stupidity I have managed to somehow get my database in a broken state and can't figure out how to fix it. The problem started with a typo in one of my db migrations. I was adding a column and mis-spelled the name of the table that I wanted to add the column to. I ran 'rake db:migrate' and it failed. So I ...

How to perform 'move field' refactoring on active-record models

This is a fairly common refactoring, Martin Fowler calls it 'move field'. Given 3 models: class Person < ActiveRecord::Base has_one :contact_details has_one :address end class ContactDetails < ActiveRecord::Base end class Address < ActiveRecord::Base end how do I refactor, including migration, the has_one address from Person to ...

Can't update records in my Rails database migrations

For example I have the following migration class AddStatusField < ActiveRecord::Migration def self.up add_column :tasks, :status, :string Task.update_all "status='complete'", "completed = 't'" remove_column :tasks, :completed end end When I run this (using rake db:migrate) I get the following message == AddStatusFiel...