Caretaker Express · PostgreSQL · Cedar

Checkpoint · Lesson 2.2

Tables, keys and constraints: checkpoint files

Git tag in the reference repository
lesson/m02-l02 (commit da42290)
Replay result
All steps replayed from an empty folder
Tests at this point
pass (tests 7, pass 7, fail 0)

Compare your folder with the reference using Git, if you cloned it: git diff lesson/m02-l02 -- src.

Files changed in this lesson

migrations/001_create_organisations_buildings_issues.sql added

migrations/001_create_organisations_buildings_issues.sql
CREATE TABLE organisations (  id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,  name text NOT NULL CHECK (length(trim(name)) BETWEEN 2 AND 100),  created_at timestamptz NOT NULL DEFAULT now(),  updated_at timestamptz NOT NULL DEFAULT now()); CREATE TABLE buildings (  id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,  organisation_id integer NOT NULL REFERENCES organisations (id) ON DELETE RESTRICT,  name text NOT NULL CHECK (length(trim(name)) BETWEEN 2 AND 100),  created_at timestamptz NOT NULL DEFAULT now(),  updated_at timestamptz NOT NULL DEFAULT now(),  UNIQUE (organisation_id, name)); CREATE INDEX buildings_organisation_id_idx ON buildings (organisation_id); CREATE TABLE issues (  id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,  building_id integer NOT NULL REFERENCES buildings (id) ON DELETE RESTRICT,  title text NOT NULL CHECK (length(title) BETWEEN 3 AND 200),  description text NOT NULL DEFAULT '',  priority text NOT NULL CHECK (priority IN ('low', 'medium', 'high', 'critical')),  status text NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'investigating', 'closed')),  occurred_at timestamptz NOT NULL,  created_at timestamptz NOT NULL DEFAULT now(),  updated_at timestamptz NOT NULL DEFAULT now()); CREATE INDEX issues_building_id_idx ON issues (building_id);

Project tree at this checkpoint

.gitignore
.npmrc
compose.yaml
db/init/01-create-test-database.sql
migrations/001_create_organisations_buildings_issues.sql
package-lock.json
package.json
public/css/style.css
src/app.js
src/server.js
test/issues.test.js
views/error.ejs
views/issues/index.ejs
views/issues/new.ejs
views/issues/show.ejs
views/not-found.ejs
views/partials/foot.ejs
views/partials/head.ejs
views/partials/nav.ejs

Back to lesson 2.2