Question

I edited to contents of some of my migration files to solve an issue between Paperclip and an Attachment model, renaming it to Upload.

01234_create_attachments.rb

class CreateAttachments < ActiveRecord::Migration
  def change
    create_table :attachments do |t|
      t.string :name
      t.string :attachment_url
      t.timestamps
    end
  end
end

became this:

01234_create_attachments.rb

class CreateUploads < ActiveRecord::Migration
  def change
    create_table :uploads do |t|
      t.string :name
      t.string :upload_url
      t.timestamps
    end
  end
end

Note that I only edited the file contents, not the file name.

The existing app runs fine but now I can't git clone the repo to a new server because rake db:migrate fails. If I then edit the actual migration filenames on the new server it runs properly:

01234_create_attachments.rb > 01234_create_uploads.rb

My question is if I rename the migration files in my master branch will it cause problems with my existing live app when I rake db:migrate in the future?

Was it helpful?

Solution

  1. Your file name and class name of migration should match.
  2. schema_migrations table is used to determine if the migration should run or not. Since that table only has timestamp, unless you change the timestamp, it wouldn't rerun the migration.
  3. Its not advised to change existing migration after it has been run on production environment. Add a new migration if you have to change anything.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top