---
title: Rewrite archive_projections for Postgres
type: task
status: completed
description: >-
  Rewrite (or delete) scripts/archive-projections.mjs, which carries pre-existing MySQL-syntax and
  column-mismatch bugs leaving it inert against the conformed Postgres projections_archive table;
  establish whether an archival cadence is still wanted before repairing vs removing.
base_uri: user:task/league/rewrite-archive-projections-postgres.md
created_at: '2026-07-24T16:46:16.955Z'
entity_id: b6f67dd3-f67c-49f9-b839-300c4b670afb
finished_at: '2026-07-29T21:59:11.115Z'
observations:
  - ████████████████████████████████████████████████
  - ████████████████████████████████████████████████
owner_identity_uri: █████████████████████████
priority: Low
public_read: true
relations:
  - duplicates [[user:task/league/rewrite-archive-projections-for-postgres.md]]
tags:
  - user:tag/league-xo-football.md
updated_at: '2026-07-29T21:59:12.182Z'
visibility_analyzed_at: '2026-11-05T23:50:17.300Z'
---

# Rewrite archive_projections for Postgres

## Context

Surfaced during the projections cluster of [[█████████████████████████-██████-████████-█████████]] (2026-07-22, league a3804da9/83bfe4cc). `scripts/archive-projections.mjs` carries pre-existing MySQL-syntax and column-mismatch bugs that make it inert against the Postgres `projections_archive` table. During the projections conform it was column-renamed (`year`→`season_year`, `seas_type`→`season_type`, timestamp handling) and documented as inert, but NOT functionally fixed — that is deliberately out of the redesign's rename-conform scope. Operator decision 2026-07-22: mint a separate task for the Postgres rewrite rather than fold it into the schema-redesign cluster work.

## Plan

- [ ] Read `scripts/archive-projections.mjs` and enumerate every MySQL-ism (syntax, functions, dialect) and every column reference that mismatches the current Postgres `projections_archive` schema (already conformed to `season_year`/`season_type`/`generated_at`).
- [ ] Rewrite the archival query/write path against Postgres (node-pg/Knex per repo convention), targeting the conformed `projections_archive` columns.
- [ ] Verify: run against a candidate/test DB, confirm it archives the intended projection rows correctly (row-count + spot-check); confirm it is idempotent / re-runnable.
- [ ] Decide + wire the invocation cadence (was it scheduled? confirm whether an archival cadence is still wanted, or the script is fully dead and should be removed instead of rewritten — clean-end-state: if nothing needs archived projections, delete the script rather than fix it).
- [ ] Commit with explicit pathspec; deploy if it becomes a live path.

## Notes

- Low priority / inert: no live consumer reads `projections_archive` on a hot path, and the script does not currently run successfully, so there is no active data loss — this is clean-end-state debt, not an outage.
- Clean-end-state framing: prefer deletion over repair if the archival need no longer exists. Establish need before rewriting.
