Before updating scaffolding from new db schema try creating a

6854933580_2c8b688306_z

by hand but you would then be responsible for telling other developers that they need to go and run them.You’d also have to keep track of which changes need to be run against the production machines next time you deploy.Active Record tracks which migrations have already been run so all you have to do is update your source and run file to match the structure of your database.Migrations also allow you to describe these transformations using Ruby.The great thing about this is that (like most of Active Record’s functionality) it is database independent: you don’t need to worry about the precise syntax of which Active Record populates automatically will also be added.Reversing this migration is as simple as dropping the table. You can also use them to fix bad data in the database or populate new fields: method.This method is preferred for writing constructive migrations (adding columns or tables).

For example after adding a column you could write code to set the value of that column for existing records (if necessary using your models).On databases that support transactions with statements that change the schema (such as Postgre SQL or SQLite3), migrations are wrapped in a transaction.If the database does not support this (for example My SQL) then when a migration fails the parts of it that succeeded will not be rolled back.You will have to rollback the changes that were made by hand.Migrations are stored as files in the timestamp identifying the migration followed by an underscore followed by the name of the migration.The name of the migration class (Camel Cased version) should match the latter part of the file name.

You must have an account to comment. Please register or login here!