Skip to content

Commit aee4d87

Browse files
committed
feat(sources): pin all four ECMA-376 parts in the manifest
Replace the single `ecma-376` placeholder with four part-specific entries (`ecma-376-part1` through `ecma-376-part4`), each pinned with URL, edition (5th), publication date, and sha256. Part 2 is the 2021 revision; Part 3 is from 2015; Parts 1 and 4 are 2016 - reflected in each entry's version field. The Part 4 zip URL is shared with the existing ecma-376-transitional entry (the XSD zip is extracted from inside Part 4); both rows pin the same outer-zip sha256. scripts/sources-sync.ts now backfills spec_content.source_id by part_number, mapping each row to the matching ecma-376-partN source. The previous backfill targeted a single `ecma-376` source which no longer exists. Migration 0005 cleans up the legacy `ecma-376` placeholder row from reference_sources, but only if no spec_content row references it (safe for a developer who had already backfilled to the placeholder id; idempotent). 44 / 0 tests still passing.
1 parent b313a9e commit aee4d87

3 files changed

Lines changed: 64 additions & 13 deletions

File tree

data/sources.json

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,40 @@
22
"$comment": "Source manifest. Human-edited; scripts/sources-sync.ts upserts these rows into reference_sources.",
33
"sources": [
44
{
5-
"name": "ecma-376",
5+
"name": "ecma-376-part1",
66
"kind": "spec_pdf",
7-
"edition": "unknown",
8-
"version": null,
9-
"url": "https://ecma-international.org/publications-and-standards/standards/ecma-376/",
7+
"edition": "5th",
8+
"version": "2016-12",
9+
"url": "https://ecma-international.org/wp-content/uploads/ECMA-376-1_5th_edition_december_2016.zip",
10+
"license_note": "Published by Ecma International. See the ECMA-376 publications page for the current download and licensing terms before redistribution.",
11+
"sha256": "9d0bcad9cf06054785b03762fcfadbf6bab7e54a5f9d69434e34b7fd464d4129"
12+
},
13+
{
14+
"name": "ecma-376-part2",
15+
"kind": "spec_pdf",
16+
"edition": "5th",
17+
"version": "2021-12",
18+
"url": "https://ecma-international.org/wp-content/uploads/ECMA-376-2_5th_edition_december_2021.zip",
19+
"license_note": "Published by Ecma International. See the ECMA-376 publications page for the current download and licensing terms before redistribution.",
20+
"sha256": "1d489dc491168ea1f9e9a59063acc8dd5f02b4ad1d21aa7ec19ba9a58d020c70"
21+
},
22+
{
23+
"name": "ecma-376-part3",
24+
"kind": "spec_pdf",
25+
"edition": "5th",
26+
"version": "2015-12",
27+
"url": "https://ecma-international.org/wp-content/uploads/ECMA-376-3_5th_edition_december_2015.zip",
28+
"license_note": "Published by Ecma International. See the ECMA-376 publications page for the current download and licensing terms before redistribution.",
29+
"sha256": "42294159fbbbe9393ccadac95b859d7729cc68d908898bcbe31034dda059daa8"
30+
},
31+
{
32+
"name": "ecma-376-part4",
33+
"kind": "spec_pdf",
34+
"edition": "5th",
35+
"version": "2016-12",
36+
"url": "https://ecma-international.org/wp-content/uploads/ECMA-376-4_5th_edition_december_2016.zip",
1037
"license_note": "Published by Ecma International. See the ECMA-376 publications page for the current download and licensing terms before redistribution.",
11-
"sha256": null
38+
"sha256": "bd25da1109f73762356596918bf5ff8b74a1331642dba5f1c1d1dfc6bed34ecd"
1239
},
1340
{
1441
"name": "ecma-376-transitional",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- Drop the legacy `ecma-376` placeholder source row.
2+
--
3+
-- An earlier version of data/sources.json had a single placeholder
4+
-- (`ecma-376`, edition=unknown, sha256=null) that stood in for the whole
5+
-- spec corpus before per-part entries existed. The manifest now pins the
6+
-- four ECMA-376 parts individually (`ecma-376-partN`), so the placeholder
7+
-- is obsolete.
8+
--
9+
-- This migration only deletes the row when nothing in spec_content
10+
-- references it, so a developer who already backfilled source_id to the
11+
-- legacy id stays safe. Idempotent.
12+
13+
DELETE FROM reference_sources
14+
WHERE name = 'ecma-376'
15+
AND NOT EXISTS (
16+
SELECT 1 FROM spec_content WHERE spec_content.source_id = reference_sources.id
17+
);

scripts/sources-sync.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,23 @@ async function main() {
6868
);
6969
}
7070

71-
const [ecma] = await sql<[{ id: number } | undefined]>`
72-
SELECT id FROM reference_sources WHERE name = 'ecma-376' LIMIT 1
73-
`;
74-
if (ecma) {
71+
// Backfill spec_content.source_id by part_number to the matching
72+
// ecma-376-partN row. Idempotent: only touches rows where source_id IS NULL.
73+
for (let part = 1; part <= 4; part++) {
74+
const sourceName = `ecma-376-part${part}`;
75+
const [src] = await sql<[{ id: number } | undefined]>`
76+
SELECT id FROM reference_sources WHERE name = ${sourceName} LIMIT 1
77+
`;
78+
if (!src) continue;
7579
const result = await sql`
76-
UPDATE spec_content SET source_id = ${ecma.id} WHERE source_id IS NULL
80+
UPDATE spec_content SET source_id = ${src.id}
81+
WHERE part_number = ${part} AND source_id IS NULL
7782
`;
78-
console.log(`Backfilled ${result.count} spec_content row(s) -> source_id=${ecma.id}`);
79-
} else {
80-
console.warn("No ecma-376 source row found; skipped spec_content backfill.");
83+
if (result.count > 0) {
84+
console.log(
85+
`Backfilled ${result.count} spec_content row(s) (part ${part}) -> source_id=${src.id}`,
86+
);
87+
}
8188
}
8289
} finally {
8390
await db.close();

0 commit comments

Comments
 (0)