Files
YPMS/migrations/versions/0004_stub_entity_tables.py
T
Chris TonjesandClaude Opus 5.5 80f280a56f Phase 0 milestone 0.7: retention scaffold
Every mapped table resolves a retention policy; a report-only job runs
over all of them and logs "N records to purge". ARCH §6.4; NIST AU-11,
SI-12; source RFP C.5.7.42.

- framework/retention.py: RetentionPolicy (data class, disposal, period,
  anchor column, cadence, approved, authority), run_retention(), and a
  `python -m ypms.framework.retention` entrypoint. Phase 0 never mutates
  data: interim-period rows are counted (interim_eligible), approved-period
  rows are counted (to_purge), nothing is purged. One retention_run audit
  row per run.
- retention_classes.py: PIA §9 data classes at their interim periods, all
  approved=False pending YPMS-POAM-054. Classes without a PIA basis
  (hosts, operational logs, accounts, consent-derived) are unset and logged
  by name with their governing POA&M item. Vendored framework tables are
  mapped by table name so vendored files stay unchanged.
- stub_models.py + migration 0004: id + mixin models for the 26 stub
  entities so each can carry a policy. Migration uses a literal table list.
- ypms/models.py: single import-all module used by Alembic env, the job,
  and the test fixtures.
- Drift guard: test upgrades a scratch SQLite DB to head and compares to
  Base.metadata. Found pre-existing drift in 0002 (named unique
  constraints duplicating the unique indexes on roles.code, users.username,
  users.email); allow-listed, follow-up noted in PHASE0_STATUS.

156 tests passing; ruff + mypy clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 09:41:46 -04:00

74 lines
2.0 KiB
Python

"""Stub entity tables — id + framework mixin columns only.
Revision ID: 0004_stub_entity_tables
Revises: 0003_registrants
Create Date: 2026-10-01
Milestone 0.7. One table per Phase 0 stub entity (`src/ypms/stub_models.py`)
so every entity can carry a retention policy. Domain phases add columns in new
revisions; table names are stable.
The table list is a literal on purpose — migrations must not import app code,
or a later rename would silently rewrite history.
Per repo rule (CONTRIBUTING.md): this file is immutable once merged.
"""
from __future__ import annotations
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
revision: str = "0004_stub_entity_tables"
down_revision: str | Sequence[str] | None = "0003_registrants"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
TABLES: tuple[str, ...] = (
"guardians",
"consent_records",
"hosts",
"host_contacts",
"worksites",
"positions",
"job_postings",
"programs",
"cohorts",
"eligibility_rules",
"applications",
"eligibility_decisions",
"certifications",
"orientations",
"enrollments",
"time_entries",
"timesheets",
"payroll_batches",
"tax_documents",
"transportation_vouchers",
"attachments",
"notes",
"integration_events",
"notifications",
"education_records",
"foster_indicators",
)
def upgrade() -> None:
for table in TABLES:
op.create_table(
table,
sa.Column("id", sa.Integer(), primary_key=True),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
sa.Column("deleted_at", sa.DateTime(timezone=True), nullable=True),
sa.Column("version", sa.Integer(), nullable=False, server_default=sa.text("1")),
)
def downgrade() -> None:
for table in reversed(TABLES):
op.drop_table(table)