0
0
Ruby on Railsframework~5 mins

Database folder and migrations in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the db/migrate folder in a Rails project?
The db/migrate folder stores migration files that describe changes to the database schema, like creating or modifying tables. These files help Rails track and apply database changes in order.
Click to reveal answer
beginner
What command do you run to create a new migration in Rails?
You run rails generate migration MigrationName to create a new migration file with a timestamp in the db/migrate folder.
Click to reveal answer
intermediate
How do migrations help keep the database schema consistent across different environments?
Migrations record each change as a file with a timestamp. Running rails db:migrate applies all pending migrations in order, ensuring all environments have the same database structure.
Click to reveal answer
intermediate
What is the role of the schema.rb file in Rails?
The schema.rb file is a snapshot of the current database structure. It is updated after migrations run and helps Rails recreate the database schema quickly without running all migrations.
Click to reveal answer
intermediate
What happens if you try to run rails db:migrate but some migrations have already been applied?
Rails checks which migrations have been applied by looking at the schema_migrations table. It only runs new migrations that haven't been applied yet, so it avoids repeating changes.
Click to reveal answer
Where are Rails migration files stored?
Alib/tasks
Bapp/models
Cdb/migrate
Dconfig
What command creates a new migration file?
Arails new migration
Brails generate migration MigrationName
Crails db:create migration
Drails generate model MigrationName
What does rails db:migrate do?
ARuns all pending migrations to update the database schema
BDeletes the database
CCreates a new Rails project
DGenerates a new model
What file shows the current database schema snapshot?
Aseeds.rb
Broutes.rb
Cdatabase.yml
Dschema.rb
How does Rails know which migrations have already run?
ABy checking the schema_migrations table in the database
BBy reading the migration filenames
CBy checking the config folder
DBy scanning the app/models folder
Explain the purpose of the db/migrate folder and how migrations work in Rails.
Think about how Rails tracks and applies database changes step-by-step.
You got /4 concepts.
    Describe the role of the schema.rb file and how it relates to migrations.
    Consider how Rails can rebuild the database structure without running all migrations again.
    You got /3 concepts.