Performance: Schema.rb understanding
Schema.rb affects database schema loading and migration speed during development and deployment.
Run migrations and update schema.rb regularly to reflect current database structure.Not updating schema.rb after migrations and relying on running all migrations from scratch every time.
| Pattern | Setup Time | Migration Runs | Consistency | Verdict |
|---|---|---|---|---|
| Using schema.rb snapshot | Fast (seconds) | None or minimal | High | [OK] Good |
| Running all migrations from scratch | Slow (minutes) | All migrations | Risk of inconsistency | [X] Bad |
schema.rb file in a Rails project?schema.rbschema.rb file represents the database structure in Ruby code format.schema.rb = database structure [OK]schema.rb maps database structure only [OK]schema.rb stores actual datatitle in schema.rb?schema.rb, string columns use t.string :column_name syntax.t.string :title, which is correct for a string column named title.t.string :title [OK]t.string :name for string columns [OK]t.integer for string columnst.text with t.stringschema.rb:
create_table "books", force: :cascade do |t| t.string "name" t.integer "pages" t.timestamps endWhat columns will the
books table have?name as string, pages as integer, and t.timestamps adds created_at and updated_at datetime columns.t.timestamps adds created_at and updated_at [OK]t.timestamps adds two datetime columns [OK]t.timestamps columnspages is stringschema.rb but your migration added a price column as decimal:
t.integer :priceWhat is the likely problem?
price as decimal, but schema.rb shows integer, indicating it was not updated.schema.rb update processschema.rb updates only after running migrations successfully; if not updated, it shows old info.schema.rb is outdated and shows integer instead of decimal -> Option Dschema.rb [OK]published boolean column with default false to your articles table. After creating and running the migration, what will schema.rb show for this column?schema.rbt.boolean :published, default: false in schema.rb.schema.rb [OK]schema.rb [OK]schema.rbPass the test and this pattern moves unknown