Chapter 1 · Sessions 1 and 2
What the old SPC tool holds, and the tables that replace it
Before you chart anything, you count what the old SPC and inspection tool holds and costs, and you find out how it really computes its limits and its Cpk. Then one careful prompt adds the thirteen SPC tables to your platform, joined to the characteristics and inspections your Foundation already records, with tests that refuse bad data.
25 min4 stepsAbout 7 hours hands-on across six sessionsSessions 1 and 2
By the end of this chapter you can
- Inventory the old tool from its own reports and invoice, and record how it sets limits and which sigma its Cpk uses.
- Map the specification's spine names to your platform, and decide how the Foundation's characteristics and inspections join the module.
- Have Claude Code write the thirteen spc_ tables, their rules and their tests in one pull request.
- Write the module's made-up seed, supabase/seeds/spc.sql, with the 36 reference readings shifted onto today, and keep the same readings as a test fixture.
What this module replaces
The module collects characteristic data at the right frequency, charts it in real time with run rules, forces a documented reaction to every signal, computes capability correctly, and manages inspection and sampling plans, gauge studies and first-article inspection. It replaces InfinityQS ProFicient or Enact, Minitab Real-Time SPC, WinSPC, SQCpack, 1factory, High QA or DataLyzer [1][2], or the spreadsheet beside the gauge. Laboratory samples (M10) and the NCR and CAPA workflow (M08) belong to other modules.
| Standard | Used in this module for |
|---|---|
| AIAG SPC Reference Manual (2nd ed.) | Chart choice, subgrouping, control limits and their constants, capability |
| AIAG MSA Reference Manual (4th ed.) | Gage R&R, bias, linearity, stability, attribute agreement |
| ISO 7870-2:2023 | Shewhart control charts |
| ISO 22514 series | Process capability and performance |
| ANSI/ASQ Z1.4 and Z1.9, ISO 2859-1 | Acceptance sampling by attributes and by variables |
| SAE AS9102C [3] | First article inspection, Forms 1 to 3 |
| Western Electric (1956) and Nelson (1984) | Run rules for patterns random variation rarely makes [4] |
Session 1: Count what the old SPC tool holds and costs, and how it computes
60 minutesWhy
The module is worth building only if it replaces real charts, real gauges, real users and a real bill, and the inventory is what Session 6 is checked against. Two questions matter as much as the counts: does the old tool recalculate limits by itself, and which sigma does its Cpk use? If either answer is wrong, your capability reports have been wrong too, and the new module will disagree with the old one for a good reason.
Do this
With the quality engineer, read from the tool's own reports, its settings and the vendor's account page (no customer names):
- Characteristics charted, by part and press; charts by type; gauges in use and their last gauge study.
- Users by what they do: measure, inspect, set or approve limits, answer signals, read reports.
- The bill: amount, period, renewal date, notice period, paid users, as printed.
- How limits are set: fixed after approval, or recalculated automatically (look in each chart's settings).
- For one characteristic, the tool's Cpk and the help page or setting that says which sigma it uses.
- What it can export: characteristics, specification limits, history, limits, violations and their responses.
- Workarounds: readings typed on paper first, charts printed for audits, signals answered by email.
On a new branch spc/inventory, write docs/spc-inventory.md from what I give you below. Use only my numbers: where I wrote "unknown", write "unknown" and who can find out. Never estimate, round or fill a gap.
Tables:
1. Tools: name, owner, bill per year, renewal date, notice period, export available, source of each figure.
2. Characteristics, charts by type, gauges and their last study, with the report each count came from.
3. Users by role (measure, inspect, set limits, approve limits, answer signals, read).
4. How limits are set (fixed after approval or recalculated automatically), per chart type, with where I saw it.
5. One characteristic's Cpk as the tool shows it, and which sigma the tool says it uses.
6. What can be exported, and for how long after cancelling.
7. Workarounds, who, how often.
8. The first slice to replace (one part, its characteristics, its gauges), why, and the quality engineer and approver who will test it.
My notes:
<paste your notes here>
Open a pull request titled "SPC inventory" and show me the link.You will see recreated screen
- The second pitfall, found in the old tool's own settings.
- The first pitfall: the old Cpk is really a Ppk. Expect the new module's Cpk to differ, and say why in Session 6.
Check it worked
Pull request SPC inventory holds the eight tables, every figure with its source, and answers to the limits and sigma questions.
If it goes wrong
Claude Code filled in a count or a price you did not give it
Say: Remove every figure I did not give you and write unknown. We hit this on our own platform: screens showed numbers nobody had measured, and one chart said "In control" on 87 screens from twelve made-up points.
Nobody knows which sigma the tool uses
Write unknown. Session 5's rehearsal recomputes Cpk and Ppk from the exported history, and the old figure will match one of them.
Your platform's names, and the characteristics you already have
The specification points at core_item, core_uom, core_equipment, core_lot, core_person, core_reason_code, core_data_tag and core_e_signature. Your Foundation already has parts, equipment and lots, and something closer still: a characteristics table with each part's limits, and an inspections table of first-piece and gauge results that the quality lead's hold decisions read. The module must not create a second home for the same limits or the same reading: two homes drift apart, and then the chart and the hold decision disagree.
| Specification or module | On the stamping plant's platform | Decision |
|---|---|---|
| core_item, core_equipment, core_lot | parts, equipment, lots | Point at them |
| spc_characteristic | characteristics (lower_mm, upper_mm) | One row each, pointing at the Foundation row; lsl and usl must equal its limits, enforced by a trigger |
| spc_measurement | inspections (value_mm) | Each new inspection is copied once into spc_measurement (source form), keeping the inspection's id, so every reading charts and the hold workflow is untouched |
| core_uom, core_reason_code, core_data_tag, core_e_signature | missing unless another module added them | Add them in the spine migration |
| tenant_id on every row | site_id | One company; site is the scope |
Session 2: Map the spine and join the characteristics you already have
20 minutesWhy
Your plant's limits and readings already live in the Foundation tables, and the quality lead's hold decisions read them. Joining the module to them, rather than copying them, keeps one set of limits and one record of each reading. The shared spine tables (units, reason codes, signatures) go in their own migration, merged first, because other modules use them too.
Do this
cd ~/code/acme-platform && git switch main && git pull && claudeRead docs/SCHEMA-PLAN.md, docs/naming-standard.md, every file in supabase/migrations, and docs/spine-map.md if it exists. Do not change any existing table or migration.
On a new branch spine/spc-prerequisites:
1. Create or extend docs/spine-map.md: for core_item, core_uom, core_equipment, core_lot, core_person, core_job_role, core_reason_code, core_data_tag, core_e_signature, core_status_history and core_event_outbox, the table here that plays that role, or "missing". Record our scope column (site_id) and id type.
2. Record in docs/spine-map.md how the module joins the Foundation: spc_characteristic will point at our characteristics table (one each) and its lsl and usl must equal that row's limits; each new inspections row will be copied once into spc_measurement with source "form" and the inspection's id in ext. Ask me before choosing anything else.
3. For every "missing" item, write ONE new migration (npx supabase migration new spine_for_spc) with this platform's conventions: primary key, site_id, created and updated columns, row_version, archived_at, ext jsonb, timestamptz; row-level security on with no policies; signatures, status history and outbox append-only. Add each new table to docs/matrix.json with no rights yet.
4. pgTAP tests for every new table.
Push, open a pull request titled "Spine for SPC", wait for every check to finish, and tell me the result in plain words. If a check fails, fix it and wait again before reporting.You will see recreated screen
- One set of limits, one record of each reading: the module joins the Foundation instead of copying it.
Check it worked
Pull request Spine for SPC is green, docs/spine-map.md records both joins, and no older migration is edited.
If it goes wrong
Claude Code proposes moving inspections into spc_measurement and dropping the old table
Refuse. Records of what happened are never dropped, and the hold workflow reads that table. Say: Keep inspections as it is; copy new rows once, as written in docs/spine-map.md.
It renamed characteristics to spc_characteristic
Say: Revert the rename; names are forever. A half-done rename breaks every query that used the old name; we hit exactly that on our platform.
It reports success but a check is red
Say: A check is red. Read the failed log, fix it and wait for green before you report. Trust the check, never the summary.
The thirteen tables
Five columns are soft links: plain uuid columns that will point at another module's table (MES operations, the FMEA, quality events) with no foreign key, because that module may not be installed yet. Readings are one row each with a numeric value; JSON only where the shape really varies.
| Table | Holds | Columns |
|---|---|---|
| spc_characteristic | Measured or counted characteristic | code text req, unique; item_id → core_item; operation_ref uuid (soft link to mes_operation_definition); name text req; char_type text req: variable, attribute; uom_id → core_uom; nominal num; lsl num; usl num; special_class text req: none, cc, sc, key; gauge_type text; data_tag_id → core_data_tag; decimals int |
| spc_control_plan | Control plan header | plan_no text req, unique; item_id → core_item req; revision text req; phase text req: prototype, pre_launch, production; status text req: draft, approved, superseded; fmea_ref uuid (soft link to qms_fmea) |
| spc_control_plan_line | Control plan line (AIAG format) | control_plan_id → spc_control_plan req; process_step text req; characteristic_id → spc_characteristic req; evaluation_method text; sample_size int; frequency text; control_method text; reaction_plan text |
| spc_sampling_plan | Sampling scheme definition | code text req, unique; scheme text req: fixed, z14_aql, z19, skip_lot, c_zero, hundred_pct; aql num; inspection_level text; params json |
| spc_inspection_plan | Inspection plan per item and type | item_id → core_item req; inspection_type text req: receiving, in_process, final, first_article, audit, source; sampling_plan_id → spc_sampling_plan; characteristics json; active bool req |
| spc_inspection_lot | Inspection instance with decision | inspection_plan_id → spc_inspection_plan req; lot_id → core_lot; lot_qty qty; sample_size int; status text req: open, in_progress, decided; decision text req: pending, accept, reject, conditional; inspector_id → core_person; decided_at ts; quality_event_ref uuid (soft link to qms_quality_event) |
| spc_chart | Control chart configuration and current limits | characteristic_id → spc_characteristic req; equipment_id → core_equipment; chart_type text req: xbar_r, xbar_s, imr, p, np, c, u, ewma, cusum, short_run; subgroup_size int req; rules json req; ucl num; cl num; lcl num; ucl_r num; lcl_r num; limits_basis text req: historical, standard, manual; limits_set_at ts; limits_set_by → core_person; limits_approval_signature_id → core_e_signature |
| spc_subgroup | Subgroup statistics | chart_id → spc_chart req; seq int req; ts ts req; n int req; mean num; range_val num; stdev num; defects num; defectives num; inspected num; lot_id → core_lot; operation_run_ref uuid (soft link to mes_operation_run) |
| spc_measurement | Individual measurement or attribute observation | characteristic_id → spc_characteristic req; subgroup_id → spc_subgroup; inspection_lot_id → spc_inspection_lot; value num; attribute_result text: pass, fail; defect_count int; measured_at ts req; measured_by → core_person; gauge_equipment_id → core_equipment; source text req: manual, gauge, tag, form, import |
| spc_violation | Run-rule signal and the required response | chart_id → spc_chart req; subgroup_id → spc_subgroup req; rule_code text req; detected_at ts req; acknowledged_by → core_person; acknowledged_at ts; assignable_cause_code_id → core_reason_code; corrective_action text; escalated_event_ref uuid (soft link to qms_quality_event); status text req: open, acknowledged, closed |
| spc_capability_study | Capability result over a period | characteristic_id → spc_characteristic req; period_start ts req; period_end ts req; n int req; mean num; sigma_within num; sigma_overall num; cp num; cpk num; pp num; ppk num; distribution text; normality_p num; expected_ppm num; stable bool |
| spc_msa_study | Measurement system analysis | study_no text req, unique; gauge_equipment_id → core_equipment req; characteristic_id → spc_characteristic; study_type text req: grr_crossed, grr_nested, bias, linearity, stability, attribute_agreement; method text req: anova, average_range, kappa, other; operators int; parts int; trials int; data json; pct_grr num; ndc int; result text: acceptable, marginal, unacceptable; performed_at date |
| spc_fai_report | AS9102 first-article inspection report | fai_no text req, unique; item_id → core_item req; part_revision text; serial_no text; form1 json; form2 json; form3 json req; status text req: draft, complete, approved, rejected; approved_signature_id → core_e_signature |
Session 2: One prompt: the thirteen tables, their rules and their tests
25 minutesWhy
A rule kept in the table protects every screen, gauge feed and import. A characteristic whose lower limit is above its upper limit, or a violation closed with no cause, would quietly corrupt every chart and report built on it. Giving Claude Code the exact column list stops it inventing or dropping a column, and the two governance rules (limits change only with an approval, a violation closes only with a coded response) are written into the database from the start.
Do this
On a new branch spc/tables, add this module's own section to docs/spine-map.md, the one shared map (never a separate tables file), with exactly this content, then use it.
## M09 SPC and inspection tables (from the module specification M09)
Every table also has the standard columns recorded above in this map. "req" means not null. A list after a colon is a check constraint. "→ core_x" means a foreign key to the table docs/spine-map.md maps core_x to. "soft link" means a plain uuid column with a comment naming the table, and no foreign key. Types: ts = timestamptz, num and qty = numeric, json = jsonb.
### spc_characteristic
Measured or counted characteristic.
- code text req, unique
- item_id → core_item
- operation_ref uuid (soft link to mes_operation_definition)
- name text req
- char_type text req: variable, attribute
- uom_id → core_uom
- nominal num
- lsl num
- usl num
- special_class text req: none, cc, sc, key
- gauge_type text
- data_tag_id → core_data_tag
- decimals int
### spc_control_plan
Control plan header.
- plan_no text req, unique
- item_id → core_item req
- revision text req
- phase text req: prototype, pre_launch, production
- status text req: draft, approved, superseded
- fmea_ref uuid (soft link to qms_fmea)
### spc_control_plan_line
Control plan line (AIAG format).
- control_plan_id → spc_control_plan req
- process_step text req
- characteristic_id → spc_characteristic req
- evaluation_method text
- sample_size int
- frequency text
- control_method text
- reaction_plan text
### spc_sampling_plan
Sampling scheme definition.
- code text req, unique
- scheme text req: fixed, z14_aql, z19, skip_lot, c_zero, hundred_pct
- aql num
- inspection_level text
- params json
### spc_inspection_plan
Inspection plan per item and type.
- item_id → core_item req
- inspection_type text req: receiving, in_process, final, first_article, audit, source
- sampling_plan_id → spc_sampling_plan
- characteristics json
- active bool req
### spc_inspection_lot
Inspection instance with decision.
- inspection_plan_id → spc_inspection_plan req
- lot_id → core_lot
- lot_qty qty
- sample_size int
- status text req: open, in_progress, decided
- decision text req: pending, accept, reject, conditional
- inspector_id → core_person
- decided_at ts
- quality_event_ref uuid (soft link to qms_quality_event)
### spc_chart
Control chart configuration and current limits.
- characteristic_id → spc_characteristic req
- equipment_id → core_equipment
- chart_type text req: xbar_r, xbar_s, imr, p, np, c, u, ewma, cusum, short_run
- subgroup_size int req
- rules json req
- ucl num
- cl num
- lcl num
- ucl_r num
- lcl_r num
- limits_basis text req: historical, standard, manual
- limits_set_at ts
- limits_set_by → core_person
- limits_approval_signature_id → core_e_signature
### spc_subgroup
Subgroup statistics.
- chart_id → spc_chart req
- seq int req
- ts ts req
- n int req
- mean num
- range_val num
- stdev num
- defects num
- defectives num
- inspected num
- lot_id → core_lot
- operation_run_ref uuid (soft link to mes_operation_run)
### spc_measurement
Individual measurement or attribute observation.
- characteristic_id → spc_characteristic req
- subgroup_id → spc_subgroup
- inspection_lot_id → spc_inspection_lot
- value num
- attribute_result text: pass, fail
- defect_count int
- measured_at ts req
- measured_by → core_person
- gauge_equipment_id → core_equipment
- source text req: manual, gauge, tag, form, import
### spc_violation
Run-rule signal and the required response.
- chart_id → spc_chart req
- subgroup_id → spc_subgroup req
- rule_code text req
- detected_at ts req
- acknowledged_by → core_person
- acknowledged_at ts
- assignable_cause_code_id → core_reason_code
- corrective_action text
- escalated_event_ref uuid (soft link to qms_quality_event)
- status text req: open, acknowledged, closed
### spc_capability_study
Capability result over a period.
- characteristic_id → spc_characteristic req
- period_start ts req
- period_end ts req
- n int req
- mean num
- sigma_within num
- sigma_overall num
- cp num
- cpk num
- pp num
- ppk num
- distribution text
- normality_p num
- expected_ppm num
- stable bool
### spc_msa_study
Measurement system analysis.
- study_no text req, unique
- gauge_equipment_id → core_equipment req
- characteristic_id → spc_characteristic
- study_type text req: grr_crossed, grr_nested, bias, linearity, stability, attribute_agreement
- method text req: anova, average_range, kappa, other
- operators int
- parts int
- trials int
- data json
- pct_grr num
- ndc int
- result text: acceptable, marginal, unacceptable
- performed_at date
### spc_fai_report
AS9102 first-article inspection report.
- fai_no text req, unique
- item_id → core_item req
- part_revision text
- serial_no text
- form1 json
- form2 json
- form3 json req
- status text req: draft, complete, approved, rejected
- approved_signature_id → core_e_signature
Then write ONE migration (npx supabase migration new spc_tables) that creates all thirteen tables exactly as listed, and:
- codes and numbers unique per site; spc_characteristic also points at our characteristics table as docs/spine-map.md says, with lsl below usl and a trigger keeping lsl and usl equal to that row's limits;
- the trigger that copies each new inspections row once into spc_measurement (source form, ext.inspection_id);
- subgroup_size, n and sample_size above 0; one subgroup seq per chart;
- a trigger refusing any change to ucl, cl, lcl, ucl_r, lcl_r, limits_basis, limits_set_at, limits_set_by except together with a new limits_approval_signature_id by someone other than the proposer;
- a trigger refusing a violation status of acknowledged or closed without assignable_cause_code_id and corrective_action, and a close by the person who acknowledged it;
- measurements and violations append-only apart from the response columns; row-level security on every table with no policies; touch-row and audit triggers; each table in docs/matrix.json with no rights yet.
pgTAP tests in supabase/tests/spc.test.sql proving the database refuses: lsl above usl, an unknown chart_type, a change to ucl without an approval signature, closing a violation with no cause code, and a close by the acknowledger. Show me each failing before its rule exists and passing after.
Do not connect to any Supabase project. Push, open a pull request titled "SPC tables", wait for every check, and tell me the result in plain words.You will see recreated screen
- The column list now lives in the one shared map, in its own section.
- The specification's compliance note, written as two triggers: limits are controlled, responses are coded.
Check it worked
Pull request SPC tables is green; you saw the five tests red then green; no older migration is edited.
Fastest path
Asking for red-then-green in the prompt saves the round trip where you discover a test that could never fail.
If it goes wrong
A screen fails later with "column does not exist"
Say: Rebuild the local database from supabase/migrations only, run supabase db diff, and write any difference as a new migration. We merged ten columns without a migration once; the fresh-database check catches it.
The check went green after a test or CI file changed
Say: Undo every change to tests and CI. Never weaken a check to get to green; stop and explain. On our platform an agent that was refused one command used another to do the same thing.
A soft link was made a real foreign key, and the migration fails
Say: Make operation_ref, operation_run_ref, fmea_ref, quality_event_ref and escalated_event_ref plain uuid columns with a comment; the other modules may not be installed.
10.03 9.88 10.06 10.12 9.95 9.91 10.05 9.86 10.08 9.97 10.13 9.92
10.34 10.08 9.98 9.89 10.07 10.01 10.02 9.90 10.05 10.09 10.03 10.14
10.02 10.06 10.01 10.11 10.04 9.96 9.87 10.10 9.93 9.99 10.08 9.92Session 2: A small made-up seed with the reference readings, on the development project
20 minutesWhy
Session 4's rules engine is tested against an answer you can find with a ruler: rule 1 at point 13, rule 2 at point 29. Keeping those readings as a test fixture, and loading the same readings as made-up, marked seed rows shifted onto today, means every later step has a known answer. Pushing to the development project yourself proves the migrations and seed work on a real project before the deploy pipeline applies the migrations to production on merge.
Do this
On the branch spc/tables, write supabase/seeds/spc.sql and list it under [db.seed] sql_paths in supabase/config.toml, after the Foundation seed. Never append to supabase/seed.sql, and never seed production. Every row is made up and marked SYNTHETIC: codes start SYN-, names start "SYNTHETIC · ". Times are shifted onto today, relative to one clock reading at seed time; safe to run twice (a second run leaves the same rows).
One part SYN-4410 with characteristic SYN-FLANGE-H (variable, mm, nominal 10.00, specification 9.60 to 10.40, special_class sc), joined to a SYNTHETIC characteristics row as docs/spine-map.md says. One press SYN-P-03 and one gauge SYN-G-07. An approved control plan with one line (sample 1, every hour, reaction plan "stop, contain, call quality"). One I-MR chart with all eight Nelson rules on, limits_basis standard, cl 10.00, ucl 10.30, lcl 9.70, approved by the quality approver. The 36 readings below as 36 subgroups of one, one hour apart, ending one hour before seed time; no violations yet (Session 4 evaluates them). One person per role: operator, inspector, quality engineer, quality approver, supervisor, manager. Three assignable cause codes (SYN-TOOL-WEAR, SYN-MATERIAL, SYN-SETUP).
Readings:
10.03 9.88 10.06 10.12 9.95 9.91 10.05 9.86 10.08 9.97 10.13 9.92
10.34 10.08 9.98 9.89 10.07 10.01 10.02 9.90 10.05 10.09 10.03 10.14
10.02 10.06 10.01 10.11 10.04 9.96 9.87 10.10 9.93 9.99 10.08 9.92
Also write the same 36 readings, with fixed times on a fixed day, centre 10.00, sigma 0.10 and the expected signals (rule 1 at point 13, rule 2 at point 29, nothing else), to tests/fixtures/spc-reference.json; the rules and capability tests read that fixture, never the seed rows. Add a test that runs the seed twice on an empty database, checks the 36 readings add up to 360.65, and checks the counts above. Push to the same pull request and wait for the checks.When it is green, push to the development project yourself, in a terminal (not inside Claude Code), with the password from Supabase: acme-platform-dev database password:
cd ~/code/acme-platform && git fetch && git switch spc/tables && npx supabase link --project-ref tsrqponmlkjihgfedcbanpx supabase db push --include-seedhttps://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/editor
The development project's Table Editor: open spc_measurement.
That is the first load. After it, reload the made-up rows with npm run seed:dev, never with supabase db reset. Then owner two approves and you merge; the deploy workflow applies the migrations (never the seed) to production.
You will see recreated screen
| characteristic | value | source | measured_at |
|---|---|---|---|
| SYN-FLANGE-H | 10.03 | manual | 36 h ago |
| SYN-FLANGE-H | 10.34 | manual | 24 h ago |
| SYN-FLANGE-H | 9.92 | manual | 1 h ago |
- Point 13, 10.34, is here; nothing has flagged it yet.
- Correct for now: the rules engine does not exist until Session 4.
Check it worked
acme-platform-dev shows 36 SYN-FLANGE-H readings and one approved chart; the pull request is merged; the deploy run on main is green.
If it goes wrong
A week later the chart's "last 24 hours" view is empty
The seed used fixed dates. Say: Make every seeded time relative to one clock reading at seed time; fixed-date examples belong in tests/fixtures/spc-reference.json. Then reload with npm run seed:dev. We hit this: eleven days after seeding, every recent-hours panel was blank.
The readings add up to something other than 360.65
One was typed wrong. Say: Compare the seed's readings and tests/fixtures/spc-reference.json with the list in the M09 section of docs/spine-map.md one by one. Fix the seed, not the check.
Claude Code offers to run db push for you
Refuse; the deny rule from Session 1 stops it anyway. You run it, on the development project.
Someone suggests supabase db reset --linked to start again
Do not. To start the made-up rows again on the development project, run npm run seed:dev.
Knowledge check
Your old tool's help page says its Cpk uses the overall standard deviation. What is that number really?
Knowledge check
Your Foundation already has a characteristics table with each part's limits. What does the module do?
References
- Advantive: SPC tools and ProFicient. https://www.advantive.com/?p=1379
- Advantive: ProFicient by InfinityQS. https://www.advantive.com/brands/infinity-qs/
- SAE International: AS9102C, Aerospace First Article Inspection Requirement. https://www.sae.org/standards/content/as9102c/
- NIST/SEMATECH e-Handbook of Statistical Methods: What are control charts?. https://www.itl.nist.gov/div898/handbook/pmc/section3/pmc31.htm
- Supabase Docs: Testing your database. https://supabase.com/docs/guides/database/testing
Chapter 2 · Session 3
Who may measure, react and approve limits, and their screens
Control limits are part of the controlled process, and every signal needs an answer, so who may do what is the heart of the module. You write six roles and three rules for two people into the role matrix, generate the access rules from it, prove every refusal, and build the screens: capture at the press, the chart, the signal answer and the limits approval.
20 min2 steps6 roles, 3 two-person rules
By the end of this chapter you can
- Add the module's roles, scopes, rights and two-person rules to docs/matrix.json and regenerate the access rules and route list.
- Prove that nobody approves limits they proposed and nobody closes a signal they answered.
- Build the operator's capture screen with limits feedback, the live chart, the violation answer and the limits approval.
| Two-person rule | Why |
|---|---|
| Whoever proposed new limits may not approve them | Limits are part of the controlled process; one person must not move the goalposts alone |
| Whoever acknowledged a violation may not close it | A second person checks the cause and the action really fit the signal |
| An inspector may not approve their own first article report | AS9102 evidence is signed by someone independent |
Session 3: The roles in the matrix, rules generated, refusals proven
30 minutesWhy
Rights written by hand drift; rights generated from docs/matrix.json keep the database, the routes and the menus in step. The two-person rules are this module's controls, so each must be proven by a test that tries to break it and is refused.
Do this
Read docs/matrix.json, scripts/gen-policies.mjs, scripts/gen-routes.mjs, lib/access/routes.ts and docs/spine-map.md with its M09 section. Before writing any route code, read the relevant guide in node_modules/next/dist/docs/ (this Next.js version keeps request middleware in proxy.ts).
On a new branch spc/access, add to docs/matrix.json:
1. Roles operator, inspector, quality_engineer, quality_approver, supervisor, manager; machine accounts spc_importer and spc_gauge (gauge and tag feeds). In a separate migration create both as database logins with NOLOGIN, no BYPASSRLS, owning nothing; I set their passwords myself on each project, and you list them by name (never a value) in docs/KEYS.md.
2. Scopes: operator and supervisor by area; inspector, quality_engineer, quality_approver and manager by site.
3. Rights from nothing: operator and inspector insert measurements and read the charts of their area or site, acknowledge violations with a cause code and action; inspector also runs inspection lots and drafts first article reports; quality_engineer owns characteristics, control plans, charts (proposing limits), sampling and inspection plans, studies; quality_approver approves limits, control plans and first article reports with a signature; supervisor acknowledges and closes violations in their area and escalates; manager reads only. spc_importer only inserts characteristics, charts and imported measurements (source import), and never reads, updates or deletes; spc_gauge inserts measurements (source gauge or tag) only. Nobody gets delete.
4. The three two-person rules as rules on the cells.
5. Screens and routes: /spc/capture (operator, inspector), /spc/charts (all roles, read), /spc/violations (operator, inspector, supervisor, quality_engineer), /spc/limits (quality_engineer proposes, quality_approver approves), /spc/inspection (inspector), /spc/studies (quality_engineer), /spc/board (manager, quality_engineer), /api/spc/measurements, /api/spc/violations, /api/spc/limits/approve (quality_approver only). No import page or route: real records arrive only through the import workflow in Session 6.
Run node scripts/gen-policies.mjs and node scripts/gen-routes.mjs (it writes lib/access/routes.ts). Write docs/spc-rights-walk.md listing every right Sessions 4 to 6 need, with a test that fails if any is not allowed. Add to supabase/tests/access.test.sql: one allowed and one refused per role and table; each two-person rule refused; a supervisor of another area cannot answer this area's violation; the manager cannot write anything; for every permitted update the row really changed; a signed-out request to every new screen and route is refused.
Push, open a pull request titled "SPC access", wait for every check, and tell me the result in plain words. If a check fails, fix the matrix or the code, never the test.You will see recreated screen
- The approver touches only the limits and the signature, never limits they proposed.
- Each control proven by a refusal.
Check it worked
Pull request SPC access is green, docs/spc-rights-walk.md passes, and each two-person rule has a refused test.
If it goes wrong
Acknowledge reports success but the violation stays open
The role's read rule does not cover the row after the change, so the update finds nothing. Say: Make each role's read rule cover violations before and after the change, and test that the row really changed. We hit this in three of our modules.
A signed-in manager can approve limits
Signed in is not allowed. Say: Add a refused-role test for every role on /api/spc/limits/approve. On our platform any signed-in user could delete a whole site.
Session 3: Capture at the press, the live chart, the answer and the approval
45 minutesWhy
Readings are only as good as the moment they are taken: an operator typing at the press needs to see at once whether a value is in specification and whether it made a signal. The chart, the answer to a signal and the limits approval are where the module's controls become visible. Building them against the seed lets an operator and the quality engineer try them before the rules engine is wired behind them.
Do this
Read the operator, supervisor and manager screens from Foundation Sessions 12, 13 and 15, and follow their layout, offline handling and tests. Read node_modules/next/dist/docs/ before adding routes; check proxy.ts still denies every route not in lib/access/routes.ts.
On a new branch spc/screens, against the seed on the development project:
1. /spc/capture (operator, phone first): pick part, characteristic and gauge; type the value with the characteristic's decimals; see at once in or out of specification; queued with no signal and sent once (a row id made on the phone); measured_by from the session on the server, never from the page.
2. /spc/charts: the chart with centre line and limits, zones at 1 and 2 sigma, specification limits drawn differently from control limits, and open violations marked. A chart with no approved limits says "Collecting: no approved limits", and never draws invented ones.
3. /spc/violations: open signals with rule, time and point; Acknowledge needs a cause code from the list and a corrective action; Close is offered only to someone other than the acknowledger.
4. /spc/limits: the quality engineer proposes limits with their basis and period; the quality approver sees the proposal beside the current limits and signs with their password typed again.
44 px targets, 16 px fields, 15 px text, no sideways scroll at 360 and 390 px. Screen tests for each role, a refused role per screen. Push, open a pull request titled "SPC screens", wait for every check including the preview, and give me the preview address and demo logins.https://github.com/acme-ops/acme-platform/pulls
Open the pull request and its Vercel preview; try capture on your phone.
You will see recreated screen
- Typed with the characteristic's decimals.
- Two different questions: the part is good, but the process has signalled.
You will see recreated screen
- Honest about what it does not yet do: no made-up "In control".
Check it worked
The preview opens on your phone; a reading taken in flight mode arrives once; specification and control limits look different on the chart; an operator sent to /spc/limits is refused.
If it goes wrong
The chart says "In control" before the rules engine exists
Say: Remove every status the code does not compute from stored readings; show Not evaluated instead. On our platform 87 screens graded a hard-coded twelve-point array and called it In control.
Every reading shows the same operator
The page sent the person and the server trusted it. Say: Take measured_by from the signed-in session on the server. We hit this: every record said it was created by the founder.
A link from the chart opens a blank 404
Say: Start the build, sign in as each role, visit every page and link on the four screens, and report every 404. We once had 130 links pointing nowhere.
Knowledge check
The quality engineer proposed new limits. Who may approve them?
Knowledge check
A reading of 10.36 has specification 9.60 to 10.40 and control limits 9.70 to 10.30. What is true?
References
- Supabase Docs: Row Level Security. https://supabase.com/docs/guides/database/postgres/row-level-security
- eCFR: 21 CFR Part 11, Electronic records and electronic signatures. https://www.ecfr.gov/current/title-21/chapter-I/subchapter-A/part-11
- W3C: Web Content Accessibility Guidelines (WCAG) 2.2. https://www.w3.org/TR/WCAG22/
Chapter 3 · Session 4
The chart and its required reaction, end to end
A reading arrives, the chart updates, every run rule is evaluated on every point, a signal opens a violation that cannot close without a coded answer, and limits never move by themselves. Then capability computed correctly, a gauge study, and a receiving inspection. Three tests are the module's definition of done.
30 min3 stepsThe three checks that define done
By the end of this chapter you can
- Have Claude Code build a rules engine that reproduces the reference readings exactly: rule 1 at point 13, rule 2 at point 29.
- Make every violation need a coded response before closing, and keep limits fixed until an approved change.
- Compute Cp, Cpk, Pp and Ppk and match a second calculation to three decimals; run a gage R&R and a receiving inspection.
| Nelson rule | The pattern | Usually means |
|---|---|---|
| 1 | One point more than 3 sigma from the centre | A sudden change or an outlier |
| 2 | Nine in a row on one side of the centre | A shift of the average |
| 3 | Six in a row steadily rising or falling | A trend, such as tool wear |
| 4 | Fourteen in a row alternating up and down | Two alternating causes |
| 5 | Two of three more than 2 sigma out, same side | A shift beginning |
| 6 | Four of five more than 1 sigma out, same side | A smaller shift |
| 7 | Fifteen in a row within 1 sigma | Too little variation: mixed streams |
| 8 | Eight in a row more than 1 sigma out, either side | Two streams, or overcontrol |
The rules come from the Western Electric handbook (1956) and Nelson (1984) [1][2]. On a p or u chart the limits move with each sample size, so rules written for fixed zones do not carry over unchanged: decide which apply to each counted chart and write the reason down.
Session 4: Capture, chart and a rules engine that reproduces the reference readings
35 minutesWhy
A rules engine that is nearly right is worse than none, because people trust it. Testing it against readings you have checked with a ruler, and the chart constants against your copy of the manual read by a second person, is the first check that defines done. Evaluating the rules in the same transaction as the reading means a point and its signal always exist together.
Do this
Type the X-bar R and I-MR constants (A2, D3, D4, d2 for n = 2 to 10) from your copy of the AIAG SPC manual or ISO 7870-2 into docs/spc-constants.csv, and ask a second person to check every value against the printed table. On paper, with a ruler: rule 1 fires at point 13, rule 2 at point 29, and nothing else.
Read the M09 section of docs/spine-map.md, docs/spc-constants.csv and tests/fixtures/spc-reference.json. On a new branch spc/rules:
1. lib/spc/rules.ts: one pure function that takes the points, the centre line, sigma and the rules switched on, and returns every rule that fires with the point number. All eight Nelson rules. Chart statistics (subgroup mean, range, moving range) and limits computed with the constants from docs/spc-constants.csv, which you must not edit.
2. /api/spc/measurements: inserts the reading, updates its subgroup, evaluates the chart's rules, and inserts any spc_violation with rule code and detected_at, all in one transaction. A chart without approved limits stores the reading and evaluates nothing. Write spc.violation.detected to the outbox.
3. Tests: on the 36 readings in tests/fixtures/spc-reference.json with centre 10.00 and sigma 0.10, the engine returns exactly rule 1 at point 13 and rule 2 at point 29 and nothing else; one hand-made case for each of rules 3 to 8 that fires exactly that rule; the constants file gives the limits of a small X-bar R example worked by hand in the test.
Show me the reference test failing with rule 2 switched off, then passing. Push, open a pull request titled "SPC rules engine", wait for every check, and tell me the result in plain words.You will see recreated screen
- Exactly the two signals, and nothing else: a rule that fires too often is as wrong as one that never fires.
Check it worked
Pull request SPC rules engine is green, the reference test was shown red then green, and the development chart shows two open violations.
If it goes wrong
Rule 2 fires at point 28 or 30 instead of 29
Count again on paper: points 21 to 29 are the nine above 10.00. Then say: Rule 2 must fire at the ninth point of the run, point 29; show me how the engine counts the run. Fix the engine, never the test.
Claude Code edits docs/spc-constants.csv to make a test pass
Say: Restore the constants file. If a test fails, show me which value disagrees with the worked example. Never loosen a check to get to green.
A test was green from the start
Say: Switch the rule off and show me the test fails, then restore it. Our page-presence check reported 350 present and 0 absent for weeks because it could only ever say yes.
Session 4: The required reaction, and limits that never move by themselves
30 minutesWhy
A signal nobody answers is just a red dot. Requiring a coded cause and an action before a violation can close, checked by a second person, is the second check that defines done and what an auditor will ask for. Limits that recalculate with every point drift with the process and hide the shift they exist to catch, so they change only by an approved proposal.
Do this
On a new branch spc/reaction:
1. /api/spc/violations: acknowledge (cause code from the list and corrective action, both required), close (someone other than the acknowledger), escalate (a supervisor creates an action item linking back; if a qms_quality_event table exists, store its id in escalated_event_ref, otherwise leave it empty). Write spc.violation.closed to the outbox.
2. Limits: the quality engineer proposes new limits computed from a stated stable period (basis historical) or a standard; the quality approver signs with their password typed again (a core_e_signature row, meaning approved); only then do ucl, cl and lcl change, with limits_set_at and limits_set_by.
3. Tests: closing with no cause code is refused; closing by the acknowledger is refused; a query for closed violations with no cause code returns no rows; replaying 100 new readings leaves ucl, cl and lcl exactly where they were; a limits change without a signature is refused; the signal response time (median minutes from detected_at to acknowledged_at) is computed from the rows.
Show each test failing before its rule and passing after. Push, open a pull request titled "SPC reaction and limits", wait for every check, and tell me the result in plain words.Then on the preview: answer one of the two seeded violations as the operator, and close it as the supervisor.
You will see recreated screen
- Chosen from the list, never typed: causes can be counted.
- The two-person rule, shown in plain words.
Check it worked
Pull request SPC reaction and limits is green; on the preview, one violation is acknowledged by one person and closed by another; the 100-point replay test leaves the limits unchanged.
If it goes wrong
Acknowledge shows success but the violation is still open
Say: After saving, read the violation back from the database; if the status did not change, show an error. On our platform a button reported success while nothing had happened.
Claude Code proposes recalculating limits automatically "to stay current"
Refuse. That is the second pitfall. Limits change only by an approved proposal.
Two people answer the same signal at once and one answer disappears
Say: Include updated_at in the update's where clause so a stale save is refused, and test two saves from the same copy. We lost records this way before we added that check.
| Index | Formula | Sigma |
|---|---|---|
| Cp | (usl − lsl) ÷ (6 × sigma within) | Within subgroups |
| Cpk | the smaller of (usl − mean) and (mean − lsl), ÷ (3 × sigma within) | Within subgroups |
| Pp | (usl − lsl) ÷ (6 × sigma overall) | Overall |
| Ppk | the smaller of (usl − mean) and (mean − lsl), ÷ (3 × sigma overall) | Overall |
Session 4: Capability done right, a gauge study and a receiving inspection
35 minutesWhy
Customers read capability reports, so Cpk computed with the wrong sigma, or reported for an unstable process without a flag, is a broken promise in writing. Matching a second calculation to three decimals is the third check that defines done. A gauge study first tells you whether the readings can be trusted at all, and a receiving inspection shows the same tables deciding about a lot.
Do this
Ask a second person to compute Cp, Cpk, Pp and Ppk for the 36 readings (specification 9.60 to 10.40, sigma within from the average moving range ÷ d2 for n = 2) in a spreadsheet or the free R language, and save the four numbers to three decimals in docs/spc-capability-check.csv. Type the Z1.4 rows your receiving inspection uses from your copy of the standard into docs/z14.csv.
On a new branch spc/capability:
1. A capability study for a characteristic over a period: n, mean, sigma_within and sigma_overall in separate columns, Cp, Cpk, Pp, Ppk, a normality test result, expected ppm. stable is true only if the rules engine found no signal in the period; otherwise the screen shows "Unstable: capability is indicative only". Below the target in ext (1.33, or 1.67 for special characteristics) writes spc.capability.below_target.
2. Tests: on the 36 readings in tests/fixtures/spc-reference.json, the four indices match docs/spc-capability-check.csv to 3 decimals (you must not edit that file); the study is marked stable false, because the period has two signals; Cpk is never computed from sigma_overall.
3. A crossed gage R&R by ANOVA (10 parts, 3 operators, 3 trials) storing pct_grr, ndc and result (under 10 acceptable, 10 to 30 marginal, over 30 unacceptable), tested on a made-up study with a hand-checked answer.
4. A receiving inspection lot: the plan picks the scheme; for z14_aql the sample size and accept number come from docs/z14.csv only; the decision accept, reject or conditional; a reject writes spc.inspection_lot.rejected.
Push, open a pull request titled "SPC capability, MSA, inspection", wait for every check, and tell me the result in plain words.You will see recreated screen
- Your colleague's spreadsheet and the module agree; the old tool's figure will match Pp or Ppk if it used overall sigma.
- Stable first: capability on an unstable period is shown, but flagged.
Check it worked
Pull request SPC capability, MSA, inspection is green, and the reference study shows four indices matching the second calculation, marked unstable.
If it goes wrong
Cpk and Ppk come out identical
Sigma within was not used. Say: Show me sigma_within and sigma_overall and how each is computed; Cpk must use sigma within. That mix-up is the first pitfall.
A capability number appears on the board with no stable flag
Say: Show the stable flag beside every capability figure, and Unstable when it is false. A figure without its condition is a number nobody measured.
You do not have Z1.4 or the AIAG manuals
Do the rest of the step now and the table-driven parts when the copies arrive. Never type a table from memory or an unofficial copy.
Knowledge check
Why must replaying 100 new readings leave ucl, cl and lcl exactly where they were?
Knowledge check
What must be recorded before a violation can be acknowledged?
References
- NIST/SEMATECH e-Handbook: Process or product monitoring and control. https://www.itl.nist.gov/div898/handbook/pmc/pmc.htm
- ASQ: Control chart. https://asq.org/quality-resources/control-chart
- NIST/SEMATECH e-Handbook: Measurement process characterization. https://www.itl.nist.gov/div898/handbook/mpc/mpc.htm
- The R Project for Statistical Computing. https://www.r-project.org/
Chapter 4 · Sessions 5 and 6
Move the history, and switch the old tool off
Characteristics, specification limits and measurement history come from the old tool's export. The import is proven on made-up data and rehearsed on the development project with a copy IT has approved, where limits and capability are recomputed and compared with the old tool's own figures. Then it runs into production through the pipeline, both tools run side by side, and the old one is switched off.
30 min5 stepsEnds with the module gate
By the end of this chapter you can
- Build an import that is safe to run twice and replays history through the rules engine in report-only mode.
- Rehearse on the development project with a copy IT approved in writing, explain every difference from the old tool's limits and capability, and remove the rehearsal the same day.
- Import into production through import-spc.yml, started by a person from main for an approved export, run a week side by side, cut over and record the saving.
Imported history is replayed through the rules engine in report-only mode: last year's signals appear in a report, never as open violations that page the floor today. Limits and capability are then recomputed from the history and compared with the old tool's own figures; that comparison is the validation, and every difference must have a reason (most often, the old tool's Cpk used overall sigma).
| Key or secret | What it unlocks | Where it lives | Who holds it | Never |
|---|---|---|---|---|
| spc_importer password (development) | Signing in as the insert-only import login on acme-platform-dev; listed by name in docs/KEYS.md | Password manager; GitHub secret SPC_IMPORTER_PASSWORD_DEV | pat@acme.com, sam@acme.com | Never in a file, a chat or Claude Code |
| spc_importer password (production) | Signing in as the insert-only import login on acme-platform-prod, until it is set to NOLOGIN at cut-over; listed by name in docs/KEYS.md | Password manager; GitHub secret SPC_IMPORTER_PASSWORD_PROD | pat@acme.com, sam@acme.com | Never on a laptop outside the password manager |
| The old SPC export | Characteristics, limits and every historical reading, with operator names | A private folder, then the private Storage bucket imports; its sha256 and counts in docs/imports/spc-approved.md | The quality engineer | Never in the repository, a test, or a chat |
Session 5: The import, built and tested on a made-up export
35 minutesWhy
History is what lets you recompute limits and capability and check them against the old tool: the validation that proves the module computes correctly. An import that runs twice without duplicating, writes nothing in a dry run, refuses a file nobody approved, and replays history without paging the floor, means the real readings only ever meet code that has been reviewed and proven.
Do this
First, with the quality engineer, write docs/spc-import-map.md: the export's counts (characteristics, charts, readings per characteristic, oldest and newest dates), how old chart types, rules and cause codes map to the module's, and the old tool's own limits and Cpk for the characteristics in the first slice.
Read docs/spc-import-map.md, the M09 section of docs/spine-map.md and docs/matrix.json. On a new branch spc/import:
1. scripts/import/spc-import.mjs: reads one export file (a zip), connects as the database login spc_importer with the password from the environment variable SPC_IMPORTER_PASSWORD (never printed), and inserts characteristics (joined to our characteristics table as docs/spine-map.md says; a part or characteristic not in the spine stops the import with a list), charts with the old limits (limits_basis manual, the old values kept in ext.legacy_limits), and readings with source import and their original times. It only inserts: existing rows (same code; same characteristic, time and value) are skipped with on conflict do nothing, so a second run adds nothing. Every row carries ext.import_run.
2. Report-only replay: imported readings are run through the rules engine and the signals written to the run's report, never as spc_violation rows.
3. A comparison report per characteristic: limits and Cp, Cpk, Pp, Ppk recomputed from the history beside the old tool's figures from docs/spc-import-map.md.
4. --dry-run changes nothing. supabase/snippets/spc-remove-run.sql, for the development project only, deletes only the rows whose ext.import_run is the run id I type in; I paste it into that project's SQL editor myself.
5. tests/import/ on a made-up export (SYN- names): dry run changes nothing; counts match; second run adds nothing; replay opens no violation; an export whose sha256 is not approved is refused; a count that differs from the approved counts fails the run; the removal snippet removes only its own run.
6. .github/workflows/import-spc.yml: started by hand only (workflow_dispatch) and refusing to run from any branch but main; inputs target (development or production) and dry_run. It downloads the export from the private Storage bucket imports of the target and computes its sha256; it refuses unless that sha256 and the expected counts (characteristics, charts, readings) are recorded for that target in docs/imports/spc-approved.md on main; it runs with SPC_IMPORTER_PASSWORD_DEV or SPC_IMPORTER_PASSWORD_PROD; it fails on any count mismatch (the export must equal the approved counts, and imported plus skipped must equal the export); it uploads both reports as artifacts. No GitHub environment with required reviewers. Never print a secret.
Push, open a pull request titled "SPC import", wait for every check, and tell me the result in plain words. Do not run the workflow.You will see recreated screen
- Last year's signals go into a report, not onto today's violation list.
Check it worked
Pull request SPC import is green and merged; the workflow's only trigger is workflow_dispatch, it refuses any branch but main, and it reads the approved sha256 and counts from docs/imports/spc-approved.md.
If it goes wrong
Claude Code wants a sample of the real export in tests/
Refuse. Real readings never go into the repository; fixtures are made up and marked SYN-.
The replay opens violations on the development chart
Stop: the floor would be paged for last year. Say: Replay must write signals to the report only; add a test that the replay opens no violation.
Claude Code suggests a GitHub environment with required reviewers
Say: No environments with required reviewers; the reviewed pull request that records the sha256 is the approval. On the Team plan they are not available for private repositories.
Session 5: Rehearse on the development project, and compare with the old tool
30 minutesWhy
This is the validation the specification asks for: limits and capability recomputed from your real history and set beside the old tool's own figures. Doing it on the development project, with a copy IT has approved in writing, means differences are explained before anything reaches production; removing the rehearsal the same day keeps that project made-up only.
Do this
Ask IT to approve one copy of the export for the rehearsal, in writing, redacted where it holds personal data (operator names on readings). Work out its fingerprint in a terminal (on Windows, Get-FileHash in PowerShell):
shasum -a 256 ~/private/spc-export.zipOn a new branch spc/import-approval-dev, create docs/imports/spc-approved.md with a section "development rehearsal": export file spc-export.zip, sha256 <paste the value>, expected counts <characteristics, charts, readings>, IT's written approval for one rehearsal on acme-platform-dev given on <date> by <role>, redacted where it held personal data, and a line "removed on:" left empty. Open a pull request titled "SPC: approve rehearsal export".Owner two approves the pull request and you merge it. On the development project, set the import login's password yourself in the SQL editor (alter role spc_importer login password '…', the value from the password manager), then:
https://github.com/acme-ops/acme-platform/settings/secrets/actions
If missing: new secret SPC_IMPORTER_PASSWORD_DEV, the value only.
https://supabase.com/dashboard/project/tsrqponmlkjihgfedcba/storage/buckets
Upload the approved copy to the private bucket imports.
https://github.com/acme-ops/acme-platform/actions/workflows/import-spc.yml
Run workflow from main: target development, dry_run true; read both reports; then dry_run false.
The same day: paste supabase/snippets/spc-remove-run.sql with the run id into the development project's SQL editor, delete the file from the bucket, and record the date on the "removed on:" line through a pull request.
You will see recreated screen
| Characteristic | Old UCL | New UCL | Old Cpk | New Cpk | New Ppk |
|---|---|---|---|---|---|
| Flange height | 10.31 | 10.31 | 1.41 | 1.58 | 1.41 |
| Hole position | 0.052 | 0.049 | 1.12 | 1.15 | 1.06 |
- Two calculations from the same history, side by side.
- A difference with a reason. One without a reason means you are not ready.
Check it worked
The sha256 matched and the counts agree with docs/imports/spc-approved.md; every limit and capability difference in the comparison report has a written reason; the same day the rehearsal rows are removed with the snippet, the file is deleted from the bucket, and the date is recorded.
If it goes wrong
The run refuses: sha256 not approved
The file in the bucket is not the one recorded on main (a re-export changes it). Record the new value through a pull request owner two approves, or upload the approved file.
The run fails at sign-in although the secret exists
The value is probably wrong: on our Academy a key's value was its own name, pasted by mistake. Paste the value only, never NAME=value.
A limit differs and nobody can say why
Check the period and subgroup size the old tool used, and whether it recalculated automatically (Session 1). Do not go to production with an unexplained difference.
Session 6: Import into production through the pipeline, and run a week side by side
25 minutes, then a weekWhy
Real history reaches production only through reviewed code that a person starts from main, for an export whose fingerprint and counts were approved in a reviewed pull request, never from a laptop, an upload page or an agent. A week where readings go into both tools shows whether operators, gauges and the rules engine behave on real days, and gives you the side-by-side figures the cutover rests on.
Do this
Take a fresh export, work out its sha256, and add a "production" section to docs/imports/spc-approved.md (file, sha256, expected counts, date) through a pull request; owner two approves and you merge. Set spc_importer's password on production yourself in its SQL editor. Then:
https://github.com/acme-ops/acme-platform/actions/workflows/deploy.yml
Check the latest deploy on main is green, so production has every migration.
https://github.com/acme-ops/acme-platform/settings/secrets/actions
If missing: SPC_IMPORTER_PASSWORD_PROD, the value only.
https://supabase.com/dashboard/project/abcdefghijklmnopqrst/storage/buckets
Production Storage: upload the export to the private bucket imports.
https://github.com/acme-ops/acme-platform/actions/workflows/import-spc.yml
Run workflow from main: target production, dry_run true, then false, then false once more (it must add nothing).
Then the quality engineer proposes limits for the first slice from the history, the quality approver approves them, and for one week every reading in that slice goes into both tools.
You will see recreated screen
| Kind | Approved | In export | Imported | Skipped |
|---|---|---|---|---|
| Characteristics | 42 | 42 | 42 | 0 |
| Readings | 61,880 | 61,880 | 61,880 | 0 |
- Started by a person on GitHub, from main, for the approved file.
- The counts that go into docs/cutover.md; any mismatch fails the run.
- Safe to run twice.
Check it worked
The run's sha256 matched the approved production entry, production counts equal the approved counts, a second run added nothing, the first slice's limits are approved in the module, and the side-by-side week has started.
If it goes wrong
The run fails with "relation does not exist"
Production is missing a migration. Check the deploy run and the daily freshness check from Session 11; never apply by hand. Our production database once fell nine migrations behind main.
The run fails on a count mismatch
Do not edit the approved counts to make it pass. Read the report, find which rows are missing or extra, and record a corrected export through a reviewed pull request.
Operators stop entering readings in one of the tools
Restart the count from the day both were used again; a partial week compares nothing.
Session 6: Compare the week, cut over, and cancel with the saving written down
35 minutesWhy
The week's side-by-side figures are the evidence for switching, and the definition-of-done checks run on the deployed address are the proof the module computes correctly. The module is finished when the old tool stops costing money; the saving written as arithmetic from invoices proves the work paid for itself.
Do this
At cut-over, set the import login to NOLOGIN on production and development (alter role spc_importer nologin in each project's SQL editor). Then:
On a new branch spc/cutover, write docs/cutover.md and update docs/spc-inventory.md from what I give you:
1. The week side by side: readings, signals by rule, chart limits and Cp, Cpk, Pp, Ppk per characteristic, old against new, with every difference explained (where I wrote "unexplained", say we are not ready).
2. Signal response time and the closed-without-cause query (must be zero rows) from the module.
3. The three checks that define done on the deployed demo address, with date and who ran them: the reference readings reproduce exactly; capability matches the second calculation to 3 decimals; every violation needs a coded response before closing.
4. The cutover date, where the old tool's final export is stored and its sha256, the retention period the quality engineer set, the old annual cost from invoice <number>, the cancellation or end date, and the saving as arithmetic from the invoices I give you, never an estimate; each tool and workaround marked replaced, retired or still in use; and, in docs/KEYS.md, spc_importer set to NOLOGIN on both projects with the date.
Then add this module's checks to docs/testing-protocol.md and open a pull request titled "SPC cutover".
My figures:
<paste the old tool's and the module's figures, the check results, dates and invoice figures>You will see recreated screen
| Measure | Old tool | Module | Note |
|---|---|---|---|
| Readings | 1,204 | 1,204 | none |
| Signals | 3 (rule 1 only) | 7 | old tool had rules 2-8 off |
| Cpk, flange height | 1.41 | 1.58 | old Cpk = module Ppk (overall sigma) |
| Closed without cause | not recorded | 0 | query in testing protocol |
- Every difference has a reason; more signals is the module seeing what the old settings hid.
- The three checks, on the deployed address, dated.
Check it worked
docs/cutover.md is merged with no unexplained difference and the three checks passing; spc_importer is NOLOGIN on both projects; the old tool is cancelled or has an end date; its export is stored with its fingerprint; the saving is written from invoices; docs/testing-protocol.md lists the module's checks.
If it goes wrong
The module shows many more signals than the old tool
Usually the old tool had rules switched off or recalculated limits. Write which, and agree the rules per chart with the quality engineer; do not switch rules off to match the old count.
Someone wants to keep the old tool for its reports
Ask which report. Build it from the module's tables, or find why the import missed the data, before cancelling.
Knowledge check
Why is imported history replayed in report-only mode?
Knowledge check
In the rehearsal, the old tool's Cpk equals the module's Ppk. What does that tell you?
References
- GitHub Docs: Manually running a workflow. https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow
- GitHub Docs: Using secrets in GitHub Actions. https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions
- Supabase Docs: Storage. https://supabase.com/docs/guides/storage
- ISO: the standards catalogue (search ISO 22514 and ISO 2859-1). https://www.iso.org/
Chapter 5 · 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
SPC and Inspection: Charts, Run Rules, Capability, Gauges and First Articles
Element M09 complete · Learner
Your LMS records this completion. For the CivOps Foundation certificate, finish the Foundation Course at https://civops.io/learn.