1. Launch day · Concepts

Concepts

  • A table holds one kind of thing. Each row is one of them (one user, one post). Each column is one fact about it, and every column has a type.
  • The types you'll use most: integer, text, boolean, timestamp (date and time).
  • Every table needs a primary key: a column that uniquely identifies a row. The usual choice is an auto-numbered id. In Postgres, the serial type numbers rows 1, 2, 3 for you.
  • SQL statements come in two families. DDL (Data Definition Language) defines structure: CREATE TABLE, ALTER TABLE, DROP TABLE. DML (Data Manipulation Language) works with the rows: INSERT, SELECT, UPDATE, DELETE. Levels 1-3 are DDL.
  • The shapes: CREATE TABLE name (column type, column type, ...); and ALTER TABLE name ADD COLUMN column type;
  • A migration is one ordered step in your schema's history. Once a migration has run, you don't edit it. You add a new one.

Tool: use the SQL workbench panel next to the lesson (the SQL button or \ toggles it), set the dialect to PostgresQL, and clear any old tabs. Each tab is a migration file, applied top to bottom. Use serial for ids (GENERATED ALWAYS AS IDENTITY doesn't parse there).