db/migrate
. Find two complex migrations and discuss them with your mentor.
Tip
Find the largest files in the
db/migrate
folder.
In MovieDB, add two fields:
Actor#total_movies
: This field should cache the total number of movies an actor stars inActor#first_movie_id
: This field should cache the first movie to which the actor starred in. The first movie is the movie with the lowest #created_at
timestamp.Add
callbacks
Show archive.org snapshot
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 total_movies
and first_movie_id
column for existing records. Write this migration in multiple styles:
update "UPDATE actors SET ..."
)