Add landlord-override DB migrations (0215 data + 0216 schema)

Splits the DB migration artifacts off the frontend branch so they can
land independently:

- 0215_invert_column_mapping: one-shot data migration inverting
  bulk_address_uploads.column_mapping from header->field to field->header
  (drops 'skip' entries). One-shot — see file header and ADR-0003.
- 0216_add_subtask_service: adds sub_task.service (nullable text) to tag
  which pipeline a subtask belongs to (address2uprn vs
  landlord_description_overrides).

Includes the subtask.ts schema source for 0216 so drizzle's snapshot
stays consistent. No app code depends on these yet.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jun-te Kim 2026-05-29 09:50:03 +00:00
parent c3346cdb6a
commit c04ff901c1
6 changed files with 20297 additions and 0 deletions

View file

@ -0,0 +1,22 @@
-- One-shot inversion of bulk_address_uploads.column_mapping.
--
-- Old shape: { "<source header>": "<internal field>" } (header -> field), with
-- unmapped columns stored as "<header>": "skip".
-- New shape: { "<internal field>": "<source header>" } (field -> header), with
-- unmapped fields simply absent. See ADR-0003 and the WIP plan (Q2.2/Q5).
--
-- 'skip' entries are dropped. On a legacy duplicate (two headers -> one field),
-- jsonb_object_agg keeps the last header — the new address-uniqueness rule
-- forbids that going forward anyway. No-op on NULL/empty mappings, so this is
-- safe regardless of data volume. One-shot: assumes rows are still old-shape.
UPDATE "bulk_address_uploads"
SET "column_mapping" = COALESCE(
(
SELECT jsonb_object_agg(elem.value, elem.key)
FROM jsonb_each_text("column_mapping") AS elem
WHERE elem.value <> 'skip'
),
'{}'::jsonb
)
WHERE "column_mapping" IS NOT NULL
AND "column_mapping" <> '{}'::jsonb;

View file

@ -0,0 +1 @@
ALTER TABLE "sub_task" ADD COLUMN "service" text;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1506,6 +1506,20 @@
"when": 1779969672088,
"tag": "0214_superb_maelstrom",
"breakpoints": true
},
{
"idx": 215,
"version": "7",
"when": 1779991310301,
"tag": "0215_invert_column_mapping",
"breakpoints": true
},
{
"idx": 216,
"version": "7",
"when": 1779992128370,
"tag": "0216_add_subtask_service",
"breakpoints": true
}
]
}

View file

@ -14,6 +14,10 @@ export const subTasks = pgTable("sub_task", {
status: text("status").notNull().default("In Progress"),
// Which pipeline this subtask belongs to, e.g. "address2uprn" or
// "landlord_description_overrides". NULL = legacy / address. See ADR-0003.
service: text("service"),
inputs: text("inputs"), // could later change to JSONB if desired
outputs: text("outputs"),
cloudLogsURL: text("cloud_logs_url"),