Chapter 1 · Sessions 1–2
What the old system holds, and the tables that replace it
The website, the product pages, the careers pages and the internal wiki can all run from one content model in your own platform: content stored once as typed entries, every edit a new version, delivered only when published. Session 1 inventories what you publish today and measures where you start. Session 2 adds the twelve cms_ tables, tried on the development project before anything reaches production.
35 min5 stepsSessions 1 and 2About 8 hours hands-on across six sessions
By the end of this chapter you can
- Inventory the old CMS, site builder or wiki: places, content counts, roles, forms, bill and export.
- Measure three baselines: publishing lead time, Lighthouse accessibility, and the list of every public address.
- Check the spine tables the module points at, and add only the missing ones.
- Have Claude Code write the twelve cms_ tables with their rules, a made-up seed shifted onto today and tests, and try them on the development project.
A headless content model
The module runs the public website, a product catalogue, careers pages and an internal knowledge base from one content model with drafts, versions, an editorial workflow, scheduled publishing, preview, languages, search-engine output and forms that feed the CRM or the help desk. It replaces WordPress (hosted), Webflow, Contentful, Sanity, Storyblok, Strapi Cloud, Payload or HubSpot CMS, and for internal pages Confluence, Notion or SharePoint pages [1]. Controlled documents are module M06; email campaigns M16.
| Rule | Used in this module for |
|---|---|
| W3C WCAG 2.2 AA [2] | Accessibility of published pages and the editor; alt text required on every image |
| schema.org and JSON-LD; the sitemaps.org protocol | Structured data and a sitemap for search engines (Session 5) |
| RFC 9110, HTTP semantics | The right redirect code: 301, 302, 307 or 308 (Session 5) |
| BCP 47 | Language tags for locales, such as en, es and es-MX |
| Google Core Web Vitals | Performance targets: LCP, INP and CLS |
Session 1: Inventory what you publish today, from its own lists and bills
45 minutesWhy
The module replaces real things, so it starts from what the old system says about itself: what is published where, who can change it, what each form does after Submit, and what it all costs. Three real publishing times give the starting number Session 6 measures again. Figures read from the admin lists and invoices survive a challenge from finance; guesses do not.
Do this
Collect these yourself, from the old system's admin screens and your invoices:
- Every place you publish: public site, catalogue, careers, internal wiki. Sort each into the module's spaces: public_site, catalog, careers, knowledge_base or internal.
- Content counts by kind from each admin list (pages, posts, products, jobs, articles, media, languages), with the date.
- Who can sign in, by role not name: write, review, publish, administer. Note any shared login: with one, nobody can say who changed a page.
- The last three website changes: when each was asked for and when it went live, from email or ticket times, not memory.
- Each form: where a submission goes, who reads it, whether consent wording is shown and stored, how spam is stopped.
- Every bill (subscription, hosting, plugins, seats, the domain) and renewal date, from invoices; and what the export gives.
cd ~/code/acme-platform && git switch main && git pull && claudeOn a new branch cms/inventory, write docs/cms-inventory.md from my notes below, for the site's owner and finance, in plain English:
1. Places: name, space, tool, owner, bill per year, renewal date, export available.
2. Content counts by kind and space, with the date counted.
3. Roles and how many people hold each; any shared login.
4. Publishing lead time: the three changes with asked and live times, and the median in hours.
5. Forms: destination, reader, consent wording shown and stored, spam protection.
6. Workarounds.
Rules: use only my numbers; never estimate; a missing number is "not yet read: <who can read it>". No form submissions or customer names. Open a pull request titled "CMS inventory".
My notes:
<paste your notes here>You will see recreated screen
| Status | Count |
|---|---|
| Published | 86 |
| Draft | 14 |
| Private | 3 |
- Drafts in the old system arrive as drafts in the new one; they are not lost and not published.
- Your deadline: Session 6 cuts over before this.
You will see recreated screen
- The median of three real changes: the number Session 6 compares against.
Check it worked
The pull request has docs/cms-inventory.md with every place sorted into a space, counts with their date, roles, the three timed changes and their median, each form's destination, and every bill or who can read it.
If it goes wrong
The lead times come from memory
Use the email or ticket timestamps. A remembered "about a day" cannot be compared with anything in Session 6.
Claude Code adds a cost for hosting it assumed
Say: Remove every number that is not in my notes and mark it 'not yet read'.
Several people share one admin login
Write it down as a finding. The module gives everyone their own sign-in; the old shared login is retired in Session 6.
Session 1: Measure the starting line, and save every public address
25 minutesWhy
Accessibility is a legal exposure in many places, and the module's definition of done asks for a Lighthouse accessibility score of 95 or more, so you need today's score to compare. The list of every public address is what Session 5 builds the redirect map from: an address missing from the list becomes a broken link the day the domain moves.
Do this
In your own terminal, run Lighthouse on the home page and the four most visited pages (Lighthouse is free and comes with Chrome; this runs it from the command line):
npx lighthouse https://www.acme.com/ --only-categories=accessibility,performance --output=html --output-path=./lighthouse-home.htmlThen save the site's list of addresses from its sitemap. Public addresses are public, so they can go in the repository:
curl -s https://www.acme.com/sitemap.xml -o old-sitemap.xmlOn the same branch:
1. Read old-sitemap.xml (and any sitemaps it points to: fetch those with curl too and tell me which) and write docs/old-urls.txt: one public path per line, sorted, no duplicates. Tell me the count.
2. Add a section "Starting line" to docs/cms-inventory.md: for each of the five pages, the accessibility and performance scores, the images reported without alt text, and the LCP, INP and CLS values the reports show. I will paste them below.
Push to the same pull request.
<paste the five pages' scores here>You will see recreated screen
- Today's scores. The new templates must reach 95 for accessibility; the report says which images and contrasts fail.
Check it worked
docs/old-urls.txt lists every public path with its count, and the inventory has the five pages' scores. Then the site's owner reads the inventory, owner two approves and it merges.
If it goes wrong
The sitemap lists only some pages, or there is none
Many sites' sitemaps leave pages out. Ask Claude Code: Also list every address the old tool's export and the site's menus link to, and merge them into docs/old-urls.txt. Add the addresses your analytics tool shows visitors arriving at.
npx lighthouse fails to find Chrome
Run Lighthouse from Chrome instead: open the page, open DevTools, choose Lighthouse, tick Accessibility and Performance, and Analyze. Save each report.
Twelve tables on the shared spine
Every table carries the standard columns recorded in docs/spine-map.md (site_id in place of the specification's tenant_id) and the prefix cms_, and points at the spine's core_person and core_attachment instead of keeping its own people or files. An entry never changes its stored content: each edit is a new, unchangeable version, and two pointers on the entry say which version readers see and which is in work.
| Table | One row is | Columns (req = required) and allowed values |
|---|---|---|
| cms_content_type | A content type, as schema | key req, unique; name req; schema json req; is_singleton req; localized req; space req: public_site, catalog, careers, knowledge_base, internal |
| cms_entry | One entry in one locale | content_type_id req; slug req; locale req; translation_group_id; parent_entry_id; status req: draft, in_review, approved, scheduled, published, archived; current_version_id; published_version_id; publish_at; unpublish_at; author_id; seo json |
| cms_entry_version | An unchangeable version of an entry's data | entry_id req; version_no req; data json req; change_note; created_by_person |
| cms_entry_reference | One link between entries, for refreshing pages | from_entry_id req; to_entry_id req; field_key req |
| cms_media_asset | An image, video or file | attachment_id req (core_attachment); title; alt_text req, never blank; focal_point; width; height; variants; license; credit |
| cms_locale | A language | code req, unique, a BCP 47 tag; name req; fallback_code (another locale, no loops); is_default req |
| cms_nav_menu, cms_nav_item | A menu, and one item in it | menu: key req; locale req. item: nav_menu_id req; parent_id; label req; entry_id; url; seq req |
| cms_redirect | One redirect rule | from_path req, unique; to_path req; status_code req: 301, 302, 307, 308; hits; active req |
| cms_web_form, cms_web_form_submission | A form, and one submission | form: key req, unique; fields json req; target req: crm_lead, helpdesk_ticket, email, webhook; consent_text; success_message; spam_protection req: none, honeypot, turnstile, recaptcha. submission: web_form_id req; payload json req; utm; ip_hash; submitted_at req; routed_type; routed_id; status req: received, routed, spam, failed |
| cms_kb_feedback | One helpful or not on an article | entry_id req; helpful req; comment; person_id; at req |
Session 2: Check the spine the module points at
15 minutesWhy
The cms_ tables point at people, files, job roles, action items, comments, approvals and the audit log on the spine. Recording each one once, in the shared docs/spine-map.md, and adding only what is missing in its own migration keeps one spine every module shares; a spine table invented inside the module's migration gives the next module a different shape.
Do this
Read every file in supabase/migrations and docs/spine-map.md (if it exists). Do not write anything yet.
Module M17 points at these spine names: core_person, core_attachment, core_job_role, core_action_item, core_number_sequence, core_comment, core_approval, core_event_outbox and core_audit_log, with core_current_actor(), core_touch_row() and core_audit_row(), as defined in the CivOps module library's spine (00_core_spine.sql).
Tell me in a table which of our tables or functions plays each role (the Foundation's sites, parts, lots, equipment and memberships first, then anything an earlier module added), which are missing, and any that differ. Then propose, and wait for my yes:
1. A section "M17 Website and content" in the one shared docs/spine-map.md (create the file if no module has yet; never a separate cms map): each spine name and our table for it. Record that the module's tables carry site_id (a foreign key to sites, the site that owns the content) in place of the specification's tenant_id, so each table keeps one simple access rule.
2. One migration (npx supabase migration new spine_for_cms) with only what is missing; row-level security on and none of the spine's tenant_isolation policies, because access comes only from docs/matrix.json through scripts/gen-policies.mjs. Never put spine tables inside the module's migration.You will see recreated screen
- When everything exists, the right answer is no new migration: only the map gains a section.
Check it worked
You have a table of the spine names marked exists or missing, and a green pull request "Spine for CMS" that adds the M17 section to docs/spine-map.md (site_id in place of tenant_id) and, only if something was missing, one migration with the missing tables.
If it goes wrong
The migration copies the spine's tenant_isolation policies
Say: Remove every hand-written policy. Access comes only from docs/matrix.json through scripts/gen-policies.mjs. A broad policy lets every signed-in person change the public website.
Claude Code writes docs/cms-spine-map.md, or adds a tenant_id column
Say: Use the one shared docs/spine-map.md, with a section for M17. Module tables carry site_id, never tenant_id. A second map, or a second scope column, gives the next module two answers.
Session 2: One prompt: the twelve tables, their rules, a made-up seed and the tests
45 minutesWhy
The database itself keeps the rules that matter: a stored version never changes, an image cannot be saved without a description, two pages cannot share an address, a language cannot fall back in a loop. The seed is small, marked SYNTHETIC and shifted onto today when it runs, so it never goes stale, while its mix stays fixed because Session 4 counts it by hand: the delivery API must return 4 entries before the scheduled run and 5 after.
Do this
Read docs/cms-inventory.md, docs/naming-standard.md, docs/spine-map.md and the spine migrations. On a new branch cms/tables:
1. npx supabase migration new create_cms. The twelve tables with the standard columns in docs/spine-map.md (site_id not null references sites, indexed; core_touch_row() and core_audit_row() triggers; no tenant_id) and exactly the columns and allowed values in element M17's table. Foreign keys only to the tables docs/spine-map.md names, to sites and to each other. Also:
- unique per site: cms_content_type.key, cms_locale.code, cms_redirect.from_path, cms_web_form.key; cms_entry_version (entry_id, version_no); cms_entry (content_type_id, locale, slug); one entry per locale for a singleton type;
- cms_entry_version can never be updated or deleted (a trigger); each version records the content type's row_version it was written against inside data;
- current_version_id and published_version_id must name a version of the same entry;
- cms_media_asset.alt_text not blank (trimmed length at least 1);
- cms_locale.code looks like a BCP 47 tag; fallback_code names another locale, never itself, never a loop.
Row-level security on, no policies.
2. Add the twelve tables to docs/matrix.json with no rights yet, and run scripts/gen-policies.mjs.
3. supabase/seeds/cms.sql, listed under [db.seed] sql_paths in supabase/config.toml (never appended to supabase/seed.sql). Every row made up and marked: titles start "SYNTHETIC · ", slugs start syn-, on the syn site. Every date shifted onto today: read the clock once when the seed runs and keep the gaps between rows. Safe to run twice: on conflict do nothing on every unique key. Locales en (default), es (falls back to en), es-MX (falls back to es). Types: page and site_settings (singleton) in public_site, product in catalog, job_posting in careers, kb_article in knowledge_base. Three media assets with alt text. Menu main with three items, one under another. Twelve entries, thirteen versions: about (en) live; about (es) live, same translation_group_id; services live at version 1 with version 2 in review; contact approved, never published; opening-hours scheduled for one hour before the seed runs (due); holiday-notice scheduled for 30 days after (not due); old-offer live with unpublish_at one day before (past); a draft product; a job posting in review; reset-a-password, a live kb_article; a draft kb_article; site_settings live.
4. tests/fixtures/cms-schedule.json: the same twelve entries with fixed dates and a fixed clock (2026-09-10 09:00 UTC: opening-hours due 2026-09-01, holiday-notice 2099-01-01, old-offer unpublish_at 2026-09-05), with the hand-worked answer: 4 live before the scheduled run, 5 after, 0 changes on a second run. A unit test of the "live" rule reads it; fixed dates never go in the seed.
5. pgTAP tests in supabase/tests/cms.test.sql: row-level security on all twelve; refused: blank alt text, a status outside the list, an update of a stored version, redirect code 304, a second entry with the same type, locale and slug, a second site_settings entry in one locale, a locale whose fallback loops. After the seed: 12 entries and 13 versions; after running the seed a second time, still 12 and 13.
Do not connect to any Supabase project. Push, open a pull request titled "CMS: tables", wait for every check, and report in plain words with the number of tests. If a check fails, fix it and wait again.You will see recreated screen
- Two rules in the table itself: no image without a description, and history that cannot be rewritten.
Check it worked
Pull request CMS: tables is green on GitHub, and its summary gives 12 entries and 13 versions after the seed.
If it goes wrong
CI fails: table cms_entry is not in docs/matrix.json
The generator is doing its job. Say: Add the twelve cms_ tables to docs/matrix.json with no rights and rerun gen-policies.
Claude Code writes fixed calendar dates in the seed
Say: Shift every seeded date onto today, keeping the gaps: opening-hours due an hour ago, holiday-notice in 30 days, old-offer past its unpublish_at. Fixed dates belong only in tests/fixtures/cms-schedule.json. A fixed date goes stale: a month later the 'future' entry is due and Session 4's count is wrong.
The summary says green but the check is red
Say: Show me the exact command, its exit code and the last 20 lines of the failed log, then fix the cause.
Session 2: Try it on the development project, then merge
15 minutesWhy
CI builds the database from nothing; the development project proves the files also apply on top of the Foundation's history, the way production will. You do it yourself because it changes a database. The first time, db push --include-seed applies the migration and loads every seed file listed in config.toml, cms.sql included; after that npm run seed:dev reloads the made-up data. After merge the deploy workflow from Foundation Session 11 applies the same migration to production and never seeds it.
Do this
cd ~/code/acme-platform && git fetch && git switch cms/tablesnpx supabase link --project-ref tsrqponmlkjihgfedcbanpx supabase db push --include-seedLater, to reload the made-up data on the development project, run npm run seed:dev yourself; the seed is safe to run twice. Then open the development project's SQL editor and run the check below.
https://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/sql/new
The development project's SQL editor. Check the name at the top says acme-platform-dev.
-- Expect: approved 1, draft 2, in_review 2, published 5, scheduled 2
-- (services is in_review for version 2 but stays live: its published_version_id still names version 1)
select status, count(*) from cms_entry group by status order by status;Owner two approves, you merge, and the deploy run applies the migration to production:
https://github.com/acme-ops/acme-platform/actions
GitHub Actions: the deploy run for the merge must be green.
You will see recreated screen
- Only the new file, on acme-platform-dev. Anything else: answer n and ask why.
Check it worked
On acme-platform-dev the count matches: published 5 (about en and es, old-offer, reset-a-password, site_settings), in_review 2 (services and the job posting), scheduled 2, draft 2, approved 1. After merge the deploy run is green and no seed row is in production.
If it goes wrong
The counts differ from the comment
Fix the seed, not the comment, through the pull request, then run npm run seed:dev. Every count in Session 4 depends on this seed. Never reset the development project to start again: it holds the Foundation's history too.
The deploy run fails at migrate
Production is unchanged. Copy the error into Claude Code: The production migrate step failed with this error. Explain it and propose a fix as a new migration. Do not touch production.
Knowledge check
Which content type design keeps content reusable?
Knowledge check
Why does the module save docs/old-urls.txt in Session 1?
References
- Cosmic: Sanity vs Contentful 2026. https://www.cosmicjs.com/blog/sanity-vs-contentful
- W3C: Web Content Accessibility Guidelines (WCAG) 2.2. https://www.w3.org/TR/WCAG22/
- Chrome for Developers: Lighthouse overview. https://developer.chrome.com/docs/lighthouse/overview
- IETF BCP 47: Tags for Identifying Languages. https://www.rfc-editor.org/info/bcp47
- Supabase Docs: Database migrations. https://supabase.com/docs/guides/deployment/database-migrations
Chapter 2 · Sessions 3–4
Who may do what, the screens, and publishing that never leaks a draft
Session 3 writes every right into the role matrix: the people who write, review, publish and administer, and the programs that serve the public site, take form submissions, run scheduled publishing and import. Then it builds the screens. Session 4 runs an entry from draft to published, previews drafts through the real front end to the people allowed to see them, serves only what is published, refreshes changed pages, and routes form submissions to the CRM or the help desk.
40 min5 stepsSessions 3 and 4Published API never returns a draft
By the end of this chapter you can
- Write people and the four programs into docs/matrix.json, and regenerate policies, route guards and tests.
- Build the author's phone editor, the review queue, the site overview and the knowledge-base reader.
- Run an entry through review, send-back, approval and scheduled publishing, with versions and rollback.
- Preview drafts in Next.js draft mode, deliver only published versions, and refresh referencing pages on publish.
- Route form submissions to a CRM lead, a help-desk ticket or an action item, with the consent text stored.
People and programs
| Role | Does | Never |
|---|---|---|
| Author | Writes their own entries as new versions, uploads media with alt text, submits for review, previews their own drafts | Reads another author's draft; approves or publishes |
| Editor | Reviews, edits as new versions, sends back with a comment, approves (step 1), menus, redirects, media | Approves an entry they wrote |
| Publisher | Final approval (step 2), publishes now or schedules, unpublishes, adds the redirect when a page is retired | Publishes an entry they wrote |
| Site administrator | Content types, locales, forms, menu structure, the form inbox and retries; reads the audit log | Edits entries' content |
| Knowledge-base reader | Reads published knowledge_base and internal articles; leaves feedback | Sees drafts |
| cms_delivery (machine) | The public read API, sitemap and redirect lookup: published versions of public_site, catalog and careers only; adds redirect hits | Reads a draft, a not-yet-due entry or knowledge-base content; inserts anything |
| cms_form_intake (machine) | Public form route: stores a submission and routes it, reading only the last ten minutes' submissions | Reads older submissions or anyone's details |
| cms_scheduler (machine) | Publishes due scheduled entries, archives entries past unpublish_at, refreshes pages | Publishes an entry that is not scheduled |
| cms_importer (machine database login, Sessions 5–6) | Inserts only: entries as drafts with no author, versions, media, redirects; set to NOLOGIN at cut-over | Publishes, updates or deletes anything |
Session 3: Write people and programs into the matrix, and regenerate everything
40 minutesWhy
The public website is the one place the platform answers strangers, so what it may read must be narrow and tested: published, public, due, and nothing else. Writing every right Sessions 4 to 6 need now, with a test per cell, stops the Publish button that reports success while nothing changes, which we hit building this very module.
Do this
Read docs/matrix.json, scripts/gen-policies.mjs, lib/access/routes.ts and docs/cms-inventory.md. On a new branch cms/access, add module M17:
Roles: cms_author, cms_editor, cms_publisher, cms_site_admin, kb_reader, and machine accounts cms_delivery, cms_form_intake, cms_scheduler and cms_importer, each with its own sign-in and a password a person sets, never the service-role key. cms_importer is insert-only: in a separate migration create it as a database login with NOLOGIN for now, no BYPASSRLS, owning nothing; I set its password myself in Session 5.
Cells: exactly the rights in the M17 role table I paste below. Nobody gets delete: a retired row gets archived_at. cms_delivery reads an entry only when published_version_id is set, archived_at is empty, unpublish_at is empty or in the future, and its type's space is public_site, catalog or careers, and reads only that published version. cms_form_intake reads a submission only within 10 minutes of submitted_at, so it can update the row it just stored and no other.
Rules (restrictive): nobody approves or publishes an entry they authored or whose current version they wrote; a live entry's slug changes only with a cms_redirect from the old path; knowledge_base and internal content is never delivered publicly. For every update a role makes (publishing, archiving, routing a submission), make sure its read rule covers the row after the change, or Postgres will silently update nothing.
Screens: /cms/write (author), /cms/review (editor, publisher), /cms/site (site admin), /kb (kb_reader). Routes: public by exact path only: /api/content, /sitemap.xml, /robots.txt, /api/forms/contact (and each form key you add later, one by one); /api/preview (author, editor, publisher); /api/cms/revalidate (publisher, cms_scheduler); /api/cms/publish-due (cms_scheduler with CRON_SECRET, and the publisher's button, which always runs as cms_scheduler).
Regenerate the policies with node scripts/gen-policies.mjs, lib/access/routes.ts with node scripts/gen-routes.mjs, and docs/access-review.md; never hand-write a policy or a route guard. Tests: an allowed and a refused test per cell, plus: cms_delivery cannot read a draft, a not-yet-due scheduled entry or a kb_article, and cannot insert; an author cannot read another author's draft; an editor cannot approve their own entry; form intake cannot read a submission 11 minutes old; nobody can delete; a signed-out request to each screen lands on sign-in; a signed-out request to /api/cms/publish-due is refused. Each update test checks the row really changed.
Push, open a pull request titled "CMS: access", wait for every check, and report.
The M17 role table:
<paste the "People and programs" table from element M17, chapter 2>You will see recreated screen
- Generated, not hand-written: change the matrix and this changes with it.
- Four live public entries on the seed: the same number Session 4 counts by hand.
Check it worked
Pull request CMS: access is green, the delivery tests read exactly 4 seeded entries, and owner two has read docs/access-review.md.
If it goes wrong
Publish reports success but the entry stays approved
The publisher's read rule did not cover the published row, so the update found nothing. We hit this building this module. Say: For each role that changes cms_entry status, check its read rule covers the row before and after the change; add a test that the row really changed.
/sitemap.xml opens but so does /api/content/drafts.json
The sign-in gate is skipping paths with a dot in them, a fault we hit. Say: Show exactly which paths proxy.ts skips. Every /api/ path is checked whatever it ends with; only the exact public paths are open.
Claude Code makes /api/forms/ public as a folder
Say: Open each form's exact path only. A folder made public opens every route filed there later.
Session 3: Build the screens, and test them on a phone
40 minutesWhy
Authors often fix a page from a phone, readers read the knowledge base on the floor, and the review queue is where most of the waiting happens. Building each against the seed, whose mix never changes, means every screen can be checked against numbers you already know.
Do this
Before writing any page or route, read the guides in node_modules/next/dist/docs/ for routing and proxy.ts (this Next.js version differs from older guides), and lib/access/routes.ts.
On a new branch cms/screens, against the seed:
- /cms/write: one field at a time with large targets; every save a new version; every image asks for alt text; Submit for review.
- /cms/review: in_review for the editor, approved for the publisher, newest first; approve, send back with a comment, publish now, schedule, unpublish; a filter for imported entries.
- /cms/site: entries by status, the median hours from creation to publication, form submissions by status.
- /kb: the page tree from parent_entry_id, the article, and a Helpful yes or no box with a comment.
Uploaded files go to Supabase Storage through core_attachment, never to a project folder or public/. Take the signed-in person from the session on the server. Screen tests per role, signed out, and at 360 and 390 px (Foundation Session 12's rules). Push, open a pull request titled "CMS: screens", wait for every check, and give me the preview address.You will see recreated screen
- Describes the image for someone who cannot see it. A file name is not a description.
Check it worked
Every check is green. On your phone, /cms/write and /kb on the preview fit the screen with no sideways scrolling; signed in as each test role, each screen shows what the matrix says and nothing more.
Fastest path
Sit an author and an editor at their screens for ten minutes this week, without explaining, and note where each stops.
If it goes wrong
Uploads work on your machine and vanish on the preview
On Vercel the project's folders are read-only and each server copy is separate. Say: Store uploads in Supabase Storage through core_attachment; add a test that fails if code writes into the project folders.
The site overview shows a lead time before anything was published
Say: Show 'No data' until something is measured; never a placeholder.
Session 4: An entry from draft to published, with versions, send-back and rollback
40 minutesWhy
This is the editorial control the old system either lacked or hid: every edit a new version, a second person approving, and a record of who did what. Rollback that copies an old version into a new one means history is never rewritten, so "what did this page say on the day we were quoted?" always has an answer.
Do this
On a new branch cms/workflow, build the editorial workflow against the seed, as element M17 describes:
1. Saving an entry writes cms_entry_version n+1 with a change note; compare two versions side by side; rollback copies an old version into a new one.
2. Submit for review; the editor sends back with a core_comment (the entry returns to draft and the author sees the comment), or approves (core_approval step 1); the publisher approves (step 2) and publishes now or schedules. An edit to a published entry sets current_version_id to the new version and status draft while published_version_id stays, so readers keep the live version.
3. Two editors saving the same entry at once: the second save is refused with a clear message if the entry changed since it was read (compare updated_at), never silently overwriting.
4. Tests, each shown failing with its rule removed, then passing: an author cannot approve; an editor cannot approve what they wrote; a rollback leaves every earlier version unchanged; of two simultaneous saves exactly one wins; the audit log records each step's person and time.
Push, open a pull request titled "CMS: workflow", wait for every check, and report.You will see recreated screen
| When | Who | What |
|---|---|---|
| 10:02 | author.test | submitted v2 |
| 10:41 | editor.test | sent back with comment |
- Readers still see version 1 while this happens.
- From the audit log: who did each step and when.
Check it worked
On the preview you took an entry through send-back, a new version, approval by the editor and publication by the publisher; the author could not approve; the audit trail shows each step.
If it goes wrong
A second editor's save quietly replaced the first
Say: Refuse a save if the entry's updated_at changed since it was read, with a message saying who changed it; test two saves at once. We have seen "Created" shown for a record a second save then erased.
Rollback edits the old version
Stored versions never change; the trigger should refuse. Say: Rollback inserts a new version that copies the old one's data.
| Key or secret | What it unlocks | Where it lives | Who holds it | Never |
|---|---|---|---|---|
| CRON_SECRET | Lets Vercel's timer call /api/cms/publish-due | Vercel environment variables (Production) | Owner one; made with openssl rand -hex 32 | Pasted into Claude Code, a file or a chat |
| IP_HASH_SALT | Makes stored form ip_hash values impossible to reverse | Vercel environment variables | Owner one | Changed without reason (old hashes stop matching) |
| Machine account passwords (cms_delivery, cms_form_intake, cms_scheduler) | Each program's own sign-in | Vercel environment variables, and the password manager | Owners one and two | Replaced by the service-role key |
Session 4: Preview, delivery, scheduling and refresh
50 minutesWhy
Four routes decide what the world sees. Preview shows a draft on the real page only to people allowed to read it; delivery serves published versions only; scheduling publishes on time without anyone at a keyboard; refresh rebuilds the pages that changed instead of waiting. The definition of done asks for one test above all: the published API never returns draft content.
Do this
As a person, create the three machine accounts in Supabase Authentication (development, then production), and type their passwords, a new CRON_SECRET and IP_HASH_SALT into Vercel. Add the names, never the values, to docs/KEYS.md.
https://vercel.com/acme-ops/acme-platform/settings/environment-variables
Vercel environment variables (Production and Preview).
Before writing, read the draft mode, caching and revalidation guides in node_modules/next/dist/docs/ and follow this version's API; tell me which guides you read. On the same branch:
1. /api/preview: checks the signed-in person may read that entry, then turns on draft mode; the page then reads current_version_id with the person's own sign-in. A stranger gets nothing; without the cookie a page never shows a draft.
2. /api/content, signed in as cms_delivery: returns published_version_id only. Write in docs/cms-rules.md: live = published_version_id set, archived_at empty, unpublish_at empty or future. Locales follow cms_locale's fallback chain and say which locale was served.
3. /api/cms/publish-due, as cms_scheduler (CRON_SECRET for Vercel's timer, or the publisher's "Run scheduled publishing now" button, which calls the same route): publishes due scheduled entries, archives entries past unpublish_at, and changes nothing on a second run. Read Vercel's cron docs for our plan's limits and tell me the schedule.
4. Every saved version writes cms_entry_reference rows; on publish or unpublish /api/cms/revalidate refreshes the entry and every page that references it.
5. Tests, each shown red first: on the seed, /api/content returns 4 entries before publish-due and 5 after (opening-hours published, old-offer archived); services returns version 1; contact, holiday-notice and kb_articles return not found; the published API never returns draft content; es-MX falls back to es then en; a second publish-due run changes nothing; a page that references a changed entry shows the new title after publish.
Push, wait for every check, and report.You will see recreated screen
- 4 then 5: the same numbers you get by reading the seed.
- It names the guides it read: this Next.js version differs from older examples.
You will see recreated screen
- Only someone allowed to read the draft sees it, and only with the draft-mode cookie.
Check it worked
Every check is green: 4 entries before the scheduled run and 5 after, no draft in any response, es-MX served from es, a second run changes nothing, and a referencing page refreshed on publish. Owner two approves and you merge.
If it goes wrong
The delivery test says 5 before the scheduled run
old-offer is past its unpublish_at but still counted live. Say: Live means unpublish_at empty or in the future; apply it in the delivery read rule, not only in the route.
A preview link shared in a chat shows the draft to anyone
Say: /api/preview must check the signed-in person may read that entry before turning on draft mode; test it as a stranger.
The scheduled run works on the preview but not in production
Vercel runs cron jobs on production deployments only. Use the publisher's button on the preview, and check the first production run on Vercel's cron page after merge.
Claude Code says it works, but the test run is not shown
Say: Show me the exact command, its exit code and the last 20 lines of output from a fresh terminal.
Session 4: Forms that reach a person, and knowledge-base feedback
35 minutesWhy
A website form is often the first contact a customer makes; one that says "thanks" while the enquiry sits in a dead inbox costs business. Storing the consent text exactly as shown with each submission proves what the visitor agreed to, and a failed hand-off must stay visible to someone, never vanish.
Do this
On a new branch cms/forms:
1. As the site administrator's setup, a cms_web_form contact with its fields, consent_text, success_message and spam_protection honeypot (a hidden box only software fills in).
2. POST /api/forms/contact, as cms_form_intake: stores one cms_web_form_submission with the payload, the consent text exactly as shown and the form's row_version inside the payload, utm, ip_hash made with IP_HASH_SALT (never the raw address), submitted_at; it supplies the row's id and later updates that row by id. Then routes it: crm_lead if module M15 is installed, svc_ticket if M19 is, otherwise a core_action_item for the person whose id the site administrator stores in the form's ext.owner_id. Status routed with routed_type and routed_id; on failure status failed, the submission kept and shown on /cms/site. Never say "thank you" before the submission is stored.
3. /kb: Helpful yes or no with a comment writes cms_kb_feedback; the editor sees it.
4. Tests: a valid enquiry ends routed with routed_type and routed_id; a filled honeypot ends spam and creates nothing; a failed hand-off ends failed and visible; a missing consent tick is refused; a feedback row is written by the reader and read by the editor.
Push, open a pull request titled "CMS: forms", wait for every check, and report.You will see recreated screen
| Submitted | Status | Routed to |
|---|---|---|
| 10:14 | routed | core_action_item |
| 10:15 | spam | (honeypot) |
| 10:17 | failed | retry |
- A failure stays in sight with a retry, instead of the visitor being told it worked.
Check it worked
The four form cases produce routed, spam, failed (kept and visible) and refused; the stored submission holds the consent text exactly as shown; a reader's feedback reaches the editor. Owner two approves and you merge.
If it goes wrong
The page says "thanks, we'll be in touch" when routing failed
Say: Show the success message only after the submission is stored; a routing failure keeps the submission, marks it failed and shows it on /cms/site. We have seen pages say a message was sent when it was not.
Form intake can read every past submission
Say: Form intake reads only submissions from the last ten minutes, enough to update the row it just stored; test an 11-minute-old one is refused.
The raw IP address is stored
Say: Store only a hash made with IP_HASH_SALT; never the raw address, in the table or the logs.
Knowledge check
A visitor opens an entry with a newer, unapproved version. What do they see?
Knowledge check
Why must the publisher's read rule cover the row after it is published?
References
- Next.js: revalidateTag. https://nextjs.org/docs/app/api-reference/functions/revalidateTag
- W3C: Understanding Success Criterion 1.1.1, Non-text Content (WCAG 2.2). https://www.w3.org/WAI/WCAG22/Understanding/non-text-content.html
- Supabase Docs: Row Level Security. https://supabase.com/docs/guides/database/postgres/row-level-security
- Vercel Docs: Cron jobs. https://vercel.com/docs/cron-jobs
- Supabase Docs: Storage. https://supabase.com/docs/guides/storage
Chapter 3 · Sessions 5–6
Move the content in, then move the domain
Session 5 imports the old content as drafts that still go through review, builds a redirect for every old address, proves each resolves in one hop or fewer, and adds the sitemap and structured data, rehearsed on the development project with a copy IT approved in writing and removed the same day. Session 6 imports for real through the import workflow a person starts from main, runs old and new side by side, proves the definition of done, moves the domain and cancels the old subscription with the saving written down.
30 min4 stepsSessions 5 and 6Ends with the module gate
By the end of this chapter you can
- Map the old export to content types and import it as drafts with no author, dry run first.
- Build the redirect map from every old address and prove each resolves in one hop or fewer.
- Generate the sitemap and JSON-LD from published versions only.
- Import into production only through import-cms.yml, prove the definition of done, move the domain, switch the importer off and cancel.
| Code (RFC 9110) | Means | Use it for |
|---|---|---|
| 301 | Moved permanently | Almost every migrated address: search engines move their standing to the new page |
| 308 | Moved permanently, method kept | A permanent move of an address that receives form posts |
| 302 / 307 | Found / temporary, method kept | Only a move you will undo |
Session 5: Map the export and build an import that creates drafts
45 minutesWhy
Imported content goes through the same review as anything else, so nothing reaches the public site because a script ran. Mapping fields first, dropping layout and keeping content, means the pages can be reused; holding back any image without a real description keeps the accessibility rule, because a file name is not alt text.
Do this
Take the export yourself (WordPress REST or WXR, Webflow CMS CSV, or a Contentful export) and keep it in a private folder outside the repository. Read what it holds first: exports often include comments, form entries and user accounts, which do not come across.
On a new branch cms/import:
1. docs/cms-mapping.md: each kind of old content to a content type; each old field to a field key; the old author to ext.original_author as text; the old address to ext.source_url; what does not map (shortcodes, page-builder blocks: keep text and images, drop layout). Every old status arrives as draft.
2. docs/cms-rules.md: the public path for each content type and locale.
3. scripts/import-cms.mjs, connecting as the insert-only database login cms_importer (never the service-role key), reading the export from the private Supabase Storage bucket imports. Media pass first: store each file through core_attachment and create cms_media_asset; an image with no real description is stored but gets no media asset and goes on a private list for the editor. Entries pass: cms_entry as draft with no author and version 1, references, and any entry using a listed image held back. on conflict do nothing on (type, locale, slug) and (entry, version_no), so a second run adds nothing. Every imported row carries ext.import_run, the workflow run id. --dry-run prints counts: rows, imported, skipped by reason, held for alt text.
4. .github/workflows/import-cms.yml, started only by hand (workflow_dispatch) from main, refusing any other branch, with inputs target (dev or production), file and dry_run. It reads the file from the private Storage bucket imports of the target project; computes its sha256; refuses the run unless that sha256 and its expected counts (entries, versions, media, redirects, held images) are listed in docs/imports/cms-approved.md on main; and fails if any count differs from the listed one. It uses repository secrets CMS_IMPORT_DATABASE_URL_DEV and CMS_IMPORT_DATABASE_URL_PROD, typed by a person; no GitHub environment and no "required reviewers" (not available for private repositories on our plan): the reviewed pull request that adds the approved line is the approval. Counts in the job summary; never print a secret.
5. docs/imports/cms-approved.md: a heading per approved export with target, file name, sha256, expected counts, the IT approval reference and, for a rehearsal, the date it was removed. Add every new secret's name to docs/KEYS.md.
6. supabase/snippets/remove-cms-rehearsal.sql, for me to run in the development SQL editor: deletes only the rows and files of one ext.import_run, prints the counts, and refuses unless the database is acme-platform-dev.
7. Tests on made-up rows: nothing imported is published; a second run adds nothing; an image named IMG_2041.jpg with no description is held, never given its file name as alt text; the workflow refuses an export not listed and a run whose counts differ.
Push, open a pull request titled "CMS: import", wait for every check, and report. Do not connect to any project.
The export's structure:
<paste the field names or the CSV heading line only, never content rows>You will see recreated screen
- The old author becomes a note, not a person who can approve their own page.
Check it worked
Pull request CMS: import is green, and docs/cms-mapping.md maps every old field or says why it is dropped.
If it goes wrong
Claude Code fills missing alt text with file names or AI guesses
Refuse. Say: Hold the image and list it; the editor writes each description. A wrong description is worse than none for someone using a screen reader.
The export includes comments and user accounts
Leave them out, and say so in docs/cms-mapping.md. They are personal data and not content.
Claude Code runs the import on merge, or adds a GitHub environment with required reviewers
Say: No import on merge and no environments: a person starts import-cms.yml from main, and the merged line in docs/imports/cms-approved.md is the approval. Required reviewers are not available for private repositories on the Team plan.
Session 5: The redirect map, the sitemap, and a rehearsal on the development project
45 minutesWhy
Every old address must reach a live page in one hop or fewer, or visitors and search standing are lost the day the domain moves; chains from earlier migrations are the second pitfall the specification names. A check that can only say "fine" is no check, so it must include an address that must not exist and show it reported as missing. Real content goes into the development project only for this rehearsal, with IT's written approval, and is removed the same day with the date recorded.
Do this
On the same branch:
1. The import writes a cms_redirect (301) for every path in docs/old-urls.txt that changes, straight to its final path (never through another redirect); an address with no new page goes to the nearest parent page, written down in docs/cms-mapping.md, not the home page by habit. on conflict do nothing on from_path.
2. scripts/check-redirects.mjs <base address>: for every path in docs/old-urls.txt, request it without following redirects, count hops, record the final status; pass = a live page in at most one hop. It also requests a path that must not exist and fails unless that path is reported missing (404). Test it with a direct rule, a two-hop chain, a loop and the must-not-exist path.
3. JSON-LD (schema.org WebPage, Product, JobPosting) and /sitemap.xml in the sitemaps.org format, built from published versions only, with last-modified dates. Tests: every sitemap address returns 200 with no redirect; no draft, archived or knowledge_base address appears.
Push to the same pull request, wait for every check, and report.When it merges, as a person: get IT's written approval to load one copy of the export into acme-platform-dev for a rehearsal on one day, redacted where it holds personal data (form entries, comments and user accounts taken out). In the development SQL editor set cms_importer's password from the password manager (alter role cms_importer with login password '…';), and type the connection string into the repository secret CMS_IMPORT_DATABASE_URL_DEV. Upload the copy to the private bucket imports on the development project. Record its sha256 and expected counts in docs/imports/cms-approved.md through a pull request owner two approves and merges. Then start the workflow from main, dry run first.
https://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/storage/buckets
Development Storage: a private bucket named imports; upload the approved copy.
https://github.com/acme-ops/acme-platform/actions/workflows/import-cms.yml
Run workflow from main: target dev, dry_run true, then false.
Then the editor submits the imported drafts, describes the held images, the publisher publishes, and you run the redirect check against the development deployment. The same day, run supabase/snippets/remove-cms-rehearsal.sql in the development SQL editor, delete the file from the bucket, write the removal date in docs/imports/cms-approved.md and tell IT in writing.
node scripts/check-redirects.mjs https://acme-platform-git-cms-import-acme-ops.vercel.appYou will see recreated screen
- Without this line, a site that answers 200 for every address would pass a broken migration. We have seen a probe that could only ever say present.
Check it worked
On the development project: imported plus skipped equals the export, with every reason written; the redirect check passes for every address in docs/old-urls.txt and reports the control path missing; the sitemap and JSON-LD tests pass; a second import run adds nothing. The same day the rehearsal content and the bucket file are removed from the development project, the date is in docs/imports/cms-approved.md, and IT is told in writing.
Fastest path
Fix chains by pointing the first rule straight at the final page (the editor updates to_path on the redirects screen), then run the check again; never add a redirect on top of a redirect.
If it goes wrong
The check passes every address even after you break one on purpose
The site answers 200 for everything (a friendly not-found page that says 200). Say: Make unknown addresses return a real 404 status with the friendly page, and keep the must-not-exist control in the check.
Hundreds of old addresses all redirect to the home page
Search engines treat that like a missing page. Say: Send each to its own new page or nearest parent, and list the ones you could not place for me to decide.
The sitemap lists a knowledge-base article
Say: The sitemap is built by the delivery account from published public versions only; add a test that fails if a knowledge_base address appears.
Session 6: The real import, side by side, and the definition of done
60 minutes over a weekWhy
A week of old and new side by side, compared number by number, lets you move the domain without a leap of faith. The real import goes into production only through the workflow you rehearsed, started by a person from main, reading an export whose sha256 and counts owner two approved, so production is changed by the pipeline, never by a laptop. The three tests of the definition of done are the proof that the new site is no worse than the old one where it matters.
Do this
As a person: in the production SQL editor set cms_importer's password from the password manager, and type the connection string into the repository secret CMS_IMPORT_DATABASE_URL_PROD. Upload the final export to the private bucket imports on production. Record its sha256 and expected counts in docs/imports/cms-approved.md through a pull request owner two approves and merges. Then start the workflow from main with target production, dry run first; any count mismatch fails the run. The editor and publisher review and publish the batch; the old site keeps serving your domain.
https://supabase.com/dashboard/project/abcdefghijklmnopqrst/storage/buckets
Production Storage: a private bucket named imports; upload the approved final export.
https://github.com/acme-ops/acme-platform/actions/workflows/import-cms.yml
Run workflow from main: target production, dry_run true, then false. Save the summary.
node scripts/check-redirects.mjs https://acme-platform.vercel.appnpx lighthouse https://acme-platform.vercel.app/about --only-categories=accessibility,performance --output=html --output-path=./lighthouse-new-about.htmlOn a new branch cms/cutover, write docs/cutover.md from my notes below, with the query or command beside each number:
1. Live pages by space in the old tool and on the platform, and every difference explained.
2. The definition of done: the test that the published API never returns draft content (name and result); check-redirects against https://acme-platform.vercel.app (counts and the control path); Lighthouse accessibility on each seeded template (each 95 or more).
3. Links: run a script that follows every internal link on the live pages and lists failures; list the fixes.
4. Forms: one marked test enquiry through the old form and one through the new, the same day; the new one's routed record and stored consent text; the week's real submissions in both.
5. Measures against Session 1: publishing lead time (median hours from core_audit_log), Core Web Vitals pass rate, form submissions (and conversion only if our analytics counts views), knowledge-base helpful share labelled as such.
Use only my numbers. Open a pull request titled "CMS: cutover".
My notes:
<paste your notes here>You will see recreated screen
| Check | Result |
|---|---|
| Published API returns a draft | never (cms.delivery: 9 of 9) |
| Old addresses in ≤ 1 hop | 214 of 214; control path 404 |
| Lighthouse accessibility, 5 templates | 96, 97, 95, 98, 96 |
| Publishing lead time | 23.3 h (Session 1) → 2.1 h |
- The three tests of the definition of done, and the number Session 1 promised to move.
Check it worked
Production holds the imported content, reviewed and published; docs/cutover.md is on main with live pages compared and explained, the three definition-of-done checks passing against https://acme-platform.vercel.app, links fixed, the form test, and the measures beside Session 1's baselines.
If it goes wrong
Lighthouse accessibility is below 95 on a template
Open the report: it names each failing element (contrast, a missing label, an image without alt text). Say: Fix each item the Lighthouse report lists for this template, and add a test that runs Lighthouse accessibility on the seeded templates in CI.
A difference in live pages has no explanation
You are not ready to move the domain. Find the cause (a mapping, a held image, a page still in review) and compare again.
The workflow refuses the export, or fails on a count
It is doing its job. The file is not the one owner two approved, or it changed since. Take the export again, record its new sha256 and counts through a pull request, and run again; never edit the check.
Session 6: Move the domain, watch the first day, and cancel
45 minutesWhy
Moving the domain is the moment visitors arrive. A lowered time to live, the old record values written down and a named person who decides to roll back make it reversible. The redirect and sitemap checks are run again against the real domain, because a check against the platform address does not prove the domain works. Cancelling comes last, after the final export is safe.
Do this
A day before, with whoever runs DNS (often IT): copy down the current records for www.acme.com and lower their time to live. On the day, add the domain in Vercel and change the records as Vercel shows.
https://vercel.com/acme-ops/acme-platform/settings/domains
Vercel domains: add www.acme.com (and the bare domain), and copy the records Vercel asks for.
nslookup www.acme.comnode scripts/check-redirects.mjs https://www.acme.comThe import is finished. On the same branch: a migration (npx supabase migration new cms_importer_off) that sets cms_importer to NOLOGIN, with a test that it cannot log in; in docs/KEYS.md mark CMS_IMPORT_DATABASE_URL_DEV and _PROD removed with today's date. Then add to docs/cutover.md: the cutover date; who changed which DNS records, and the old values; the rollback rule (how many days the old site and its subscription stay, who decides to go back); the first day (forms arriving, the scheduled run, not-found errors in Vercel's logs and what was fixed); where the last export of the old system is kept and by whom; and the saving: the old yearly cost from invoices minus what the module adds to services we already pay for, as arithmetic. Then update docs/cms-inventory.md: each place and tool replaced, retired or kept, with the date. Use only my numbers.
My notes:
<paste your notes here>When it merges, the deploy workflow applies the NOLOGIN migration to production; delete the two CMS_IMPORT_DATABASE_URL secrets on GitHub. Tell the search engines you use where the sitemap is. After the agreed days with no rollback: take and store a last export, read the cancellation terms on your own account page, cancel, and remove every old user and shared login.
You will see recreated screen
- Valid and secured. Then run the redirect check against the real domain, not the platform address.
Check it worked
www.acme.com serves the new site on a phone; the redirect check against it passes with the control path missing; docs/cutover.md holds the date, old record values, rollback rule, first day and the saving from invoices; cms_importer is NOLOGIN and its secrets are deleted; the old system is cancelled after the agreed days, or its end date written.
If it goes wrong
Visitors still see the old site hours later
Their computers remember the old address until the time to live runs out. Check with nslookup from two networks; this is why it was lowered a day ahead.
Not-found errors rise in Vercel's logs on the first day
Copy the paths into Claude Code: These old paths return 404 on the live domain. Add each to docs/old-urls.txt, propose a redirect straight to its new page, and rerun check-redirects.
Someone wants to cancel before the rollback days are over
Wait. Cancelling removes the way back; the old system costs little more for a few days than a failed cutover does in an hour.
Knowledge check
Which redirect code fits a page that has moved for good, when its method may change?
Knowledge check
Why does check-redirects request an address that must not exist?
References
- IETF RFC 9110: HTTP Semantics. https://www.rfc-editor.org/rfc/rfc9110.html
- sitemaps.org: The Sitemaps protocol. https://www.sitemaps.org/protocol.html
- Google Search Central: Redirects and Google Search. https://developers.google.com/search/docs/crawling-indexing/301-redirects
- Google Search Central: Site moves with URL changes. https://developers.google.com/search/docs/crawling-indexing/site-move-with-url-changes
- schema.org. https://schema.org/
- web.dev: Web Vitals. https://web.dev/articles/vitals
Chapter 4 · 12 questions · 80% passes
Final assessment
Twelve questions across the module. Score 80% (10 of 12) to pass. Your LMS records your score and each answer; you can review the chapters and try again.
15 min12 questions≈ 15 minutesRetake allowed
Your result
CivOps AI Academy
Website and Content: A Headless CMS for the Site, the Catalogue and the Knowledge Base
Element M17 complete · Learner
Your LMS records this completion. For the CivOps Foundation certificate, finish the Foundation Course at https://civops.io/learn.