···11+-- Migrate legacy index_hook and script columns into the trigger-keyed
22+-- scripts table, then drop the old columns.
33+44+-- 1. index_hook -> record.index:<lexicon_id>
55+INSERT INTO scripts (id, body, script_type, created_at, updated_at)
66+SELECT 'record.index:' || id, index_hook, 'lua', NOW(), NOW()
77+ FROM lexicons
88+ WHERE index_hook IS NOT NULL
99+ON CONFLICT (id) DO NOTHING;
1010+1111+-- 2. script -> xrpc.query:<id> or xrpc.procedure:<id>
1212+INSERT INTO scripts (id, body, script_type, created_at, updated_at)
1313+SELECT 'xrpc.' ||
1414+ CASE (lexicon_json::jsonb)->'defs'->'main'->>'type'
1515+ WHEN 'query' THEN 'query'
1616+ WHEN 'procedure' THEN 'procedure'
1717+ END || ':' || id,
1818+ script, 'lua', NOW(), NOW()
1919+ FROM lexicons
2020+ WHERE script IS NOT NULL
2121+ AND (lexicon_json::jsonb)->'defs'->'main'->>'type' IN ('query', 'procedure')
2222+ON CONFLICT (id) DO NOTHING;
2323+2424+-- 3. Drop legacy columns.
2525+ALTER TABLE lexicons DROP COLUMN index_hook;
2626+ALTER TABLE lexicons DROP COLUMN script;
···11+-- Migrate legacy index_hook and script columns into the trigger-keyed
22+-- scripts table, then drop the old columns.
33+44+-- 1. index_hook -> record.index:<lexicon_id>
55+INSERT INTO scripts (id, body, script_type, created_at, updated_at)
66+SELECT 'record.index:' || id, index_hook, 'lua', datetime('now'), datetime('now')
77+ FROM lexicons
88+ WHERE index_hook IS NOT NULL
99+ON CONFLICT (id) DO NOTHING;
1010+1111+-- 2. script -> xrpc.query:<id> or xrpc.procedure:<id>
1212+INSERT INTO scripts (id, body, script_type, created_at, updated_at)
1313+SELECT 'xrpc.' ||
1414+ CASE json_extract(lexicon_json, '$.defs.main.type')
1515+ WHEN 'query' THEN 'query'
1616+ WHEN 'procedure' THEN 'procedure'
1717+ END || ':' || id,
1818+ script, 'lua', datetime('now'), datetime('now')
1919+ FROM lexicons
2020+ WHERE script IS NOT NULL
2121+ AND json_extract(lexicon_json, '$.defs.main.type') IN ('query', 'procedure')
2222+ON CONFLICT (id) DO NOTHING;
2323+2424+-- 3. Drop legacy columns.
2525+ALTER TABLE lexicons DROP COLUMN index_hook;
2626+ALTER TABLE lexicons DROP COLUMN script;
···1919 lexicon: &crate::lexicon::ParsedLexicon,
2020) -> Result<Response, AppError> {
2121 // Trigger-keyed dispatch: a script bound at `xrpc.procedure:<id>`
2222- // overrides the default PDS-write flow. The legacy `lexicon.script`
2323- // column is no longer read.
2222+ // overrides the default PDS-write flow.
2423 let trigger = format!("xrpc.procedure:{}", lexicon.id);
2524 if let Some(resolved) = crate::lua::resolve(state, &trigger).await {
2625 // Delegation guard preserved from origin/dev: scripts that run
···4444 const [deleting, setDeleting] = useState(false);
4545 const [saving, setSaving] = useState(false);
46464747- // Editable text state. The lexicon page used to edit `script` and
4848- // `index_hook` columns inline via lua editors; those columns are
4949- // now managed via the Scripts subsystem (see "Scripts targeting
5050- // this lexicon" panel below). We pass the existing values through
5151- // unchanged on save so legacy data isn't accidentally NULLed.
5247 const [jsonText, setJsonText] = useState("");
5348 const [originalJson, setOriginalJson] = useState("");
5449 const [tokenCost, setTokenCost] = useState("");
···8984 await uploadLexicon({
9085 lexicon_json: lexiconJson,
9186 backfill: lexicon.backfill,
9292- // Preserve any legacy script / index_hook values verbatim — we
9393- // no longer edit them here, but leaving them out of the body
9494- // would NULL the columns on upsert and lose data.
9595- script: lexicon.script ?? undefined,
9696- index_hook: lexicon.index_hook ?? undefined,
9787 token_cost: tokenCost ? Number(tokenCost) : null,
9888 });
9989 load();
···262252263253 {/* JSON editor only — scripts (record-event handlers, XRPC
264254 handlers, label-arrival handlers) are managed via the
265265- "Scripts targeting this lexicon" panel above. The legacy
266266- `script` / `index_hook` columns on the lexicons table are
267267- preserved as-is on save but no longer edited here. */}
255255+ "Scripts targeting this lexicon" panel above. */}
268256 <CodePanels
269257 className="flex-1 min-h-0 px-4 md:px-6"
270258 jsonValue={jsonText}