feat(berths): normalize mooring numbers to canonical form
Sweep CRM mooring numbers from the legacy hyphen+padded form ("A-01")
to the canonical bare form ("A1") used by NocoDB, the public website,
the per-berth PDFs, and the Documenso EOI templates. Drift was
introduced by the original load-berths-to-port-nimara.ts seed; this
gates the Phase 3 public-website cutover where /berths/A1 URLs would
404 against a CRM still storing "A-01".
- 0024 data migration: idempotent regexp_replace + post-update sanity
check that surfaces any non-conforming rows for manual triage.
- Invert normalizeLegacyMooring in dedup/migration-apply: it now
canonicalizes ("D-32" -> "D32") instead of legacy-izing.
- Update tiptap-to-pdfme example tokens, EOI fixture moorings, and
smoke-test seed moorings.
- Refresh seed-data/berths.json to canonical form; drop the now-
redundant legacyMooringNumber field.
- Delete scripts/load-berths-to-port-nimara.ts (superseded in 0c).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
31
src/lib/db/migrations/0024_normalize_mooring_numbers.sql
Normal file
31
src/lib/db/migrations/0024_normalize_mooring_numbers.sql
Normal file
@@ -0,0 +1,31 @@
|
||||
-- Normalize berth mooring numbers from legacy hyphen+padded form ("A-01")
|
||||
-- to the canonical form ("A1") that NocoDB, the public website, the
|
||||
-- Documenso EOI templates, and every external reference use.
|
||||
--
|
||||
-- Idempotent: rows already in canonical form are untouched. The regex
|
||||
-- accepts:
|
||||
-- - optional hyphen between letter prefix and digits
|
||||
-- - optional leading zeros on the digits
|
||||
-- - one or more letters in the prefix (future-proofs "AA1" etc.)
|
||||
-- Pure-numeric or otherwise non-conforming moorings (e.g. "B-LEG") are
|
||||
-- left unchanged so they show up in the orphan check below for manual
|
||||
-- review.
|
||||
UPDATE berths
|
||||
SET mooring_number = regexp_replace(mooring_number, '^([A-Z]+)-?0*(\d+)$', '\1\2')
|
||||
WHERE mooring_number ~ '^[A-Z]+-0*\d+$';
|
||||
|
||||
-- Sanity check: surface any moorings that don't match the canonical
|
||||
-- pattern after the rewrite. These need manual triage before Phase 3
|
||||
-- can ship (the public website builds /berths/:mooring URLs from this
|
||||
-- value). Logged via NOTICE so the migration runner prints them.
|
||||
DO $$
|
||||
DECLARE
|
||||
bad_count integer;
|
||||
BEGIN
|
||||
SELECT count(*) INTO bad_count
|
||||
FROM berths
|
||||
WHERE mooring_number !~ '^[A-Z]+\d+$';
|
||||
IF bad_count > 0 THEN
|
||||
RAISE NOTICE 'Mooring normalization: % rows do not match ^[A-Z]+\d+$ - manual review needed', bad_count;
|
||||
END IF;
|
||||
END $$;
|
||||
10639
src/lib/db/migrations/meta/0024_snapshot.json
Normal file
10639
src/lib/db/migrations/meta/0024_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -169,6 +169,13 @@
|
||||
"when": 1777927586934,
|
||||
"tag": "0023_omniscient_reaper",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 24,
|
||||
"version": "7",
|
||||
"when": 1777938954111,
|
||||
"tag": "0024_normalize_mooring_numbers",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user