# Editorial calendar database schema

Source: https://personalsoftwarefactory.com/schemas/content-calendar
Updated: 2026-12-04

> Seven tables. pieces carries the design: one row per piece of content with its status, publish date, reviewer and approval, plus two date columns that remember which publish date a reminder or overdue notice was already sent for. Table CHECKs keep the approval present exactly while a piece is scheduled or published, and overdue is computed from the date and status, never stored.

- 7 tables, 7 indexes
- Verified on SQLite 3.53.4 and PostgreSQL 19.0 (PGlite 0.6.1) on 2026-12-04
- 37 seed rows from the blueprint
- The blueprint's test build passed 27 of 27 acceptance checks

Files: [content-calendar.sql](https://personalsoftwarefactory.com/schemas/content-calendar.sql) · [content-calendar-seed.sql](https://personalsoftwarefactory.com/schemas/content-calendar-seed.sql) · [the Content Calendar blueprint](https://personalsoftwarefactory.com/blueprints/content-calendar)

## Relationships

- settings.default_reviewer_id references people.id: each settings row points to exactly one people row, and one people row can have many settings rows pointing to it.
- campaigns.created_by references people.id: each campaigns row points to exactly one people row, and one people row can have many campaigns rows pointing to it.
- pieces.channel_id references channels.id: each pieces row points to exactly one channels row, and one channels row can have many pieces rows pointing to it.
- pieces.owner_id references people.id: each pieces row points to exactly one people row, and one people row can have many pieces rows pointing to it.
- pieces.campaign_id references campaigns.id: each pieces row points to at most one campaigns row, and one campaigns row can have many pieces rows pointing to it.
- pieces.reviewer_id references people.id: each pieces row points to at most one people row, and one people row can have many pieces rows pointing to it.
- pieces.approved_by references people.id: each pieces row points to at most one people row, and one people row can have many pieces rows pointing to it.
- pieces.created_by references people.id: each pieces row points to exactly one people row, and one people row can have many pieces rows pointing to it.
- activities.actor_id references people.id: each activities row points to at most one people row, and one people row can have many activities rows pointing to it.
- notifications.person_id references people.id: each notifications row points to exactly one people row, and one people row can have many notifications rows pointing to it.
- notifications.piece_id references pieces.id: each notifications row points to at most one pieces row, and one pieces row can have many notifications rows pointing to it. On delete: set null.

## Tables

Also described as: content calendar database design, content planning app tables, editorial workflow schema.

### people

A writer or editor on the content team. Implements: Person.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  |  |
| `email` | TEXT | no |  | Unique |  |
| `role` | TEXT | no |  |  | Check: `role IN ('writer', 'editor')` |
| `active` | BOOLEAN | no | `TRUE` |  |  |

- App rule (section 11): the last active editor and the default reviewer can't be demoted or deactivated; owners of unpublished pieces hand them over first.

### settings

The single row with the team time zone, default reviewer and last digest date. Implements: Settings.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | INTEGER | no |  | Primary key | one row only Check: `id = 1` |
| `time_zone` | TEXT | no |  |  | IANA name; publish dates and "today" are in this zone |
| `default_reviewer_id` | TEXT | no |  | References people.id | an editor; gets review requests by default (R3) |
| `last_digest_on` | DATE | yes |  |  | the Monday the weekly digest last went out |

### channels

A place content is published, with its calendar color. Implements: Channel.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  | Check: `LENGTH(name) BETWEEN 1 AND 30` |
| `color` | TEXT | no |  |  | hex, "#rrggbb" Check: `color LIKE '#______'` |
| `active` | BOOLEAN | no |  |  | inactive channels keep their pieces but are hidden from pickers |

- Unique index `channels_name_uniq` on (LOWER(name))
- App rule (section 13): the last active channel can't be deactivated.

### campaigns

A named date range that groups pieces. Implements: Campaign.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `name` | TEXT | no |  |  | Check: `LENGTH(name) BETWEEN 1 AND 80` |
| `starts_on` | DATE | no |  |  |  |
| `ends_on` | DATE | no |  |  |  |
| `goal` | TEXT | yes |  |  | optional Check: `LENGTH(goal) <= 200` |
| `created_by` | TEXT | no |  | References people.id |  |
| `created_at` | TIMESTAMP | no |  |  |  |

- Table check: `ends_on >= starts_on`
- Unique index `campaigns_name_uniq` on (LOWER(name))

### pieces

One piece of content with its status, publish date and review state. Implements: Piece.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `title` | TEXT | no |  |  | Check: `LENGTH(title) BETWEEN 1 AND 120` |
| `channel_id` | TEXT | no |  | References channels.id |  |
| `owner_id` | TEXT | no |  | References people.id | an active person |
| `campaign_id` | TEXT | yes |  | References campaigns.id |  |
| `status` | TEXT | no |  |  | Check: `status IN ('idea', 'writing', 'in_review', 'scheduled', 'published')` |
| `publish_on` | DATE | yes |  |  | empty means unscheduled (the backlog) |
| `draft_url` | TEXT | yes |  |  | Check: `draft_url LIKE 'http://%' OR draft_url LIKE 'https://%'` |
| `notes` | TEXT | yes |  |  | Check: `LENGTH(notes) <= 2000` |
| `reviewer_id` | TEXT | yes |  | References people.id | the editor asked to review, set on submit |
| `submitted_at` | TIMESTAMP | yes |  |  |  |
| `approved_by` | TEXT | yes |  | References people.id |  |
| `approved_at` | TIMESTAMP | yes |  |  |  |
| `published_at` | TIMESTAMP | yes |  |  |  |
| `reminded_for` | DATE | yes |  |  | the publish_on value the due-soon reminder was sent for (R11); cleared on a move |
| `overdue_notified_for` | DATE | yes |  |  | the publish_on value the overdue notice was sent for (R12); cleared on a move |
| `created_by` | TEXT | no |  | References people.id |  |
| `created_at` | TIMESTAMP | no |  |  |  |
| `updated_at` | TIMESTAMP | no |  |  |  |

- Table check: `status IN ('idea', 'writing') OR publish_on IS NOT NULL`
- Table check: `status IN ('idea', 'writing') OR draft_url IS NOT NULL`
- Table check: `status <> 'in_review' OR (reviewer_id IS NOT NULL AND submitted_at IS NOT NULL)`
- Table check: `(status IN ('scheduled', 'published') AND approved_by IS NOT NULL AND approved_at IS NOT NULL) OR (status NOT IN ('scheduled', 'published') AND approved_by IS NULL AND approved_at IS NULL)`
- Table check: `(status = 'published' AND published_at IS NOT NULL) OR (status <> 'published' AND published_at IS NULL)`
- Index `pieces_publish_on_idx` on (publish_on)
- Index `pieces_owner_idx` on (owner_id, status)
- Index `pieces_campaign_idx` on (campaign_id)
- App rule (R1, R2): only the transitions in section 6; the only way into scheduled is an editor's approval from in_review.
- App rule (R3): nobody approves or requests changes on a piece they own at that moment.
- App rule (R4, R6, R7): sending for review and approving need a publish date of today or later; moves to past dates are refused.
- App rule (R14): only ideas can be deleted.

### activities

One append-only log entry for a piece. Implements: Activity.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `piece_id` | TEXT | no |  |  | not a foreign key: the deleted entry outlives its piece (section 6, Delete) |
| `actor_id` | TEXT | yes |  | References people.id | empty for the scheduled job |
| `type` | TEXT | no |  |  | Check: `type IN ('created', 'edited', 'moved', 'started_writing', 'parked', 'submitted', 'withdrawn', 'approved', 'changes_requested', 'reopened', 'published', 'commented', 'reminded', 'overdue', 'deleted')` |
| `comment` | TEXT | yes |  |  |  |
| `data` | TEXT | yes |  |  | JSON text, e.g. the from and to dates of a move, or the title of a deleted idea |
| `created_at` | TIMESTAMP | no |  |  |  |

- Index `activities_piece_idx` on (piece_id, created_at)

### notifications

One in-app notification, also sent by email. Implements: Notification.

| Column | Type | Null | Default | Key | Notes |
|---|---|---|---|---|---|
| `id` | TEXT | no |  | Primary key |  |
| `person_id` | TEXT | no |  | References people.id |  |
| `kind` | TEXT | no |  |  | Check: `kind IN ('review_requested', 'approved', 'changes_requested', 'assigned', 'commented', 'due_soon', 'overdue', 'digest')` |
| `piece_id` | TEXT | yes |  | References pieces.id, on delete set null | empty for digests, and cleared if the idea is deleted |
| `text` | TEXT | no |  |  |  |
| `created_at` | TIMESTAMP | no |  |  |  |
| `read` | BOOLEAN | no | `FALSE` |  |  |
| `emailed_at` | TIMESTAMP | yes |  |  |  |
| `error` | TEXT | yes |  |  | a failed email is retried on the next daily job |

- Index `notifications_person_idx` on (person_id, read, created_at)

## The SQL

```sql
-- Content Calendar database schema
-- Source: https://personalsoftwarefactory.com/blueprints/content-calendar (data model, section 5 of the blueprint)
-- Verified on SQLite 3.53.4 and PostgreSQL 19.0 (PGlite). All timestamps are UTC.
-- License: MIT. Free to copy and adapt.

-- A writer or editor on the content team.
-- App rule (section 11): the last active editor and the default reviewer can't be demoted or deactivated; owners of unpublished pieces hand them over first.
CREATE TABLE people (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL,
  email TEXT NOT NULL UNIQUE,
  role TEXT NOT NULL CHECK (role IN ('writer', 'editor')),
  active BOOLEAN NOT NULL DEFAULT TRUE
);

-- The single settings row. Comes after people because it names the default reviewer.
CREATE TABLE settings (
  id INTEGER PRIMARY KEY CHECK (id = 1), -- one row only
  time_zone TEXT NOT NULL, -- IANA name; publish dates and "today" are in this zone
  default_reviewer_id TEXT NOT NULL REFERENCES people(id), -- an editor; gets review requests by default (R3)
  last_digest_on DATE -- the Monday the weekly digest last went out
);

-- A place content is published: Blog, Newsletter, LinkedIn and so on.
-- App rule (section 13): the last active channel can't be deactivated.
CREATE TABLE channels (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (LENGTH(name) BETWEEN 1 AND 30),
  color TEXT NOT NULL CHECK (color LIKE '#______'), -- hex, "#rrggbb"
  active BOOLEAN NOT NULL -- inactive channels keep their pieces but are hidden from pickers
);
CREATE UNIQUE INDEX channels_name_uniq ON channels (LOWER(name)); -- unique ignoring case

-- A named date range that groups pieces.
CREATE TABLE campaigns (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL CHECK (LENGTH(name) BETWEEN 1 AND 80),
  starts_on DATE NOT NULL,
  ends_on DATE NOT NULL,
  goal TEXT CHECK (LENGTH(goal) <= 200), -- optional
  created_by TEXT NOT NULL REFERENCES people(id),
  created_at TIMESTAMP NOT NULL,
  CHECK (ends_on >= starts_on)
);
CREATE UNIQUE INDEX campaigns_name_uniq ON campaigns (LOWER(name)); -- unique ignoring case

-- One piece of content moving from idea to published. Overdue is computed, never stored (R12).
-- App rule (R1, R2): only the transitions in section 6; the only way into scheduled is an editor's approval from in_review.
-- App rule (R3): nobody approves or requests changes on a piece they own at that moment.
-- App rule (R4, R6, R7): sending for review and approving need a publish date of today or later; moves to past dates are refused.
-- App rule (R14): only ideas can be deleted.
CREATE TABLE pieces (
  id TEXT PRIMARY KEY,
  title TEXT NOT NULL CHECK (LENGTH(title) BETWEEN 1 AND 120),
  channel_id TEXT NOT NULL REFERENCES channels(id),
  owner_id TEXT NOT NULL REFERENCES people(id), -- an active person
  campaign_id TEXT REFERENCES campaigns(id),
  status TEXT NOT NULL CHECK (status IN ('idea', 'writing', 'in_review', 'scheduled', 'published')),
  publish_on DATE, -- empty means unscheduled (the backlog)
  draft_url TEXT CHECK (draft_url LIKE 'http://%' OR draft_url LIKE 'https://%'),
  notes TEXT CHECK (LENGTH(notes) <= 2000),
  reviewer_id TEXT REFERENCES people(id), -- the editor asked to review, set on submit
  submitted_at TIMESTAMP,
  approved_by TEXT REFERENCES people(id),
  approved_at TIMESTAMP,
  published_at TIMESTAMP,
  reminded_for DATE, -- the publish_on value the due-soon reminder was sent for (R11); cleared on a move
  overdue_notified_for DATE, -- the publish_on value the overdue notice was sent for (R12); cleared on a move
  created_by TEXT NOT NULL REFERENCES people(id),
  created_at TIMESTAMP NOT NULL,
  updated_at TIMESTAMP NOT NULL,
  CHECK (status IN ('idea', 'writing') OR publish_on IS NOT NULL), -- R8: in review, scheduled and published pieces keep a date
  CHECK (status IN ('idea', 'writing') OR draft_url IS NOT NULL), -- R4 and R7: a draft link to submit, unchangeable after
  CHECK (status <> 'in_review' OR (reviewer_id IS NOT NULL AND submitted_at IS NOT NULL)),
  CHECK ((status IN ('scheduled', 'published') AND approved_by IS NOT NULL AND approved_at IS NOT NULL) OR (status NOT IN ('scheduled', 'published') AND approved_by IS NULL AND approved_at IS NULL)), -- reopen and request changes clear the approval
  CHECK ((status = 'published' AND published_at IS NOT NULL) OR (status <> 'published' AND published_at IS NULL))
);
CREATE INDEX pieces_publish_on_idx ON pieces (publish_on);
CREATE INDEX pieces_owner_idx ON pieces (owner_id, status);
CREATE INDEX pieces_campaign_idx ON pieces (campaign_id);

-- One append-only log entry for a piece. Never edited or deleted (R17).
CREATE TABLE activities (
  id TEXT PRIMARY KEY,
  piece_id TEXT NOT NULL, -- not a foreign key: the deleted entry outlives its piece (section 6, Delete)
  actor_id TEXT REFERENCES people(id), -- empty for the scheduled job
  type TEXT NOT NULL CHECK (type IN ('created', 'edited', 'moved', 'started_writing', 'parked', 'submitted', 'withdrawn', 'approved', 'changes_requested', 'reopened', 'published', 'commented', 'reminded', 'overdue', 'deleted')),
  comment TEXT,
  data TEXT, -- JSON text, e.g. the from and to dates of a move, or the title of a deleted idea
  created_at TIMESTAMP NOT NULL
);
CREATE INDEX activities_piece_idx ON activities (piece_id, created_at);

-- One in-app notification, also emailed.
CREATE TABLE notifications (
  id TEXT PRIMARY KEY,
  person_id TEXT NOT NULL REFERENCES people(id),
  kind TEXT NOT NULL CHECK (kind IN ('review_requested', 'approved', 'changes_requested', 'assigned', 'commented', 'due_soon', 'overdue', 'digest')),
  piece_id TEXT REFERENCES pieces(id) ON DELETE SET NULL, -- empty for digests, and cleared if the idea is deleted
  text TEXT NOT NULL,
  created_at TIMESTAMP NOT NULL,
  read BOOLEAN NOT NULL DEFAULT FALSE,
  emailed_at TIMESTAMP,
  error TEXT -- a failed email is retried on the next daily job
);
CREATE INDEX notifications_person_idx ON notifications (person_id, read, created_at);
```

## Seed data

Loads section 14 as on Tue 2026-10-13, the date of its worked examples: 6 people, the settings row, 5 channels, 2 campaigns and 19 pieces, plus this morning's daily job run (Lee's due-soon reminder and Sam's overdue notice, as 2 activities and 2 notifications with the texts from section 12). The spec gives no seed time zone, so it uses its own example, America/Chicago. Draft link URLs and the creation, submission, approval and publication times are not in the spec; they follow the blueprint's working demo, and the Pricing explainer video's link uses the demo's URL pattern because the demo omits it. No other activity history is loaded.

## Load it

```sh
# SQLite
curl -s https://personalsoftwarefactory.com/schemas/content-calendar.sql https://personalsoftwarefactory.com/schemas/content-calendar-seed.sql | sqlite3 content_calendar.db
# PostgreSQL
createdb content_calendar && curl -s https://personalsoftwarefactory.com/schemas/content-calendar.sql https://personalsoftwarefactory.com/schemas/content-calendar-seed.sql | psql -v ON_ERROR_STOP=1 content_calendar
```

## Design decisions

### The approval is tied to the status

R1 makes an editor's approval the only way into Scheduled, and section 6 clears it on Reopen and Request changes. A CHECK requires approved_by and approved_at exactly when the status is scheduled or published. The rule that nobody approves their own piece (R3) is not a CHECK, because the owner may change after approval: an editor can take over a scheduled piece.

### Reminders remember the date they were for

R11 and R12 send one due-soon reminder and one overdue notice per publish date. reminded_for and overdue_notified_for store that date; moving a piece clears them (R10), so the daily job reminds again for the new date. This also makes the job safe to run twice on the same day.

### Overdue is not a column

Section 5 says overdue is computed from publish_on, today and status (R12): a date before today on anything not published, including scheduled pieces nobody marked published. Storing it would be wrong every morning until a job rewrote it, and the flag must disappear the moment a piece is published or moved.

### Pieces past writing keep a date and a draft link

R8 refuses to unschedule a piece in review or scheduled, and R4 needs a draft link to send for review. R7 then refuses edits to in-review and scheduled pieces, and published pieces can't be edited. CHECKs require publish_on and draft_url for every status after writing. The build test found that a piece in review or scheduled could still be edited without another review; R7 now refuses that, so the draft link can't be removed after submission. (This point comes from a gap the blueprint's build test found.)

### Activity outlives deleted ideas

Deleting an idea writes a deleted activity with the title (section 6), and activity rows are never deleted (R17). activities.piece_id is therefore a plain column, not a foreign key, so the log survives the piece. Notifications about a deleted idea keep their text and lose only the link (ON DELETE SET NULL).

### Names unique ignoring case

Channel names (up to 30 characters) and campaign names (up to 80) are unique ignoring case in section 5. Unique indexes on LOWER(name) enforce it on both engines, so Blog and blog can't both exist.

## Example queries

### Publishing in the next 7 days (digest)

```sql
SELECT p.publish_on, p.title, c.name AS channel, p.status, o.name AS owner, CASE WHEN p.status IN ('scheduled', 'published') THEN '' ELSE 'not approved yet' END AS flag FROM pieces p JOIN channels c ON c.id = p.channel_id JOIN people o ON o.id = p.owner_id WHERE p.publish_on BETWEEN '2026-10-13' AND '2026-10-19' ORDER BY p.publish_on, p.title;
```

On the seed data for the week of Tue 2026-10-13: 7 rows, matching section 9's worked example, from Launch thread: new pricing (X, scheduled) to Olsen & Co (LinkedIn, scheduled).

### Pipeline board counts

```sql
SELECT status, COUNT(*) AS pieces FROM pieces GROUP BY status ORDER BY CASE status WHEN 'idea' THEN 1 WHEN 'writing' THEN 2 WHEN 'in_review' THEN 3 WHEN 'scheduled' THEN 4 ELSE 5 END;
```

On the seed data: 5 rows, 5 idea, 5 writing, 2 in review, 4 scheduled, 3 published, as section 14 counts.

### Review queue for Maya Chen

```sql
SELECT p.title, o.name AS owner, p.publish_on, p.submitted_at, p.draft_url FROM pieces p JOIN people o ON o.id = p.owner_id WHERE p.status = 'in_review' AND p.owner_id <> 'person_maya' ORDER BY p.submitted_at;
```

On the seed data: 2 rows, October newsletter (sent 2 days ago) before New pricing FAQ (sent 1 day ago).

### Overdue pieces

```sql
SELECT p.title, p.publish_on, p.status, o.name AS owner FROM pieces p JOIN people o ON o.id = p.owner_id WHERE p.publish_on < '2026-10-13' AND p.status <> 'published' ORDER BY p.publish_on;
```

On the seed data on 2026-10-13: 1 row, Acme case study video, due 2026-10-12, writing, Sam Okafor.

### Campaign progress

```sql
SELECT c.name, c.starts_on, c.ends_on, SUM(CASE WHEN p.status = 'published' THEN 1 ELSE 0 END) AS published, COUNT(p.id) AS pieces, SUM(CASE WHEN p.publish_on < c.starts_on OR p.publish_on > c.ends_on THEN 1 ELSE 0 END) AS outside_dates FROM campaigns c LEFT JOIN pieces p ON p.campaign_id = c.id GROUP BY c.id, c.name, c.starts_on, c.ends_on ORDER BY c.starts_on;
```

On the seed data: 2 rows, Customer stories 1 of 5 published and Q4 pricing launch 1 of 5 published, none outside their dates.

## What was not tested

- MySQL, MariaDB, SQL Server and Oracle. The file avoids engine-specific syntax, but it was not run on them.
- Other versions of SQLite and PostgreSQL than the two named above.
- PostgreSQL as a server. The PostgreSQL run used PGlite, which is PostgreSQL compiled to run in-process.
- Production load. The check loads the seed rows and runs the example queries; it says nothing about performance with real volumes.
- Migrations. This is a schema for a new database, not a path from an existing one.

## The blueprint

This schema is section 5 of the [Content Calendar blueprint](https://personalsoftwarefactory.com/blueprints/content-calendar), which also has the business rules, the screens, the phased build prompts and the acceptance checks. Paste-ready spec: https://personalsoftwarefactory.com/blueprints/content-calendar/blueprint.md
