Language module Phase 7 — predecessor data import — implementation plan
Scope: the seventh phase of the language-module migration
(docs/architecture/language-module-migration-v1.md, item 13 and the Phase 7 line): the
predecessor’s lexeme identity, its paid-for machine-translation and dictionary-lookup caches, and
ONE person’s learning data, moved into emergent once. Phases 3–5 are closed; nothing here reopens
them.
Status: implemented 2026-09-10 — every slice is on develop (7a 6318b354, 7b 2bc35057, 7c with this
status update). bun run --cwd packages/db predecessor:import --source-url … --person-email … --dry-run
against the surviving copy reconciles every step: identity 239,344 en / 515,781 zh; frequency 53,467 /
98,733; bing-mt 161,531 / 515,522; bing-dict 239,344 / 515,781; google-mt 147,066; cards 26,410 graph /
26,409 sound / 26,409 meaning; node facts 41,358; day facts 508. Closes when the maintainer has run it
against the rebuilt database (run order below) and parked it. Decisions taken while landing, in the
commits: the identity reconcile reports graph collisions, legacy-id conflicts and empty graphs as
counted skips; cache steps count distinct source words under the same join the write pass uses; the
person steps resolve the person once per run and refuse if it already holds cards or facts; an efactor
below the CHECK floor (the predecessor’s never-reviewed 0) becomes the default; the baseline evidence
row is a change_audit_entry (source_operation_id = predecessor-import:v1), written only when all
three person steps matched; and a ninth step, policy, derives the verdicts the imported facts imply
through the projector’s person-scoped replayPolicyOnly — expecting the person’s userword rows with a
first success, since for an imported fact counts_as_known reduces to first_success_at != null — and is
the one person step the one-shot guard exempts, because it requires the rows that guard protects.
The standard for this phase, ruled by the maintainer: this is one-shot work over personal and reference data. The job prints what it expected and what it did; the maintainer reads, practises, looks at the stats, and parks it when they look roughly right. No integration lane, no seeded source fixture, no benchmark run, no re-import path. The same standard applies when it runs against the future production database.
Grounding (verified 2026-09-10 against the surviving copy)
Section titled “Grounding (verified 2026-09-10 against the surviving copy)”- Identity is the same contract on both sides. The predecessor’s
wordtable is one row per(language, graph);word.id = bingapilookup.idfor all 755,125 rows (zh-Hans 515,781, en 239,344).lang_lexemeis unique on(language_tag, graph)and carries a nullablelegacy_id, unique per(language_tag, legacy_id), that nothing writes yet. - Three Bing caches, two consumed here.
bingapitranslation771k rows (666k match a word),bingapitransliteration561k (515k match),bingapilookup998k rows of the Dictionary Lookup API (755k match a word; the 243k orphans are mostly multi-word English fragments). Emergent’s pipeline speaks Translate and Transliterate only and caches inlang_dictionary_entryunder thebing-mtsystem dictionary per pair, content{gloss, phones}, read before any live call. providerdefinition(1.3M):fallback= the Translate gloss re-shaped;cedict= a CEDICT re-parse;google= 147k en→zh Google Translate sentences;abc= the ABC dictionaries in the predecessor’s parsed format (the maintainer holds the raw files and a licence).wordmaterial:sound(pinyin) on 582k;synonyms(Bing back-translations) on 137k;metadata.frq(SUBTLEX words-per-million etc.) on 152,200 (zh 98,733, en 53,467; 381 with several POS rows); HSK tags on 11k. The predecessor ordered new words byfrq.wcpm.- The surviving copy is
dev-pg-transcrobes, databasesupabase, a 5 May 2026 snapshot on the pre-cutover model (card539k,userword133k,userlist161, 155 auth users; last card and word activity 2026-04-29, last sign-in 2026-05-01).wordstate/research_eventnever held data in any surviving copy. Production is gone; the copy is backed by the Barman backup in~/backups/db-backups-prod-transcrobes/supabase-cluster/, an external SSD and Garage on mac101. - The maintainer’s own rows (
auth.users.email = anton@melser.org): 41,358userword, 508userday, 10 goals, 6 content, 1 list, plus cards in four types.
Rulings (ratified 2026-09-10)
Section titled “Rulings (ratified 2026-09-10)”- R1 — Reconcile by graph. The identity step is idempotent and order-independent: for every
predecessor
wordit stampslegacy_idonto the lexeme that already exists for that(language, graph)or mints the lexeme with the id set. The list imports already run on the current database were not a mistake; the reconcile stamps them. - R2 — Every
wordrow becomes a lexeme, both languages; the 243k lookup orphans are dropped. - R3 — Imported lexemes are UNPUBLISHED and the import never touches publication (ADR-0059’s 2026-08-01 amendment: the everything-public semantics are not ported). Publication stays with the curated paths (list import, CEDICT ingest). A predecessor learner’s obscure words reach their devices through the own-index shape; they are not platform-enumerable until a curated source names them.
- R4 — The caches. Translate + Transliterate fold into one
bing-mtentry per matched word and pair (glossfrom the translation text,phonesfrom the space-separated pinyin), zh→en and en→zh. Dictionary Lookup becomes abing-dictsystem dictionary per pair: content stored as parts of speech with their glosses in Bing’s confidence order, back-translations kept as data, no pronunciation (Bing Lookup gives none). Implementation note: the client picks how to draw an entry from its stored shape, sobing-dictneeds a small rendering addition inpackages/domain/src/lang-dictionary-presentation.ts;google-mtreuses the MT shape and needs none. - R5 —
providerdefinition.fallbackandcedictdropped (the CEDICT importer runs on the fresh database from the source file).googlecarried as agoogle-mten→zh system dictionary (gloss =sentences[].trans).abcEXCLUDED from this import: a separate project ports the two raw ABC files through two newDictionaryParserimplementations (the transcrobes parser is a reference, not code to run), scopedorg-licensedtopersonal-0narrowed to the maintainer’s personal Offering; further licences become further rows. - R6 —
wordmaterial.soundis the phones fallback where no transliteration row exists.synonymsand the HSK tags are dropped.frqis carried as ONE nullable numeric column onlang_lexeme(words per million, firstfrqrow), present on BOTH identity shapes (shared published index and the per-person own index), consumed by the ordering policy’s frequency criterion log-scaled with the list rank as fallback where null. New minted words get null and score zero as unranked words do today. Refresh from the public corpora (SUBTLEX-CH, SUBTLEX-US) is a later job — backlog 0015. - R7 — Source of record is the
dev-pg-transcrobescopy, read frozen over a second connection. It is on the old model, so the migration doc’s item 13 is corrected tocard+userword+userlist; there is noresearch_eventhistory to archive. - R8 — One person. Only
anton@melser.orgis ported. Nobody else is minted or imported. - R9 — The person is resolved at run time. The maintainer signs in once on the rebuilt database
(which also mints the personal Offering);
--person-emailresolves exactly one active person holding that email and the job refuses on none or many. No pre-minted person, no new contact-point source, no dependence on identity linking. - R10 — Rows.
card→lang_card(same SM-2 fields;word_id→ lexeme vialegacy_id); phrase cards are dropped (“the idea was good, the execution wasn’t”).userword→lang_node_fact(nb_seen→ encounters,nb_checked + nb_translated→ aid interactions, dates to their counterparts), minting the person’s nodes through the lazy-minting path and recording one provenance-marked baseline evidence row. Facts written directly fold no event, so nothing asks the projector what they mean: a finalpolicystep therefore derives the verdicts they imply —lang_node_policy_outputthrough the projector’s own person-scopedreplayPolicyOnly, never a second interpreter — because the learner surface reads the verdicts, not the facts. (Superseded by the offline plan R1/R6 (2026-09-12): the learner surface computes the verdict from thelang_word_staterow the import writes, and thepolicystep now derives the SERVER-sideperson_competency_stateover it.)userday→lang_day_fact(seen → encounters, checked → lookups, success → successes, success + failures → grades). Goals, the personal list and content rows are dropped and recreated by hand (ADR-0061: content is never re-imported). (2026-09-17: the learner’s EXCLUSIONS are carried too —userworddetails.ignore(the May snapshot’s spelling; the predecessor’s own 2026-07-25 cutover renamed itwordstate.excluded) becomeslang_word_state.excluded, so thepolicystep’s expectation is “first success AND not ignored”. Without it, 8 930 words the maintainer deliberately put aside — 7 086 of them with a first success — would come back as words they are told they know.) - R11 — Mechanism. One job,
packages/db/scripts/import-predecessor.ts(scriptpredecessor:import):--source-url,--person-email,--dry-rundefault-safe like the other importers. Ordered, individually re-runnable, idempotent steps: identity reconcile → frequency →bing-mt→bing-dict→google-mt→ cards → node facts → day facts → policy. The three person steps that write rows refuse if the person already has cards or facts;policyderives from those rows and is exempt. Batched writes. The source tables are declared as Drizzle objects inside the script module (the SQL-strings rule). Operator-run, never by an agent. - R12 — Entries are written directly as
lang_dictionary_entryrows against the reconciled lexemes, never throughrunDictionaryIngest, whose door publishes every headword it touches.
Run order (operator runbook)
Section titled “Run order (operator runbook)”-
Migrations; the account — sign in once, or mint it with
users:create— and its personal offering, minted bypersonal-offering:ensure(see The scripted form below). -
predecessor:import(all steps — the last,policy, derives the verdicts the imported facts imply, which is what makes them visible as “words you know”;--step policyre-derives verdicts for an already-imported person). (2026-09-17:--steptakes a comma-separated list, always run in declared order, because the person half is ONE job — the recovery after a deliberate delete of that person’s rows is--step cards,node-facts,day-facts,policyin a single run.) -
The seven list imports (
lists:import,--levelfor HSK 1–6). HSK 1–6 are the six hskhsk.com “HSK Official With Definitions 2012” files (zh_hsk1.txt…zh_hsk6.txt, in thetpddata directory) — tab-separated, and the importer takes the first column, so they go in as they are. The frequency list is cut from the published SUBTLEX-CH corpus file, which is already sorted by count: drop the header, take the first ten thousand data lines.Terminal window tail -n +2 "$SUBTLEX_ZH_FILE" | head -n 10000 > tmp/zh-frequency-top-10k.txtbun run --cwd packages/db lists:import --language zh --file tmp/zh-frequency-top-10k.txt --slug zh-frequency-top-10k --title "Chinese frequency, top 10 000"The parser collapses the corpus’s duplicate rows, so the list lands a few dozen graphs short of ten thousand — take a few hundred extra lines if the round number matters.
-
The CEDICT import.
-
The ABC dictionaries (backlog 0014) — one row each, licensed personally. The Chinese–English run is the one to do; the English–Chinese run waits for a learner who can reach an
enrow (0014 ruling 7).Terminal window bun run --cwd packages/db dict:import --provider abc-ce --file "$ABC_CE_FILE" --language zh --l1 en --scope org-licensed --organization personal-0 --offering <personal offering id>bun run --cwd packages/db dict:import --provider abc-ec --file "$ABC_EC_FILE" --language en --l1 zh --scope org-licensed --organization personal-0 --offering <personal offering id>The personal offering must exist first — its id is what the licence row points at. Step 1’s
personal-offering:ensuremints it and prints the id as its last stdout line; the first write into the personal space (saving a text to Your library) mints it too. Signing in alone does not.DATABASE_URLmust be in the shell for a real run — only the scripted block below loads.env.development.local, so export it first (set -a; source .env.development.local; set +a). A run that stops on a dropped connection has written a prefix; re-running the same command finishes it. -
frequency:refresh, once per language, over the PUBLISHED SUBTLEX files (backlog 0015) — it fills thefrequency_wcpmof every word the predecessor’s own copy of those corpora did not cover, and leaves the figures step 2 carried alone unless--overwriteis given.
Predecessor first so the curated imports adopt already-stamped rows and do nothing but publish.
The scripted form (every step)
Section titled “The scripted form (every step)”infra/utils/cloudnativepg/supabase/db/recreate-database.sh --with-real-user recreates the local
database as usual and then runs every step above for the maintainer’s own account, in order. 1: it
mints the auth user with users:create, grants platform_admin with roles:grant, waits for the api
(supabase-functions) to roll out, and mints the personal offering with personal-offering:ensure,
keeping its id. 2: predecessor:import against the frozen transcrobes copy. 3: the six HSK lists
from HSK_LIST_DIR and the zh frequency list cut from SUBTLEX_ZH_FILE. 4: CC-CEDICT. 5: ABC
Chinese–English, licensed to that offering, re-run once if it stops part-way (English–Chinese is not
run — 0014 ruling 7). 6: frequency:refresh once per language, last, so the words the dictionaries
minted receive figures too. An optional input that is absent is skipped with a message and listed again
at the end; nothing is left to do in a browser.
Its inputs come from .env.development.local (documented in .env.development.local.example), which
the block loads into the environment — a variable already set in the shell wins, the file fills the
rest, and the bun jobs inherit it, so none of them takes an --env-file:
| key | what it is |
|---|---|
EMERGENT_REAL_USER_EMAIL |
the account’s email — prompted when missing or blank |
EMERGENT_REAL_USER_NAME |
its display name — prompted when missing or blank |
EMERGENT_USER_PASSWORD |
its password — prompted silently when missing; never an argument |
TRANSCROBES_DATABASE_URL |
the predecessor source. Required: no prompt and no fallback, because a wrong source is a silent bad import |
SUBTLEX_ZH_FILE, SUBTLEX_EN_FILE |
the published SUBTLEX file per language (optional; ~ expanded; unset or missing on disk skips that language with a message). The zh file also gives the zh frequency list (step 3) |
HSK_LIST_DIR |
the directory holding zh_hsk1.txt … zh_hsk6.txt (optional; ~ expanded; unset or not a directory skips the six lists, a missing file skips that level) |
CEDICT_FILE |
the CC-CEDICT file (optional; ~ expanded; unset or missing skips step 4) |
ABC_CE_FILE |
the ABC Chinese–English file (optional; ~ expanded; unset or missing skips step 5). Licensed: it never enters the repo |
The file is read by a small loader, never sourced or evaled: it carries JSON values (the LTI JWKs)
that are not shell-safe, and values are taken verbatim — one pair of surrounding quotes stripped,
$(…) and ${…} left alone.
users:create is how the person is minted without a browser. Step 1 offers “sign in once” only
because a sign-in is what mints an auth user, and handle_auth_user_created mints the person, their
profile and their identity binding from it (ADR-0013).
EMERGENT_USER_PASSWORD=… bun run --cwd packages/db users:create --email … --display-name "…" creates
the same auth user through the Supabase admin API, so the person exists before predecessor:import has
to resolve them. The password is read from that environment variable and never from an argument (an
argument is visible in ps); --dry-run contacts no service at all; an email GoTrue already holds is
reported and exits 0, so a re-run is harmless. It is an operator job — it mints ONE real person, and it
writes no seeded mark.
personal-offering:ensure is how the personal offering is minted without a browser (ADR-0056
decision 3). EMERGENT_USER_PASSWORD=… bun run --cwd packages/db personal-offering:ensure --email … signs
in as that account (GoTrue’s password grant) and POSTs to the api’s own provisioning route,
/functions/v1/workflow/personal-offering — whose service, ensurePersonalOfferingWithDb, is the one
learner-web’s first write into personal space runs too. It goes through the route, not the database:
authority_level cannot be minted over the sync rail, and the provisioner’s one transaction lives in the
api, where calling it exercises it as deployed. It is idempotent (a re-run answers the same offering and
says whether it was created), the password comes from the environment only, --dry-run contacts nothing,
and the offering id is its last stdout line, alone — which is how the scripted run hands it to the ABC
import. Signing in is no longer a step.
Verification
Section titled “Verification”The job prints the source counts it expects next to the counts it wrote — lexemes stamped per language, frequency set, entries per dictionary, cards per type, node facts, day facts, known verdicts — and exits non-zero if they differ. Nothing else.
Slices
Section titled “Slices”- 7a — identity and frequency.
frequency_wcpmonlang_lexemeand on both identity shapes (revision bumps), the ordering policy’s criterion, the migration regeneration; the script skeleton with the identity and frequency steps. - 7b — caches. The
bing-mt,bing-dictandgoogle-mtsteps; thebing-dictpresentation addition. - 7c — the person. Cards, node facts, day facts; the run-order note in the runbook.
Records forced elsewhere
Section titled “Records forced elsewhere”docs/architecture/language-module-migration-v1.mditem 13 corrected (R7).- ADR-0059 consequence list: the frequency column (R6).
- Backlog 0014 (ABC two-parser project, R5) and 0015 (frequency refresh from the corpora, R6).