USA News — DB migrations¶
Ordered, incremental SQL deltas for the USA News schema and stored procedures.
Model¶
../ddl.sqland../sp_only.sqlare the current full state (source of truth) — they always reflect the schema/SPs as they should look after every migration here has been applied.- This folder holds the ordered deltas needed to bring an existing database from a previous state up to that current state.
When you change the schema or an SP: edit ddl.sql / sp_only.sql (full state) and add a numbered migration here with just the delta.
Conventions¶
- Files are named
NNNN_description.sqland must be applied in ascending order. - There is no migration framework: apply each file manually (e.g.
mysql ... < 0001_no_category_default.sql) and track what you have already run. - Migrations are written to be idempotent / safe to re-run where practical (SPs via
DROP+CREATE, inserts viaINSERT IGNORE, index adds guarded against duplicates, backfills guarded byWHERE NOT EXISTS/IS NULL). DEFINERis`admin`@`%`(production user), matchingsp_only.sql. Adjust if your environment differs.
Migrations¶
| File | What it does |
|---|---|
0001_no_category_default.sql |
Adds the no-category category, updates sp_usanews_upsert_post_full to default both the category list and primary_category_id to no-category when none is provided, and backfills existing posts. |
0002_usanews_ctr_map_and_index.sql |
Adds sp_usanews_get_ctr_map (CTR aggregation for the chronological list min_ctr filter) and a covering index on usanews_notifications_metrics for the CTR aggregations. |