Week 3 - Overview
Students should be comfortable with the following at the end of this week:
- Database Basics
- Migrations
- SQL
- ActiveRecord
- Associations and Validations
Important Links
Monday - Database Design
Challenge: FizzBuzz
Problem of the Day: Student Data Structure
- Human Learning
- ON BOARD: Review when memory is stale
- Files as permanent storage
- Databases
- Data Structure Design (based on POD)
- Entity-Relationship Diagrams (ERDs)
- Lucidchart
- Primary and Foreign Keys
- Join Tables
- Gemfiles
- Bundler
bundle install
- Semantic versioning (e.g. 4.1.5)
- How Semantic versioning fits in with
public
/private
- Migrations
- Data types
_on
fields
_at
fields
t.timestamps
t.decimal :amount, precision: 5, scale: 2
- Mention
add_column
, etc
- SQLite Browser
Lecture Notes/Links
Evening Reading
Assignment
Time Entry Data Structure
Tuesday - SQL
Challenge: String Split
Problem of the Day: Phone Numbers SQL
- Agile
- Immerse yourself in the culture.
- Read some every day.
- Ruby Rogues and Ruby Weekly.
- Dissecting a book vs drinking from a fire hydrant
- DIAGRAM: Developer spectrum. Hammer-user all the way to shiny-object
- ON BOARD: Hammer-user vs. shiny-object
- Random Topics
- Migrations
- SQL Query Browser
- Migrating up twice
.gitignore
and database files
t.timestamps
t.references
- SQL
- (Alternate between these questions together and PotD questions as student groups)
- Find all people
- Find all people with a last name of “Smith” (where)
- Find the first names of people with a last name of “Matthews” (where, select)
- (First PotD question)
- Find the three people who were entered most recently (order, limit)
- (Second PotD question)
- Find the number of people who have each last name (group)
- Find the last time at which a person with each last name was created (group, max)
- (Third PotD question)
- OPTIONAL: Find the most common first name for people with the last name of “Smith” (group, where)
- OPTIONAL: (Fourth PotD question)
- Find all email addresses, and show their owners’ names with them (join)
- (Fifth PotD question)
- Find all people, and include all of their email addresses if they have them (left join)
- Find all people with no e-mail addresses (left join, check for null)
- (Sixth PotD question)
- Quick mention of ActiveRecord Methods which map to SQL clauses
- Query for Google-like search bar?
Lecture Notes
Evening Reading
Assignment
Time Entry SQL Practice
Wednesday - ActiveRecord and Unit Testing
Challenge: Arrays and Hashes (this builds on yesterday’s challenge, so bring that code up and use it!)
Problem of the Day: Phone Numbers Active Record
- Agile
- ON BOARD: All code becomes legacy code.
- Arguably, working on some tonight.
- Definitely working on some this weekend.
- ActiveRecord Models
- Using
irb
accesses the same database as ruby ...
.new
.save
.create
.update
.all
.first
.find
and .find_by_id
.find_by_name
- Relations
- Basic Associations
- Unit Testing
- Test database vs development database
def setup
and def teardown
(for migrations)
Lecture Notes/Links
Evening Reading
Assignment
Employee Reviews with DB
Thursday - Associations and Validations
Challenge: Classes
Problem of the Day: Employee and Department Validations
- Random Topics
- Definitely don’t commit
.sqlite3
files.
- Two variables referring to the same record can get out of sync.
- Efficiency
- SQL versus Ruby solutions to the Medium HW problems
- Execute some of the code 100,000 times with different numbers of records and analyze the results
- XKCD on SQL Injection
- Validations
- Associations
- Calling methods inside a class definition
- Macros are just methods being called in definitions
dependent: :destroy
and dependent: :restrict_with_exception
- Associations with non-standard foreign_keys
has_many :through
(add companies
table)
- Git
- Reason: working with other developers on code
- GitHub Organizations
git pull
git branch
git merge
git stash
- Merge Conflicts
Lecture Notes/Links
Evening Reading
Weekend Assignment - IN PAIRS
Legacy Associations and Validations