Chapter 1 · Sessions 1–2
What the old handover holds, and the tables that replace it
Before anything is built, you find out how one area hands a shift over today, what the tool or chat costs, and what gets lost between crews. Then one prompt adds the module's nine tables to your Foundation schema, with the tests that try to break them and a made-up seed, and you try them on the development project before the pipeline takes them to production.
30 min5 stepsSessions 1 and 29 shf_ tablesabout 7.5 hours hands-on across six sessions
By the end of this chapter you can
- Inventory one area's handover, its tool and its losses from the logs and the bills, inventing nothing.
- Write down what the handover must carry and where each item comes from, and settle it with both leads.
- Add the shf_ tables with one prompt, prove them on the development project, and let the pipeline apply them to production.
Check your names once. Every prompt, command and address below uses them.
Saved with your progress. Every prompt, command and address in the course now uses these names. Change them any time from Your names at the top of the page.
What Shift handover replaces
Shift handover gives every area a structured, searchable operations log and a consistent, signed handover filled in from live data, so open issues, holds, permits and equipment out of service cannot be lost between crews. It replaces electronic shift logs and handover tools; the module library names Hexagon j5 Shift Operations Management [1], Eschbach Shiftconnector [2], Tervene, Shiftworx, MaintainX (partly) and SharePoint or Excel logs. A paper logbook, a whiteboard or a chat group is a shift log too, and just as likely to lose a note.
| Standard | Used in this module for |
|---|---|
| UK HSE human factors: safety-critical communication at shift handover [3] | A structured, two-way handover, written plus spoken |
| API RP 1168, Control Room Management | Handover content and fatigue-aware practice in control rooms |
| ANSI/ISA-18.2 (IEC 62682) | Alarm management principles for the event rules that write log entries |
| 21 CFR Part 11 [4] | Signed handovers and acknowledgements, where the log is a regulated record |
Session 1: Inventory one area's handover and what it costs
40 minutes, most of it in the areaWhy
The module must replace the handover people really do, not the one in a procedure. Reading two weeks of the old log and sitting in on one live handover finds the losses nobody reports: the note that never reached nights, the hold the next crew did not know about. The bills tell you what the old tool costs. Claude Code writes it up in minutes, inventing nothing.
Do this
Choose one area that runs at least two shifts. With its supervisor's permission, read the last two weeks of its shift log or handover notes, and sit in on one live handover. Write down: the shifts and their times, who hands over to whom, where and how long, spoken or written or both, and three things that got lost between crews (with the date, never a person's name, and nothing that describes an injury). Open the old tool's bill on the vendor's own account page: amount and renewal date as printed, and what export it offers. Keep any copies in a private folder, never in the repository. Then:
cd ~/code/acme-platform && git switch main && git pull && claudeI am starting the Shift handover module (M02). It replaces our shift log and handover tool with the platform. Do not write any code in this session.
On a new branch m02/inventory, create docs/handover-inventory.md from my notes below, with:
1. The area's shift pattern: the shifts with start and end times, the crews (jobs, never names), and one line for every handover: who hands over to whom, where, how long, spoken, written or both.
2. What a handover carries today, item by item, and where each item comes from (a screen, a whiteboard, memory).
3. Three things that were lost between crews: date, what was lost, what it cost (as I describe it), and what would have caught it.
4. Tools: name, owner (a job), the bill amount and renewal date exactly as I give them, and the export it offers.
Use only what is in my notes. Never fill in a price, a count, a date or a vendor feature I have not given you: write "unknown, ask <who>" instead. No person's name anywhere. End with "Questions to settle".
Open a pull request titled "M02: handover inventory", wait for the checks, and tell me the result in plain words.
My notes:
<paste your notes here>You will see recreated screen
- Every handover, how it happens today.
- The losses are the case for the module, in your plant's words.
Check it worked
docs/handover-inventory.md is in a pull request with every handover, three losses, every bill copied from an invoice or marked with who to ask, and no person named.
If it goes wrong
Claude Code fills in a cost or a count you did not give it
Say: Remove every figure I did not give you and write unknown, ask <who>. Agents fill empty places so a page looks finished; on our platform a report showed a revenue figure the customer never gave. The saving you claim in Session 6 is only as good as these figures.
The old log is a chat group
It still counts. Export the chat if the service allows it, or note the dates you read. Do not copy messages that name people into the repository.
Session 1: Write down what the handover must carry, and settle it with both leads
20 minutesWhy
The handover report is filled in automatically from other modules and from the log, so every item must have a source. Writing the list now, with the outgoing and incoming leads, decides the snapshot's contents, the categories people will really use, and how many minutes after shift end a handover may wait before it escalates. Each of those becomes a rule in a table next session.
Do this
Read docs/handover-inventory.md. On a new branch m02/content, write docs/handover/content.md for someone who does not write code:
1. Every item the handover report must carry for this area, and its source: the platform's own log (open and carried entries, equipment out of service, active standing orders), or another module's event (mes.shift_summary.ready for production against plan, OEE and downtime; cmms.work_order.status_changed for open work orders; qms.hold.placed for holds; ehs.permit.activated for active permits; ehs.incident.reported for safety events). Mark items whose module we do not have yet as "not yet available".
2. The log categories we will use (from production, quality, safety, maintenance, environmental, process, logistics, general) with one real example each from the inventory, and what each priority (info, low, medium, high, critical) means here.
3. N: how many minutes after shift end a handover must be accepted before it escalates, and who is told.
End with "Questions for the leads". Open a pull request titled "M02: handover content", wait for the checks, and show me the link.Read it on GitHub with the outgoing and the incoming lead of one handover. Then:
The leads answered the questions in docs/handover/content.md:
1. <their answer>
2. <their answer>
They also said: <anything else they changed>.
Update the file, add "Checked with the outgoing and incoming leads on <today's date>" at the top, and push to the same pull request.You will see recreated screen
- Each item with its source. Items from modules you do not have yet are listed, not invented.
- Your N, decided by the people who hand over.
Check it worked
docs/handover/content.md is merged with every item's source, the categories with real examples, N in minutes and who is told, signed off with both leads and the date.
If it goes wrong
The leads want everything in the snapshot
Ask what the incoming lead reads first, in the first five minutes. Put that first; the rest can be one click away in the log. A report nobody finishes reading is a lost handover too.
Nobody agrees on N
Take the time the procedure gives, or 30 minutes, write it down as provisional, and look at the on-time rate after the side-by-side week in Session 6.
The nine tables
The module library puts standard columns on every table: id, created_at, created_by, updated_at, updated_by, row_version, archived_at and ext, and a tenant_id; on your platform module tables carry site_id in place of tenant_id, so each keeps one simple access rule. The shared file docs/spine-map.md says which Foundation table plays each core_ name, the same for every module. The module keeps no list of people, equipment or shifts of its own; it points at the shared spine: core_shift_instance (one real run of a shift, such as the afternoon of 2 November), core_shift_definition, core_equipment (an area is equipment at the area level of the ISA-95 hierarchy [5]), core_person, core_data_tag and core_e_signature.
| Table | One row is | Columns (req = required; {a, b} = only these values; → points to) |
|---|---|---|
| shf_shift_log | The log for one area and one shift | shift_instance_id → core_shift_instance req; area_equipment_id → core_equipment req; status req {open, handed_over, closed}; lead_person_id → core_person |
| shf_log_entry | One operational event or note | shift_log_id → shf_shift_log req; equipment_id → core_equipment; category req {production, quality, safety, maintenance, environmental, process, logistics, general}; priority req {info, low, medium, high, critical}; title text req; body text; status req {open, monitoring, closed}; carry_forward bool req; occurred_at ts req; author_id → core_person req; linked_type text; linked_id uuid; origin req {manual, event_rule, import} |
| shf_handover | The signed handover between two leads | shift_log_id → shf_shift_log req; outgoing_lead_id → core_person req; incoming_lead_id → core_person; summary text; auto_snapshot json; signed_out_at ts; signed_in_at ts; outgoing_signature_id → core_e_signature; incoming_signature_id → core_e_signature; status req {draft, signed_out, accepted, escalated} |
| shf_standing_order | A time-bound instruction to acknowledge | order_no text req, unique; title text req; body text req; area_equipment_id → core_equipment; issued_by → core_person req; effective_from ts req; effective_to ts; requires_ack bool req; priority req {normal, high, critical}; status req {draft, active, expired, withdrawn} |
| shf_standing_order_ack | One person's acknowledgement of one order | standing_order_id → shf_standing_order req; person_id → core_person req; acknowledged_at ts req; signature_id → core_e_signature |
| shf_task_template | A recurring shift task | area_equipment_id → core_equipment req; title text req; shift_definition_id → core_shift_definition; rrule text; form_template_ref → frm_template (soft link); active bool req |
| shf_shift_task | One task for one shift | shift_log_id → shf_shift_log req; task_template_id → shf_task_template; title text req; assignee_id → core_person; due_at ts; done_at ts; result {done, not_done, not_applicable, issue_found}; note text |
| shf_event_rule | A rule on a data tag that writes entries | name text req; data_tag_id → core_data_tag req; condition json req; category text req; priority text req; dedupe_window_min int; active bool req |
| shf_event_occurrence | One firing of a rule, and the entry it made | event_rule_id → shf_event_rule req; triggered_at ts req; value text; log_entry_id → shf_log_entry; suppressed bool |
Two links are deliberately soft, a uuid with no foreign key, because the module must work without the other module: form_template_ref (an M01 form) and linked_type with linked_id (the record an entry led to). The module library names two pitfalls: free-text entries with no equipment link, which can be read but never counted, and recomputing the snapshot when the handover is viewed, which Chapter 3 prevents.
Session 2: Check the spine before adding to it
10 minutesWhy
The module points at shared tables for shifts, crews, equipment, people, tags and signatures. If Claude Code cannot find them it creates its own, and you get two lists of equipment that drift apart. A read-only report first shows what exists, what plays the role under another name, and what is missing.
Do this
Read docs/spine-map.md (if another module made it), docs/SCHEMA-PLAN.md, docs/naming-standard.md, docs/matrix.json and every file in supabase/migrations. Do not change anything.
Shift handover (M02) needs these shared ("spine") tables and helpers. For each one: exists (file and line), exists under another name (which table plays the role, for example our equipment table for core_equipment), or missing:
core_person, core_site, core_equipment (with an area level), core_shift_definition, core_shift_instance, core_crew (with lead_person_id), core_data_tag, core_e_signature, core_attachment, core_comment, core_action_item, core_notification, core_event_outbox, core_number_sequence, core_audit_log, and a trigger that sets updated_at, updated_by and row_version.
Then tell me how a person's own area could be recorded (for example ext.area_id on the person), and how our generated access rules decide which rows a person may see. Finish with a short plan: the rows M02 adds to docs/spine-map.md, and one spine migration that adds only what is missing and reuses the rest. Our module tables carry site_id in place of tenant_id.You will see recreated screen
- Reuse: your equipment table already has the area level.
- Pieces another module already added are found, not rebuilt.
- Only these are new.
Check it worked
Every spine name is marked exists, exists as, or missing, and the plan reuses your Foundation and earlier module tables instead of creating copies.
If it goes wrong
The plan creates core_equipment next to your equipment table
Say: Reuse equipment for core_equipment. Never create a second table for something we already keep. Two names for one thing is how a rename goes half done: on our platform three ids for one demo company were live at once.
Shift times are hard-coded in the plan
Say: Shift definitions are rows in core_shift_definition, with start and end times and a time zone, so a change of shift pattern is data, not code.
Session 2: One prompt: the spine pieces, the shf_ tables, their tests and the seed
20 minutesWhy
The tables, the tests that try to break them and the made-up data in one pull request means the proof arrives with the change and the next sessions have something to build on. The seed's counts are fixed now, so in Session 4 you can count them by hand and check every view against your count.
Do this
Read docs/handover/content.md, docs/naming-standard.md, docs/matrix.json and the spine plan you just gave me.
On a new branch m02/schema:
1. A spine migration (npx supabase migration new m02_spine) with only the missing pieces from the plan, each with the standard columns (id uuid primary key default gen_random_uuid(), created_at, created_by, updated_at, updated_by, row_version, archived_at, ext jsonb) and site_id in place of tenant_id, reusing our existing tables where they play the role. Every function has set search_path = ''. Add M02's rows to docs/spine-map.md (create it if missing).
2. The module migration (npx supabase migration new m02_shf_tables): these nine tables with the standard columns, a site_id and every column below. req means not null; {a, b} is a check constraint; → is a foreign key; "person" and "equipment" mean the tables the plan uses.
shf_shift_log: shift_instance_id → core_shift_instance req, area_equipment_id → equipment req, status req {open, handed_over, closed}, lead_person_id → person
shf_log_entry: shift_log_id → shf_shift_log req, equipment_id → equipment, category req {production, quality, safety, maintenance, environmental, process, logistics, general}, priority req {info, low, medium, high, critical}, title text req, body text, status req {open, monitoring, closed}, carry_forward bool req, occurred_at timestamptz req, author_id → person req, linked_type text, linked_id uuid, origin req {manual, event_rule, import}
shf_handover: shift_log_id → shf_shift_log req (one per log), outgoing_lead_id → person req, incoming_lead_id → person, summary text, auto_snapshot jsonb, signed_out_at timestamptz, signed_in_at timestamptz, outgoing_signature_id → core_e_signature, incoming_signature_id → core_e_signature, status req {draft, signed_out, accepted, escalated}
shf_standing_order: order_no text req (unique per site, from core_number_sequence), title text req, body text req, area_equipment_id → equipment, issued_by → person req, effective_from timestamptz req, effective_to timestamptz, requires_ack bool req, priority req {normal, high, critical}, status req {draft, active, expired, withdrawn}
shf_standing_order_ack: standing_order_id → shf_standing_order req, person_id → person req (one per person per order), acknowledged_at timestamptz req, signature_id → core_e_signature
shf_task_template: area_equipment_id → equipment req, title text req, shift_definition_id → core_shift_definition, rrule text, form_template_ref uuid (soft link to frm_template, no foreign key), active bool req
shf_shift_task: shift_log_id → shf_shift_log req, task_template_id → shf_task_template, title text req, assignee_id → person, due_at timestamptz, done_at timestamptz, result {done, not_done, not_applicable, issue_found}, note text
shf_event_rule: name text req, data_tag_id → core_data_tag req, condition jsonb req, category text req, priority text req, dedupe_window_min int, active bool req
shf_event_occurrence: event_rule_id → shf_event_rule req, triggered_at timestamptz req, value text, log_entry_id → shf_log_entry, suppressed bool
Every table: row-level security on with no policies yet, the update and audit triggers, an index on every foreign key. A trigger refuses any change to a closed log entry. linked_type and linked_id have no foreign key.
3. Add every new table to docs/matrix.json with no rights yet.
4. pgTAP tests in supabase/tests/m02_schema.test.sql: every new table exists with a primary key and row-level security on; a bad category, a bad status, a duplicate order number, a second handover for one log and an update of a closed entry are each refused.
5. Made-up data in supabase/seeds/m02.sql, listed under [db.seed] sql_paths in supabase/config.toml, marked SYNTHETIC, shifted onto today from one moment read once at the start, and safe to run twice: the press shop area with six presses (P-04 out of service); two shift definitions (Days 06:00 to 14:00, Afternoons 14:00 to 22:00) and two crews, each with a lead; shift instances for the last two days; three leads, nine operators in the area, one standing-order issuer and one log administrator, all SYNTHETIC; fourteen log entries over the first three logs (five open, two monitoring, seven closed; three open and one monitoring with carry_forward true; every category and priority used); three handovers with fixed auto_snapshot values: the first accepted 10 minutes after its shift ended, the second 50 minutes after, the third signed out and never accepted; standing order SO-0001 active and requiring acknowledgement from the nine operators: six before it took effect, one after, two never; one event rule on one synthetic tag with a 30-minute dedupe window.
The hand-worked examples, with fixed dates, go in tests/fixtures/m02-hand-count.json (the same entries, handovers and acknowledgements) and tests/fixtures/m02-tag-stream.json (episodes 06:00–08:00, 09:00–09:10, 09:25–09:35 and 13:00–13:30), not in the seed. Add a test that loads the hand-count fixture and counts exactly that.
6. Do not connect to or change any Supabase project, and do not run supabase db push.
Push, open a pull request titled "M02: shf tables", wait for every check, and tell me in plain words: the tables added, the tests run and the fixture's counts. If a check fails, fix it and wait again before reporting. End with the exact commands I must type myself to try this on the development project.You will see recreated screen
- Spine first: its earlier time makes it run first everywhere.
- Every allowed value is a rule in the table, not only in a screen.
- The counts you hand-count in Session 4.
Check it worked
Pull request M02: shf tables is green on GitHub, and the summary gives the fixture counts: 14 entries (5, 2, 7; 4 carried), 3 handovers, 6 of 9 acknowledged in time.
Fastest path
"Wait for every check and fix it before reporting" saves a round trip: Claude Code reads the failure while you do something else.
If it goes wrong
CI fails: relation "core_shift_instance" does not exist
The module migration ran before the spine migration. Say: Give the spine migration a timestamp before the module migration on this branch, re-run the tests and push. Only rename migrations that have not reached any database.
The seed uses fixed dates
Say: Count every time back from one moment read once at the start of the seed. We hit this: a seed with fixed dates was ten days old by the next week, and every "this shift" panel was blank.
Claude Code says green, GitHub says red
Say: The check on the pull request is red. Run gh pr checks, read the failed log, fix the cause and wait for green before you report. A summary is a claim; the check is the evidence.
Session 2: Try it on the development project yourself, then merge
15 minutesWhy
A merge applies migrations to production automatically (Foundation Session 11), so the last place to catch a problem is before it. Applying the branch to the development project yourself shows the tables build on a database that already holds your Foundation data. Only a person does this, with the password from the password manager.
Do this
In a terminal, not inside Claude Code:
cd ~/code/acme-platform && git fetch && git switch m02/schema && git pullnpx supabase link --project-ref tsrqponmlkjihgfedcbaType the development project's database password from the password manager (nothing shows as you paste). Check, then apply the migrations and the seed. --include-seed is for the first time a seed file is added; after that, reload made-up data with npm run seed:dev. Never supabase db reset on a project.
npx supabase migration listnpx supabase db push --include-seedhttps://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/editor
The development project's Table Editor: shf_log_entry holds the fourteen SYNTHETIC entries.
Owner two (sam@acme.com) approves; merge. The deploy pipeline applies the migrations to production:
https://github.com/acme-ops/acme-platform/actions
The deploy run for the merge: green, two migrations applied.
You will see recreated screen
- Two new files, on your branch only.
- Check you linked tsrqponmlkjihgfedcba, the development project. If it lists files you do not expect, answer n.
You will see recreated screen
Applying migration 20261102094000_m02_spine.sql... Applying migration 20261102094500_m02_shf_tables.sql... Finished supabase db push.
- The pipeline, after review, changed production; no person ran db push there.
Check it worked
The development project has the shf_ tables and the SYNTHETIC rows from supabase/seeds/m02.sql; the deploy run is green; production's Table Editor (https://supabase.com/dashboard/project/abcdefghijklmnopqrst/editor) shows the shf_ tables, empty.
If it goes wrong
db push: Remote migration versions not found in local migrations directory
The development project has a migration this branch does not, often another module's branch tried there. Do not force anything. In Claude Code: supabase db push on the development project says remote versions are not in the local directory. Tell me which versions differ and which branch each came from, without changing any project.
The deploy run fails on the migration
Good: the pipeline stopped before the code went live. Do not fix it in the dashboard. In Claude Code: The deploy failed applying the m02 migrations. Show me the error and write the fix as a new migration on a new branch. Our production once fell nine migrations behind main because nothing applied them.
The seed fails with a duplicate key
Every seed must be safe to run twice. Say: supabase/seeds/m02.sql failed with a duplicate key when run again. Make it safe to run twice and add a test that runs it twice. Then reload with npm run seed:dev. Never use supabase db reset to get round it.
Knowledge check
Which of these does Shift handover leave to another system?
Knowledge check
Which entry can the analytics count later?
References
- Hexagon: j5 Shift Operations Management help. https://docs.hexagonppm.com/r/en-US/j5-Shift-Operations-Management-Help/Version-30/1046047
- Eschbach: Shiftconnector digital shift book. https://www.eschbach.com/en/shiftlog/
- UK Health and Safety Executive: human factors. https://www.hse.gov.uk/humanfactors/
- eCFR: Title 21, Part 11, Electronic records; electronic signatures. https://www.ecfr.gov/current/title-21/chapter-I/subchapter-A/part-11
- ISA: ISA-95 standard, Enterprise-Control System Integration. https://www.isa.org/standards-and-publications/isa-standards/isa-95-standard
- Supabase CLI reference: supabase db push. https://supabase.com/docs/reference/cli/supabase-db-push
Chapter 2 · Session 3
Who may do what, and the screens
Rights to the log, the handover and standing orders are decided once, in the role matrix, and the rules, the route list and the tests are generated from it. Then Claude Code builds the shift log, the handover report, the standing orders page and an offline phone view, and two leads try them at a real handover.
25 min4 stepsSession 35 roles + 2 machine accounts6 screens
By the end of this chapter you can
- Add the module's roles, scopes, screens and machine accounts to docs/matrix.json and regenerate the rules and tests.
- Have Claude Code build the screens with identity from the session and photos kept out of the project folders.
- Prove the phone view sends what was written offline exactly once, and watch two leads use it at a real handover.
Rights start from nothing
Every role starts with no rights. Nobody deletes: a correction is a new entry or a status change, and a closed entry is never edited. Two scopes need a record behind them: a person's own area (ext.area_id on their membership, the area's equipment row) and a lead's own shift (the shift log's lead_person_id, copied from the crew's lead when the log opens). Role-based access control is described by NIST [2]; on your platform it is enforced row by row by the database [1].
| Role (a job) | Scope | What they do |
|---|---|---|
| operator | Own area | Write entries with photos and comments, finish shift tasks, acknowledge standing orders, use the phone view offline |
| outgoing lead | Own area, own shift | As an operator, plus change any entry's status in the area, write the handover and sign out |
| incoming lead | Own area | As an operator, plus work carried entries, ask on the handover and sign in |
| standing-order issuer | Site | Issue, activate and withdraw orders, track acknowledgements, receive escalations |
| log administrator | Site | Task templates, event rules, the import, read everything at the site |
| machine: shift scheduler | Named jobs only | Open logs, make draft handovers, escalate, expire orders |
| machine: event evaluator | Named jobs only | Write entries and occurrences from event rules |
| Screen | Address | Who may open it |
|---|---|---|
| Shift log | /shift/log | operator, outgoing and incoming lead |
| Handover report, sign-out and sign-in | /shift/handover | outgoing and incoming lead |
| Standing orders to acknowledge | /shift/orders | everyone in the area |
| Issuer's page | /shift/orders/issue | standing-order issuer |
| Templates, rules and import | /shift/admin | log administrator |
| Offline phone view | /shift/field | operator, outgoing and incoming lead |
Session 3: The module's rows in the matrix, and the rules generated from them
20 minutesWhy
One reviewed line in the matrix decides each right, and the database rules, the route guard and the tests all follow from it, so they cannot disagree. Testing in both directions, and reading a row back after every allowed change, catches the two access mistakes we hit most: a role that can do too much, and an update that reports success and changes nothing.
Do this
Read docs/matrix.json, scripts/gen-policies.mjs, lib/access/routes.ts and docs/access-review.md. Never edit a generated file by hand.
On a new branch m02/access, add Shift handover to the matrix:
- Roles (jobs): operator, outgoing lead, incoming lead, standing-order issuer, log administrator, reusing ours where they fit; and two machine accounts with named jobs only: shift scheduler (runs inside the database as a pg_cron job, so it never signs in) and event evaluator (signs in with its own password, set by a person and listed by name in docs/KEYS.md; never the service role key).
- Scopes: own area = the area in ext.area_id on the person's membership; own shift = the shift log's lead_person_id, or a handover's outgoing_lead_id, is the person.
- Rights, starting from nothing:
operator: read the area's logs, entries, handovers and active orders; insert entries (origin manual) and comments and photos on them; finish their shift tasks; insert their own acknowledgement and its signature; read their own signatures and the attachments on the area's entries.
outgoing lead: as operator, plus update any entry's status in the area while it is not closed, and insert and update the handover of their own shift while it is a draft, and sign out.
incoming lead: as operator, plus sign in a signed_out or escalated handover of their area, never one they signed out.
standing-order issuer: insert and update standing orders at the site; read acknowledgements; read escalations.
log administrator: task templates and event rules at the site; read everything in the module at the site.
shift scheduler: insert shift logs and draft handovers; set status to escalated; set orders to expired; insert notifications.
event evaluator: insert entries with origin event_rule and occurrences.
Nobody deletes. A closed entry never changes.
- Screens: /shift/log, /shift/handover, /shift/orders, /shift/orders/issue, /shift/admin, /shift/field, and the route the phone view sends to, /api/shift/sync.
Run scripts/gen-policies.mjs and scripts/gen-routes.mjs, then add to supabase/tests/access.test.sql one allowed and one refused test for every new cell, and: an operator of another area sees nothing here; nobody signs both sides of one handover; an operator cannot change a handover; for every role that updates a row, read it back and check it really changed.
Push, open a pull request titled "M02: who may do what", wait for every check, and tell me the result in plain words, quoting the new sections of docs/access-review.md.You will see recreated screen
- Rights by job and scope, reviewed in one place.
- A machine account is a role too, with the narrowest rights.
Check it worked
The pull request is green, docs/access-review.md has a section for each new role and machine account, and the tests include the cross-area, both-sides and read-back tests.
If it goes wrong
Signing in a handover says success but the status stays signed_out
An update only finds rows the role can read, and the changed row must still pass the read rule; we hit this building the module courses. Say: Make the incoming lead's read rule cover the handover before and after sign-in, regenerate, and add a test that reads the row back.
A photo upload is refused although the operator may write entries
An insert that hands the new row back counts as a read. Say: Give the operator read on the attachments of their area's entries, regenerate, and test the upload end to end.
A check fails that names a generated list
The generated files are older than the matrix. Say: Open the failed check's log, run the command it names to regenerate, commit, and show me what changed.
Session 3: The shift log, the handover report and standing orders
25 minutesWhy
These screens are where the record is made and read at shift change, often in a hurry. Who wrote an entry must come from the session on the server, never from the page, and photos must go to Supabase Storage: the app's own folders cannot be written on Vercel, and anything in public/ can be opened by anyone.
Do this
Before writing any page or route, read the guides in node_modules/next/dist/docs/ for routing, server actions and proxy.ts in our version of Next.js, and our operator-screen rules from Session 12.
On a new branch m02/screens, build against the development data:
1. /shift/log: the current shift's log for the person's area: carried entries first with their age, then this shift's; add an entry with equipment (required unless "whole area" is chosen), category, priority, title, body, carry-forward, photos (private Supabase Storage bucket, never public/ or a project folder) and mentions; filter and full-text search by area, equipment, category and dates.
2. /shift/handover: the handover report for the outgoing lead: the summary to write and, before sign-out, a preview of what the snapshot will hold; for the incoming lead, the stored snapshot, the carried entries, questions as comments, and Sign in.
3. /shift/orders: active standing orders for the area with an Acknowledge button; /shift/orders/issue for the issuer with who has and has not acknowledged.
4. /shift/admin for task templates and event rules (forms only; the rules engine comes in Session 4).
Who is signed in comes from the session on the server, never from the page. Everything goes through proxy.ts and the generated lib/access/routes.ts; nothing public. Playwright tests at 360 and 390 px for each role that may open each screen, a refused test for each role that may not, and a signed-out test that each lands on sign-in.
Push, open a pull request titled "M02: screens", wait for every check and the Vercel preview, and tell me the preview link and what each test proved.You will see recreated screen
- Carried items first, so nobody starts a shift without them.
- Each entry names its press, category and priority, and shows its age.
- 44 px targets; equipment is required unless the whole area is chosen.
Check it worked
The pull request is green; the preview opens each screen for its roles at phone width and refuses the others; a photo added in the preview is in the Storage bucket, not the repository.
If it goes wrong
Photos save in development and vanish on the preview
The code wrote into a project folder, which is read-only on Vercel; we hit this when a register wrote where the server could not. Say: Store every photo in the private Supabase Storage bucket and add a test that fails if code writes into the project folders.
Every entry shows the same author
The page sent the author and the server trusted it; on our platform every record said it was made by the founder. Say: Take author_id from the signed-in session on the server and ignore anything the page sends. Add a test with two users.
Claude Code writes middleware.ts
This version of Next.js calls it proxy.ts. Say: Read node_modules/next/dist/docs/ on proxy.ts, use our proxy.ts, and delete middleware.ts.
Session 3: The offline phone view, and the test that proves it
20 minutesWhy
Operators write entries at the press, where the signal is worst. The phone view keeps the area's open and carried items on the phone and sends what was written when the signal returns, once. A save that said "created" and was later gone is a failure we have had, so the prompt asks for tests that are shown failing first.
Do this
On a new branch m02/field, build /shift/field, reusing the outbox from Session 12:
- On opening, it keeps the area's open and carried entries and active orders on the phone (IndexedDB).
- A new entry or comment gets its id on the phone with crypto.randomUUID(), is saved as it is typed, and waits in the queue with the phone's occurred_at; the screen shows how many are waiting.
- /api/shift/sync inserts with on conflict (id) do nothing, takes author_id from the session, and keeps the phone's time as occurred_at and the server's as created_at. The same id again adds nothing; the same id with different text is refused as a conflict and shown. A refused item stays visible in the queue. If the sign-in expired, the queue waits for sign-in.
- Acknowledging a standing order needs a fresh password, so it stays online; the phone view says so.
Playwright tests with the browser offline: write three entries, close and reopen, still three waiting; go online, exactly three new entries with the phone's times; send them again, still three; a conflicting copy is refused and shown. Show each test failing with the on conflict line removed, then passing.
Push, open a pull request titled "M02: offline phone view", wait for every check, and tell me the result in plain words.You will see recreated screen
- Without the safety line a retry stores entries twice: the test can fail, so it proves something.
- Green on GitHub, not only on Claude Code's word.
Check it worked
The pull request is green, and the summary says the tests failed with the safety line removed and passed with it.
If it goes wrong
The screen says "Saved" but no entry arrives
Say: Count an entry as sent only when the sync route answered with its id; otherwise keep it in the queue and say so. Add a test with the route switched off. A button that claims success while nothing happens is worse than an error.
Two leads change the same entry's status at once, and one change is lost
We hit this: a save said "Created" and a minute later the record was gone. Say: Include row_version in every update of shf_log_entry and refuse a stale save with a clear message; test two saves from the same starting copy.
The tests pass even with the safety line removed
They cannot fail, so they prove nothing. Say: Rewrite the test to count rows in the database; show it red without the fix and green with it.
Session 3: Try it at a real handover
20 minutesWhy
A handover happens in ten minutes at the end of a long shift. Watching two real leads use the screens at one, without explaining anything, finds what no test can: the item they look for first, the word they do not understand, the button they cannot find with a cold thumb.
Do this
https://github.com/acme-ops/acme-platform/pulls
Open the M02 screens and phone view pull requests: Vercel's comment on each has the preview link.
On a real phone: airplane mode on, write one entry, reconnect, watch it arrive. Then, at one real handover, let the outgoing lead use the preview's handover report beside the usual handover (the old way stays the record until Session 6), and the incoming lead read it. Say nothing; write down every place either stops or asks. Then:
Here are my notes from two leads trying the M02 screens at a real handover:
<paste your notes>
Write each as a one-line change request in docs/m02/try-out.md, marked screen, wording, or rule. Make the screen and wording changes on this branch with their tests; list the rule changes for me to decide. Push, wait for the checks, and tell me what changed.Owner two approves each pull request; merge in order: access, screens, phone view.
You will see recreated screen
| Snapshot item | At sign-out |
|---|---|
| Presses out of service | P-04 |
| Open and carried entries | 4 |
| Active standing orders | SO-0001 |
- Who signed out and when, from the session.
- What the outgoing lead saw, stored, not recomputed.
- Two-way: the incoming lead can ask before signing.
Check it worked
An entry written in airplane mode arrived once; docs/m02/try-out.md lists what the leads hit; the three pull requests are merged.
If it goes wrong
The preview link answers 401
That is Vercel's preview protection, not your code. Sign in to Vercel on the phone, or use Vercel's Share button for the preview.
The leads say the report is too long
Ask what the incoming lead reads first, and move it to the top. Write the change in docs/handover/content.md too, so Session 4's snapshot follows it.
Knowledge check
An operator's photo upload on an entry is refused, though operators may write entries. Why, most likely?
Knowledge check
Where is "nobody signs both sides of one handover" written first?
References
- Supabase Docs: Row Level Security. https://supabase.com/docs/guides/database/postgres/row-level-security
- NIST: Role-based access control project. https://csrc.nist.gov/projects/role-based-access-control
- MDN: IndexedDB API. https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API
- Playwright: BrowserContext.setOffline. https://playwright.dev/docs/api/class-browsercontext#browser-context-set-offline
- W3C: WCAG 2.2, Understanding Target Size (Enhanced). https://www.w3.org/WAI/WCAG22/Understanding/target-size-enhanced.html
Chapter 3 · Session 4
The handover, standing orders and event rules
The handover becomes a record the next crew can rely on: its snapshot is stored when the outgoing lead signs out and is byte-identical a week later, both leads sign, and one nobody accepts escalates on schedule. Standing orders are acknowledged person by person, an event rule writes exactly one entry per episode, and the three KPIs must match your count of the seed.
25 min4 stepsSession 43 definition-of-done tests1 hand count
By the end of this chapter you can
- Store the snapshot at sign-out, sign both sides, and prove the stored record does not drift.
- Escalate an unaccepted handover once, on schedule, and track standing order acknowledgements per person.
- Make an event rule write one entry per condition episode, and check the KPIs against a hand count.
Stored, not recomputed
The module library names this pitfall first: recomputing the snapshot whenever the handover is opened. A week later the work orders have moved on and the holds are released, so the handover shows something the incoming crew never saw. The record has drifted. Stored at sign-out, it is the original record, which is what data-integrity guidance asks for [2].
Each signature is a core_e_signature row: who, when, what it means (authored for the outgoing lead, acknowledged for the incoming lead), and a hash of what was signed, as Part 11 asks for signed records [1]. The hash is of one JSON object holding the summary and the snapshot, written with its keys sorted and no extra spaces, so anyone can rebuild it and compare.
| Status | Means | Moved on by |
|---|---|---|
| draft | Being written. Still unsigned at the due time: the supervisor is told once, and it stays a draft so it can still be signed out | The outgoing lead |
| signed_out | Signed by the outgoing lead; the snapshot is stored | The incoming lead |
| accepted | Signed in by the incoming lead | Nobody: the end |
| escalated | Signed out but not accepted in N minutes; the supervisor was told | The incoming lead can still accept |
Session 4: Sign out stores the snapshot; both leads sign
25 minutesWhy
The first definition-of-done test is that the snapshot stored at sign-out is byte-identical when re-opened a week later. Writing it once, in the same transaction as the signature, and refusing any later change in the database, makes that true for every screen, import and agent. The hash lets anyone prove it later without trusting the screen.
Do this
Read docs/handover/content.md. On a new branch m02/signout:
1. Sign-out (outgoing lead, own shift, draft only): after the password is confirmed again, in one transaction: build auto_snapshot from docs/handover/content.md (our log, equipment out of service, active orders, and the other modules' latest events in core_event_outbox, marking unavailable items "not available"); write core_e_signature (signer from the session, meaning authored, record_type shf_handover, a SHA-256 hash of {"auto_snapshot": ..., "summary": ...} with keys sorted and no extra spaces, signed_at from the server clock); set signed_out_at and status signed_out; mark the shift log handed_over.
2. Sign-in (incoming lead of the area, never the person who signed out): password confirmed again; core_e_signature with meaning acknowledged and the same hash; signed_in_at; status accepted.
3. A trigger refuses any change to summary or auto_snapshot once signed_out_at is set. Viewing a handover never rebuilds the snapshot.
4. A database trigger writes shf.handover.signed_out and shf.handover.accepted into core_event_outbox; no person or route gets write rights on the outbox.
Tests: sign out, then add a hold event and set a press out of service; the stored snapshot is byte-identical and its rebuilt hash equals record_hash; changing the summary after sign-out is refused; the outgoing lead cannot sign in. Show the byte-identical test failing when the report rebuilds the snapshot on view, then passing.
Push, open a pull request titled "M02: stored snapshot and sign-off", wait for every check, and tell me the result in plain words.Try it on the development project as in Step 5, then prove it yourself in its SQL editor:
https://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/sql/new
The development project's SQL editor: paste the text below and Run. It must fail.
-- Development project only. Must be refused: a signed-out handover cannot change.
update public.shf_handover set summary = 'edited after sign-out'
where signed_out_at is not null;You will see recreated screen
- Red first: rebuilding on view makes the record drift, and the test catches it.
- The same bytes, proven by the hash, not by looking.
You will see recreated screen
update public.shf_handover set summary = 'edited after sign-out' where signed_out_at is not null;
- Refused even in the dashboard. That is the point.
Check it worked
The update in the development SQL editor is refused; the byte-identical and hash tests are green and were shown red with the snapshot rebuilt on view.
If it goes wrong
The hash does not match when rebuilt
The object was written differently (key order, spaces) at signing and when checking. Say: Use one function to write the signed object, keys sorted, no extra spaces, for both signing and checking, and test it with a fixed example.
The report still shows today's open work orders on an old handover
It rebuilds on view. Say: The report must read auto_snapshot only, never live tables, once signed_out_at is set.
Session 4: Escalation on schedule, and standing orders acknowledged person by person
20 minutesWhy
An unaccepted handover must stop being silent, once, at the time you chose in Session 1, however often the scheduler runs. A standing order counts people, not clicks, so each acknowledgement is one signed row per person. Running the scheduler inside the database with pg_cron means no new key is needed for it.
Do this
Read docs/handover/content.md (N and who is told). On a new branch m02/schedule:
1. A function, run every five minutes by pg_cron (Supabase Cron) as the shift scheduler: a signed_out handover not accepted N minutes after its shift's end is set to escalated, once, and the supervisor gets one core_notification; a draft still unsigned at that time stays a draft and the supervisor is told once. It also opens each new shift's log and draft handover, and sets standing orders past effective_to to expired. Running it twice in a row changes nothing the second time.
2. Standing orders: the issuer creates an order (number from core_number_sequence), activates it, and sees who has and has not acknowledged. Acknowledging needs the password again and writes one shf_standing_order_ack and its core_e_signature (meaning acknowledged); a second acknowledgement by the same person is refused. A trigger writes shf.standing_order.issued into core_event_outbox on activation.
3. Write both rules into docs/shift-rules.md.
Tests on tests/fixtures/m02-hand-count.json: handover 3 escalates exactly once and handovers 1 and 2 never; running the function twice adds no second notification; SO-0001's compliance is 6 of 9; a second acknowledgement is refused.
Push, open a pull request titled "M02: escalation and standing orders", wait for every check, and tell me the result in plain words.Try it on the development project, merge after owner two approves, and check the job is scheduled:
https://supabase.com/dashboard/project/abcdefghijklmnopqrst/integrations/cron/jobs
Production: Integrations, Cron. The escalation job is listed, every five minutes, with its last run.
You will see recreated screen
- Compliance counts acknowledgements before the effective time, one per person.
- The ones to chase, by job and crew.
Check it worked
docs/shift-rules.md holds both rules; the tests show handover 3 escalated exactly once and SO-0001 at 6 of 9; the cron job is listed in production.
If it goes wrong
The supervisor gets a notification every five minutes
The function escalates every run. Say: Make escalation set the status and notify only when the status was not already escalated, in one statement, and test two runs in a row.
The cron job is not listed in production
Cron jobs created in a migration reach production with the merge. Run npx supabase migration list on the development project to check the migration exists, and check the deploy run applied it.
Session 4: An event rule writes exactly one entry per episode
20 minutesWhy
A rule that wrote an entry every minute while a tank stayed high would bury the log, and the next crew would stop reading it. The third definition-of-done test is one entry per condition episode. Predicting the count on paper first, then replaying a made-up tag stream, tells you whether the rule or the prediction is wrong. The alarm system of record stays in SCADA.
Do this
On a new branch m02/events, build the event evaluator (machine account, named jobs only):
- It signs in as its own machine account, with a password a person sets and stores (named in docs/KEYS.md, never the service role key), and reads tag values from the plant connector's feed (Session 20), or from a replay script on the development project.
- A shf_event_rule's condition is a threshold, a state change or a duration. When an episode starts, it inserts a shf_event_occurrence and, unless the rule is shelved (active false) or the episode starts within dedupe_window_min of the previous episode clearing, a shf_log_entry with origin event_rule, the rule's category and priority, and the tag's equipment; otherwise the occurrence is suppressed true. suppressed is always true or false, never empty.
- A unique index on (event_rule_id, triggered_at), and a partial unique index on (event_rule_id, ext->>'episode_key') where suppressed is false, so replaying the same stream adds nothing. The occurrence is inserted first with on conflict do nothing; the entry is made only when the occurrence was really inserted.
- scripts/replay-tags.mjs replays tests/fixtures/m02-tag-stream.json, made-up tag values, through the evaluator on the development project only, and refuses any other project.
Tests with the fixture's rule and a 30-minute window: the stream 06:00–08:00, 09:00–09:10, 09:25–09:35, 13:00–13:30 makes 4 occurrences and 3 entries; a second replay adds nothing; shelved, a new episode makes no entry; unshelved, the same new episode makes exactly one.
Push, open a pull request titled "M02: event rules", wait for every check, and tell me the counts in plain words.Before you read Claude Code's counts, predict them on paper from the rule and the stream: occurrences, entries, suppressed. Then compare.
You will see recreated screen
- Your paper prediction: 4 and 3. If it differs, find out whether the rule or the prediction is wrong.
- Replaying again changes nothing: the unique indexes keep it so.
Check it worked
The counts match your paper prediction (4 occurrences, 3 entries), a second replay adds nothing, and the shelving tests pass.
If it goes wrong
A second replay adds entries
Say: Add the unique index on rule and triggered_at and the partial unique index on rule and episode key, insert the occurrence first with on conflict do nothing, and make the entry only when it was inserted.
The replay script ran against production
It must refuse any project but the development one. Say: Make replay-tags refuse unless the project reference is tsrqponmlkjihgfedcba, and test the refusal. Then list, without deleting, every entry with origin event_rule in production made by the replay.
| KPI | Definition | On the fixture |
|---|---|---|
| Handover on-time sign-off rate | Handovers accepted within N minutes of shift end ÷ handovers | 1 of 3 |
| Open carry-forward items | Count and age of carried items not closed, by area | 4: 3 open, 1 monitoring |
| Standing order ack compliance | Acknowledged before the effective time ÷ required | 6 of 9 |
Session 4: The three KPIs, checked against a hand count
15 minutesWhy
A number nobody can reproduce by hand is a number nobody should trust. The fixture's counts are fixed, so a count on paper shows whether each view uses the same rule as the paper. Every widget says where its number comes from and shows "No data" rather than a number nobody measured.
Do this
Count the fixture first, and write your counts down. It is a readable file with fixed dates:
https://github.com/acme-ops/acme-platform/blob/main/tests/fixtures/m02-hand-count.json
The hand-worked example on GitHub: entries, handovers and acknowledgements.
Read docs/shift-rules.md. On a new branch m02/kpis, add to the dashboard from Session 15: handover on-time sign-off rate (accepted within N minutes of shift end, divided by handovers), open carry-forward items with age by area, and standing order acknowledgement compliance (acknowledged before the effective time, divided by required), each saying where its number comes from and showing "No data" when there is none, never 0 for unknown. Add a test on tests/fixtures/m02-hand-count.json expecting 1 of 3, 4 carried (3 open, 1 monitoring), and 6 of 9. Push, open a pull request titled "M02: KPIs", wait for every check and the preview, and tell me the numbers each widget shows on the development data.You will see recreated screen
- The late handover counts against the rate even though it was accepted.
- Open and monitoring entries with carry_forward true.
Check it worked
Your hand count and the widgets agree exactly: 1 of 3, 4 carried, 6 of 9. Then merge.
Fastest path
Count first, then read the dashboard: reading it first makes it too easy to count your way to its answer.
If it goes wrong
The dashboard says 2 of 3 on time
Fix the query, not the count. Say: The on-time widget says 2 of 3; my hand count says 1. Show me which handover you count on time and against which N. Usually the late one was counted because it was accepted.
The test expects counts the fixture never makes
We found this in reviews of five Academy modules. Say: For every count this test expects, show me the fixture rows that create it. Fix the fixture, not the test.
Knowledge check
A handover opened a week after sign-off shows a hold that did not exist at sign-out. What went wrong?
Knowledge check
A rule's condition clears at 09:10 and returns at 09:25, with a 30-minute dedupe window. What does the module record?
References
- eCFR: 21 CFR 11.50, Signature manifestations. https://www.ecfr.gov/current/title-21/chapter-I/subchapter-A/part-11/subpart-C/section-11.50
- FDA: Data integrity and compliance with drug CGMP: questions and answers (2018). https://www.fda.gov/regulatory-information/search-fda-guidance-documents/data-integrity-and-compliance-drug-cgmp-questions-and-answers
- Supabase Docs: Cron. https://supabase.com/docs/guides/cron
- PostgreSQL Documentation: Unique and partial indexes. https://www.postgresql.org/docs/current/indexes-partial.html
Chapter 4 · Sessions 5–6
Move the history in, and switch the old tool off
The old log's history is imported as closed entries tagged origin import, with the items the next crew still needs loaded open and carried. The import is rehearsed on the development project, then run into production through the pipeline with counts that must match. You run old and new side by side, cut over on a written date, and cancel the old tool with the saving from real invoices.
25 min4 stepsSessions 5 and 6History arrives closedCounts must match
By the end of this chapter you can
- Build the history import as reviewed code and rehearse it on the development project.
- Prove the module side by side with the old handover for a week, with every difference explained.
- Import the history into production through the pipeline after a backup, cut over, and record the saving.
The module library gives the migration in one line: export the historical logs as CSV and import them as closed entries tagged origin import. Closed, because history is evidence of what happened; tagged, so every report can tell old from new. Items still open in the old tool that the next crew needs are the exception: loaded open with carry_forward true, and listed by name for the leads to confirm.
| Key or secret | What it unlocks | Where it lives | Who holds it | Never |
|---|---|---|---|---|
| Event evaluator's password | The machine account that writes event-rule entries, nothing else | Where the evaluator runs, set by a person; listed by name in docs/KEYS.md | pat@acme.com, sam@acme.com | Never the service role key; never in a chat or a file |
| Plant connector's sign-in (Session 20) | Sending tag values to the event evaluator | Where Session 20 put it | The connector, as a machine account | Never reused by a person or another job |
Session 5: Build the import, and rehearse it on the development project
35 minutesWhy
Old entries are evidence, so they arrive closed and can never be edited. Building the import as reviewed code, run from main by a workflow with an insert-only account, means real records reach production only through the pipeline, with their fingerprint and counts printed, never through a laptop or a chat. A rehearsal on the development project, with a copy IT approved in writing, finds the mapping problems first.
Do this
Take the export yourself from the old system's own export page, into a private folder outside the repository. Claude Code never reads it. Give it the first line of each file only, the column names:
We will move the old shift log's history in. The export file stay outside the repository and you will not read it. The first line of each, the column names only:
<paste the first line of the export: column names only, no data>
On a new branch m02/import:
1. scripts/import-m02.mjs, which reads the export file in this format and maps each row to a shf_log_entry with origin import, status closed, the original time as occurred_at, the original author's name as text in ext.original_author, the old tool's name in ext.source_tool, its equipment matched to our equipment by tag or name, and its category and priority mapped to our lists; each old shift becomes a closed shf_shift_log. Rows marked still open in the old tool are loaded open with carry_forward true and listed separately. Rows it cannot match are not imported but listed with the reason. It prints each file's sha256 and the counts: rows, records it would create, rows skipped. In dry-run mode it writes nothing.
2. A migration that creates this module's import account: a database role import_m02 that can log in, with insert only on shf_shift_log and shf_log_entry and on an insert-only table import_log (module, file, sha256, counts, run_at, run_by), read on the private Storage bucket imports, and nothing else: no update, no delete, never the service role key. Imported closed entries are protected by the closed-entry trigger. A file whose sha256 is already in import_log is refused.
3. .github/workflows/import-m02.yml, started only by hand from main (workflow_dispatch), with inputs target (development or production), file (its path in the bucket imports) and apply (default false). It downloads the file from the target project's bucket, signs in as import_m02 with a password a person stores as a GitHub secret (IMPORT_M02_PASSWORD_DEV and IMPORT_M02_PASSWORD_PROD, listed by name in docs/KEYS.md), and runs the script. For production with apply true it refuses unless docs/imports/m02-approved.md on main lists this file's sha256 and expected counts, and it fails on any count mismatch. It never prints a row of the export.
4. Tests on a made-up ten-row file per export (SYNTHETIC values): a dry run writes nothing; apply creates the expected counts; the same file again is refused; an unknown press is listed; an imported closed entry cannot change; import_m02 cannot update or delete anything.
Do not run the workflow and do not set any password. Push, open a pull request titled "M02: import", wait for every check, and tell me the result in plain words, with the secrets I must create myself.Try it on the development project and merge it, as in Step 5. Then a person creates the import account's password in the password manager, sets it on each project in the SQL editor, and types the same value as the GitHub secret. Nobody pastes it into Claude Code or a file.
-- Typed by a person, once per project. The password comes from the password manager.
alter role import_m02 with login password '<from the password manager>';https://github.com/acme-ops/acme-platform/settings/secrets/actions
Add IMPORT_M02_PASSWORD_DEV and IMPORT_M02_PASSWORD_PROD: paste the value only, never NAME=value.
| Key or secret | What it unlocks | Where it lives | Who holds it | Never |
|---|---|---|---|---|
| import_m02 password (one per project) | Inserting imported records into this module's tables, nothing else | GitHub Actions secrets, and the password manager | pat@acme.com, sam@acme.com | Never in a chat, a file or a log; set to NOLOGIN at cut-over |
The rehearsal uses a copy of the export that IT has approved in writing for the development project, redacted where it holds personal, injury or pay data. It is the only real data a development project ever holds, and it is removed the same day.
https://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/storage/buckets
Development project, Storage: upload the approved copy to the private bucket imports.
https://github.com/acme-ops/acme-platform/actions/workflows/import-m02.yml
Run workflow from main: target development, the file's path, apply false. Read the counts; then again with apply true.
Open three imported entries on the development preview beside the same three in the old tool: time, press, text and status must match. Then, the same day, remove the rehearsal from the development project: delete the file from the bucket, and run:
-- Development project only, the same day: remove the rehearsal's real records.
delete from public.shf_log_entry where origin = 'import';
delete from public.shf_shift_log where ext->>'origin' = 'import';
delete from public.import_log where module = 'm02';On a new branch m02/rehearsal, write docs/imports/m02-rehearsal.md: the date of IT's written approval and who gave it (a job, not a name), what was redacted, the rehearsal's counts and skipped rows from the run log below, the three records checked, and the date the copy was removed from the development project:
<paste the counts and the dates>
Open a pull request titled "M02: rehearsal record", wait for the checks, and show me the link.You will see recreated screen
file shiftlog-2026-11.csv sha256 4be1…07c9 rows 4,880 shift logs to create 736 entries to create 4,861 (closed, origin import) loaded open 6 (carry forward) rows skipped 13 (press 'P-7' not in equipment)
- Every skipped row has a reason. Fix the mapping, or decide to leave them out, and write which.
- Read before you apply.
Check it worked
The import is merged; the import account's password is set on both projects and in GitHub secrets, by a person; the rehearsal ran dry, then applied, with every skipped row explained; three entries matched the old tool; the copy was removed the same day and docs/imports/m02-rehearsal.md records it.
If it goes wrong
Claude Code asks to read the export "to get the mapping right"
Say no. Give it the column names and, if needed, a made-up row you write yourself. Real records reach the platform only through the import workflow.
IT will not approve a copy in writing
Then no real data goes to the development project. Rehearse with a made-up file in the same columns (Claude Code can write one from the header), and keep the first production run a dry run. Write the decision in docs/imports/m02-rehearsal.md.
The workflow cannot sign in as import_m02
The password on the project and the GitHub secret differ, or the secret holds NAME=value. Set both again from the password manager, value only. Never give the import account more rights to get past it.
Session 6: Run side by side for a week, and write the cutover
30 minutes, after a week of running bothWhy
The module is ready to replace the old handover only when both have handled the same week and every difference is explained. Comparing handover counts and open carried items, and the three record tests on production, shows the new way caught everything the old way did, and usually what it missed.
Do this
For one week, both run: the old handover stays the record, and the leads also sign out and in on the platform. At the end, count the old way (handovers written, items carried, from the old tool's own report or the binder) and read the same from the dashboard. Then:
On a new branch m02/cutover, write docs/cutover.md with a side-by-side table for the week of <dates>: handovers, handovers accepted within N minutes, open carried items at the end of the week, and standing order acknowledgements, one column from my count of the old way and one from the platform:
Old way (<the old tool's report or the binder>): <your counts>
Explain every difference in one line, or mark it "not explained". Add the three definition-of-done checks with the query and its result on production: a snapshot re-opened is byte-identical to sign-out (rebuilt hash equals record_hash) for every handover of the week; every unaccepted handover escalated exactly once; every event rule episode made at most one entry. Then add the cutover date, who tells each crew, when the old log and whiteboard go, where the old export is kept and by whom, and the way back: if the platform is down, the paper handover sheet, entered within 24 hours as late with the reason. Do not change any data. Open a pull request titled "M02: side by side and cutover", wait for the checks, and show me the link.You will see recreated screen
- The platform shows what the old way kept only on a whiteboard.
- The three definition-of-done tests, run on production by query.
Check it worked
docs/cutover.md has no "not explained" line, the three checks pass on production, and the cutover date and way back are written.
If it goes wrong
A difference cannot be explained
You are not ready. Run another week and ask the leads to watch the item that differs.
Leads sign in without reading
Look at the time between sign-out and sign-in on the platform. Ten seconds is not a handover. Talk to the supervisor; the record shows it, which the old way never could.
Session 6: Import into production through the pipeline
20 minutesWhy
Real records go into production once, through reviewed code, after a backup, from a file whose fingerprint and counts owner two approved in the repository. The workflow refuses any other file and fails on any count mismatch, and the import account can only insert, so nothing already there can be changed by it.
Do this
https://github.com/acme-ops/acme-platform/actions
First, run the nightly backup workflow from Session 11 by hand (its Run workflow button) and wait for it to finish green.
https://supabase.com/dashboard/project/abcdefghijklmnopqrst/storage/buckets
Production, Storage: upload the full export to the private bucket imports.
https://github.com/acme-ops/acme-platform/actions/workflows/import-m02.yml
Run workflow from main: target production, the file's path, apply false. Copy the sha256 and the counts from the log.
On a new branch m02/import-approval, write docs/imports/m02-approved.md: today's date, the source (the old system's name and the export's date), and for each file its path, its sha256 and the expected counts exactly as in this dry-run log, with the skipped rows' reasons as a list, and the entries that will be loaded open, by press and title, for the leads to confirm:
<paste the sha256 and counts from the run log>
Open a pull request titled "M02: approve the import", wait for the checks, and show me the link.The leads confirm the open items; owner two approves; merge. Then run the workflow again from main: target production, the same file, apply true.
You will see recreated screen
shift logs created 736 entries created 4,861 (closed) loaded open 6 (carry forward) import_log: m02, 4be1…07c9
- The approval is a file on main that owner two approved.
- The same numbers, or the run fails.
Check it worked
The backup ran green first; docs/imports/m02-approved.md is on main; the production counts equal it; an imported closed entry opens read-only and a change is refused; the six open items appear carried on the next shift's log.
If it goes wrong
The workflow refuses: sha256 not in the approved file
The file in the bucket is not the one you approved, often a second export taken later. Do not edit the approved file to match. Upload the approved file, or dry-run the new one and approve it in a new pull request.
The run fails: counts do not match
Nothing was imported: the run is one transaction. Ask Claude Code: The m02 import failed on a count mismatch. Show me which count differs and why, from the log, without running anything.
The backup workflow has no Run workflow button
Say to Claude Code: Add workflow_dispatch to the nightly backup workflow so a person can run it before an import. Merge that first. A backup nobody has restored is only a hope: Foundation Session 23 drills the restore.
Session 6: Cut over, and cancel the old tool
15 minutesWhy
Cutting over on the written date means nobody is unsure which handover counts. The saving is real only when it comes from the old invoices and the vendor's own terms, so the old tool is cancelled after the history is safely imported, and the arithmetic is written down.
Do this
On the date: each crew is told at its first handover; the old log, spreadsheet or whiteboard is retired; the platform is the record. Watch the first day's handovers arrive and get accepted. Then read the old vendor's cancellation terms on its own account page (notice period, renewal date, how long you can still export). Then:
On a new branch m02/saving, add to docs/cutover.md: the old tool's bill, renewal date and notice period exactly as I give them below, the date it is cancelled or ends, and the saving with its arithmetic: the old cost minus what the module adds to our running costs (none: it runs on the services we already pay for). Mark the area as cut over in docs/handover-inventory.md with the date. Add a new migration that sets the import account import_m02 to NOLOGIN, now that the import is done.
Old bill and terms: <from your invoice and the vendor's account page>
Open a pull request titled "M02: saving", wait for the checks, and show me the link.You will see recreated screen
- Every figure points at the document it came from.
- One area cut over; others follow the same steps.
Check it worked
The first day's handovers were signed out and accepted on the platform; docs/cutover.md has the saving with its arithmetic; the old tool is cancelled or its end date recorded; after the merge, import_m02 can no longer sign in.
If it goes wrong
Another area still uses the old tool
Keep it until that area cuts over too, and write its date in docs/handover-inventory.md. Cancel when the last area moves, and record the saving then.
The notice period means another renewal
Write the end date and the export window in docs/cutover.md, set a reminder before the notice deadline, and keep using the platform.
Knowledge check
How do historical entries from the old tool arrive?
Knowledge check
What lets the production import apply its rows?
References
- GitHub Docs: Manually running a workflow. https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/manually-running-a-workflow
- Supabase Docs: Storage buckets. https://supabase.com/docs/guides/storage/buckets/fundamentals
- PostgreSQL Documentation: CREATE ROLE (LOGIN, NOLOGIN). https://www.postgresql.org/docs/current/sql-createrole.html
- Supabase Docs: Database backups. https://supabase.com/docs/guides/platform/backups
- Fabrico: best shift handover software 2026. https://www.fabrico.io/blog/best-shift-handover-software/
Chapter 5 · 12 questions · 80% passes
Final assessment
Twelve questions across the element. 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
Shift Handover: the Operations Log, the Signed Handover and Standing Orders
Element M02 complete · Learner
Your LMS records this completion. For the CivOps Foundation certificate, finish the Foundation Course at https://civops.io/learn.