fix(migrations): dropping the demo also takes its reset job's interval-change audit rows
0098 deleted the reset job's run rows but not the scheduler_interval rows that changing its interval wrote; with the job's label gone they rendered as a raw id. The delete now takes every job-targeted row for it, and a test seeds both kinds below 0098 and upgrades (red on the old filter). The test has its own file so the removed-features guard can name it.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""Migration 0098's data cleanup, DB-lane.
|
||||
|
||||
The schema half of every migration is checked by test_migrations.py; this one also deletes rows, and
|
||||
a delete that misses a row is invisible there. Its own file so the removed-features guard can name it.
|
||||
"""
|
||||
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.db import engine
|
||||
|
||||
|
||||
def test_dropping_the_demo_takes_every_audit_row_about_its_reset_job(db):
|
||||
# The reset job's interval could be changed from the scheduler page like any job's; once its
|
||||
# name is gone from the UI, a left-behind row would render as a raw job id.
|
||||
cfg = Config("alembic.ini")
|
||||
command.downgrade(cfg, "0097_drop_messages")
|
||||
try:
|
||||
with engine.begin() as conn:
|
||||
conn.execute(
|
||||
text(
|
||||
"INSERT INTO audit_log (action, target_type, target_id, created_at) VALUES"
|
||||
" ('job_run', 'job', 'demo_reset', now()),"
|
||||
" ('scheduler_interval', 'job', 'demo_reset', now()),"
|
||||
" ('scheduler_interval', 'job', 'sync_feed', now())"
|
||||
)
|
||||
)
|
||||
finally:
|
||||
command.upgrade(cfg, "head")
|
||||
with engine.connect() as conn:
|
||||
left = conn.execute(
|
||||
text("SELECT action, target_id FROM audit_log WHERE target_type = 'job' ORDER BY id")
|
||||
).all()
|
||||
assert [tuple(r) for r in left] == [("scheduler_interval", "sync_feed")]
|
||||
Reference in New Issue
Block a user