Questions tagged [rails-migrations]

Rails migrations are used to track and apply database alterations in a reversible manner.

Migrations are a way to alter your database in a reversible manner using (usually) Ruby classes and objects rather than raw SQL. Rails also keeps track of which migrations have run so a simple

$ rake db:migrate

is all that is needed to bring your database up to date even if different people have made different changes. The migrations also maintain your db/schema.rb file.

Links:

1033 questions
0
votes
2 answers

Does change handle migration / rolling back of schema

In the new preferred way, there is only 1 method which seems to add a column. Does that mean you don't need to have a method to remove columns? # the old way class AddNameToPerson < ActiveRecord::Migration def up add_column :persons, :name,…
Sam
  • 8,387
  • 19
  • 62
  • 97
0
votes
2 answers

Uable to run migration on heroku on a postgre database

I need to add a property/column to a table in a production database(Postgre) on Heroku.com (Rails app) by doing migration. When I do the migration it looks ok, but when I view the columns on the table it has has not added the column! My development…
jacob
  • 541
  • 1
  • 9
  • 19
0
votes
1 answer

Datatype performance for static text

I am currently querying my database to check deals for lunch and dinner using a boolean datatype (Rails, ActiveRecord). I am going to be adding more meal options and do not want to store the static text in the database because I fear that it will…
Kyle C
  • 4,077
  • 2
  • 31
  • 34
0
votes
1 answer

RoR engines using JRuby - failed initial migration, bad

First time I try to set up rails mountable engine in project based on JRuby (necessary). Engine is empty only with one 'hello world' testing controller+view, without any model, no use of JSON. I tried run 'bundle install' and it passed well without…
0
votes
1 answer

How to fix database in rails after deleted migrations?

Okay, this is what happened: 1) I needed to add a column to a table but instead of generating the migration I wrote it by hand. The file name I gave it seemed to work okay but didn't have a timestamp so then things went bad. 2) After messing about…
Finnjon
  • 651
  • 4
  • 19
0
votes
2 answers

Are there any reasons not to use Rails Migrations on production DB?

The only danger I can think of is a developer using Capistrano to rollback a migration on the production database. Are there any other risks you can think of and what's the best way to avoid accidental migrations/database reset, etc? edit: We do…
dyanisse
  • 114
  • 1
  • 8
0
votes
1 answer

rake db:migrate shows no change on my tables

I am the beginner of RoR and just follow the "Ruby on Rails 3 Essential Training with Kevin Skoglund" on Lynda. Because of some typo so I got stucked and I drop the table to the original state. But after I did it, I can not change my tables any…
Iseng
  • 17
  • 4
0
votes
1 answer

changing column names

I just want to rename one column in my table from tenant_id to organization_id I saw this post about it http://blog.techsoftsolutions.net/?p=340 but the whole thing seemed too much for just a "rename" and I thought maybe that's because his column…
Bohn
  • 26,091
  • 61
  • 167
  • 254
0
votes
1 answer

Should a table be made for associations in rails

I am new to rails and have a very basic question. While creating models, for ex. I have to store recipe and its steps. Now should i make recipe table, steps table and recipe_steps table or should i have recipe , steps table and in the model for…
abhilash
  • 1,587
  • 2
  • 10
  • 17
0
votes
1 answer

Editing migrations after deployment to production

I'm finishing a major refactoring of an app and I am trying to clean up the migrations. I've made the changes and everything works great locally after reseting and re-migrating the database. On production I can't get the migrations to run. I've…
Eric
  • 429
  • 2
  • 6
  • 15
0
votes
1 answer

Rake migration cannot find the table

So I have created a manual file name 001_create_users.rb in db->migrate folder like this: class CreateUsers < ActiveRecord::Base def self.up create_table :users do |t| t.string :name t.string :email t.string :password …
Bohn
  • 26,091
  • 61
  • 167
  • 254
0
votes
2 answers

Rails: Generating several model migrations with one command?

Is it possible to make Rails generate several model migrations in just 1 command? Something like... $ rails g model Product1 name:string, Product2 name:string, Product3 name:string [...] Background: I have to generate about 4'000 models/db…
TomDogg
  • 3,803
  • 5
  • 33
  • 60
0
votes
1 answer

SQLite migration removes 'add_index' and 'add_foreign_key' from schema.rb file

I use SQLite3 and MySQL on the same Rails project but on two different computers. I noticed that the schema.rb which is generated when I run all migrations looks different for both environments. When I run the migrations in the SQLite3 environment…
JJD
  • 50,076
  • 60
  • 203
  • 339
0
votes
0 answers

rails ghost migrations

I keep on getting duplicate devise migration files with the same name but different time stamp in my rails app. I thought the only way to create a migration is to do so manually. If so, why are these migrations being created? Is it safe to simply…
LightBox
  • 3,395
  • 4
  • 25
  • 38
0
votes
2 answers

How to revert few values which were set on a rollback during migration

We set few values on a certain row during migration, how do we handle this on a rollback. I would like to set empty null values on down def up f = Foo.where(:name => 'some').first f.update_attributes(:val1 => 'val1', :val2 => 'val2'); end def…
Sam
  • 8,387
  • 19
  • 62
  • 97