EXAM 2025/2026 ACTUAL COMPLETE REAL EXAM
QUESTIONS WITH DETAILED VERIFIED ANSWERS
(CORRECT ANSWERS) ALREADY GRADED A+ /
NEWEST EXAM / JUST RELEASED!!
Which database to use? - ANSWER-SQLite is the
easiest (no setup)
MySQL has better
performance
PostgreSQL favored for Heroku
deployment
Table constraints - ANSWER-Database is responsible for
assigning unique
identifier for each row (a primary key, can't change
after creation)
PRIMARY KEY, FOREIGN KEY, NOT NULL, NULL, UNIQUE,
CHECK
Linking tables - ANSWER-Different tables can be related to
each other
Keys are used to encode this relationship
, - E.g. Students table include a column identifying a student's
major (foreign key) Association is an invariant between
tables
Schema (table structure) - ANSWER-
Table name
Column names and
types
Constraints
Migrations - ANSWER-Who writes schema.rb? It is generated!
Rule: never edit schema.rb directly
Instead, write a migration
Migration: ruby code (a class) that represents a change in
schema
- Create new tables (including column names and column
types)
- Modify existing tables (adding/removing columns, or
changing associations) - Delete ("drop") existing tables
Migration Classes - ANSWER-See db/migrate
Filename consists of
- Timestamp (UTC) of creation
- Class name (descriptive of delta)
- Example: class CreatePosts in
20220319145307_create_posts.rb
Consequence: migrations are run in consistent order
- Deltas do not commute, so order is important
Class extends ActiveRecord::Migration
, - Contains method change
- This method invoked by rails db:migrate
Schema Deltas in Migrations - ANSWER-In addition to
creating tables, the
change method can also change
existing tables
- Modify columns of an existing table: add_column,
remove_column,
rename_column,
change_column
- Modify and delete tables: change_table,
drop_table
Migrations as history - ANSWER-Change defined by migration
can be undone
- Migrations give a linear history of deltas
- Schema is the result of applying them (in order)
Can move forward/backward in history
- Create database only (no schema) defined in
config/database.yml: rails db:create
- Update schema.rb and apply to database: rails db:migrate
- Rollback schema.rb to earlier point in history: rails
db:rollback
- Load schema defined in db/schema.rb: rails db:schema:load
Migrations vs schema - ANSWER-Golden rule: never edit
schema.rb
- It is regenerated every time you do a migration