Person
(as per the class diagram below), and initialize the database for saving Person
objects.Inspect model files and folders:
app/models/
- folder where model classes go (currently empty).app/models/application_record.rb
- a base class inherited by all model classes.Inspect database tables:
psql --command="\dt" app_development
ar_internal_metadata
and schema_migrations
.Generate model class Person
and database migration script:
rails generate model Person first_name:string last_name:string height_inches:integer weight_lbs:integer
Run migration to configure database:
rails db:migrate:reset
Inspect the database tables:
psql --command="\dt" app_development
people
table.snake_case
form of class name (Person
class → people
table).Inspect schema of people
table:
psql --command="\d people" app_development
first_name
and last_name
.id
, a unique ID number for each row.created_at
and updated_at
, automatically generated timestamps.Inspect rows of people
table:
psql --command="SELECT * FROM people" app_development
Inspect generated migration:
db/migrate/20240203174351_create_people.rb
- migration script for setting up database.
create_table
for adding new table to database.Inspect generated model class:
app/models/person.rb
- code file to open in VS Code.
Person
definition empty because Rails automatically generates attributes based on db/schema.rb
.