- Read the Rails Guide about Active Record migrations
- Understand why we never use models in migrations.
- Checkout the repository through Project Hero and read all the migrations in
db/migrate. Find the three most complex migrations in the project and discuss them with your mentor.
- Read and understand How to write complex migrations in Rails
In MovieDB, add two fields:
- This field should cache the total number of movies an actor stars in
- This field should cache the first movie to which the actor was ever assigned in MovieDB
Add callbacks to your ActiveRecord models so the field is always up to date. For the purpose of this exercise, please don't use the
:counter_cache option and do everything manually instead.
Whenever you add a new column you need to take care of existing records. Add a migration that sets the
first_movie_id column for existing records. Write this migration in multiple styles:
- Embedding ActiveRecord models into your migration
- SQL statements (
update "UPDATE actors SET ...")
- Helper methods from the database adapter