0
0
Ruby on Railsframework~5 mins

Schema.rb understanding in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is schema.rb in a Rails project?

schema.rb is a file that shows the current structure of the database in Ruby code format. It helps Rails know what tables and columns exist.

Click to reveal answer
beginner
How is schema.rb generated or updated?

Rails updates schema.rb automatically when you run migrations using commands like rails db:migrate. It reflects the latest database changes.

Click to reveal answer
beginner
Why should you not edit schema.rb manually?

Because schema.rb is auto-generated, manual changes will be overwritten by Rails. Always change the database structure using migrations instead.

Click to reveal answer
intermediate
What is the difference between schema.rb and the actual database?

schema.rb is a Ruby file that describes the database structure. The actual database stores the real data and structure. schema.rb is a snapshot, not the live database.

Click to reveal answer
intermediate
How does schema.rb help when setting up a new Rails environment?

When you set up a new Rails project, you can load the database structure quickly using rails db:schema:load which uses schema.rb to create tables without running all migrations.

Click to reveal answer
What command updates schema.rb in a Rails project?
Arails console
Brails server
Crails generate model
Drails db:migrate
Which file should you edit to change the database structure in Rails?
Aschema.rb
Broutes.rb
Cmigration files
Dapplication.rb
What does rails db:schema:load do?
ALoads database structure from <code>schema.rb</code>
BDrops the database
CStarts the Rails server
DRuns all migrations
Why is schema.rb useful in a team environment?
AIt shows the current database structure for everyone
BIt stores user data
CIt runs the Rails server
DIt contains application logic
If you manually edit schema.rb, what will happen?
AChanges will be saved permanently
BYour changes will be overwritten on next migration
CRails will ignore migrations
DThe database will update automatically
Explain what schema.rb is and how it relates to Rails migrations.
Think about how Rails keeps track of your database tables and columns.
You got /4 concepts.
    Describe how schema.rb helps when setting up a new Rails project on a different machine.
    Consider how to quickly prepare the database without running every migration.
    You got /4 concepts.