/ migrations / versions / 045_routine_execution_log.py
045_routine_execution_log.py
 1  """Per-fire execution log for project routines.
 2  
 3  Keeps a historical row per routine fire so admins can debug flaky
 4  routines beyond the single-string `last_result` on
 5  ``project_routines``. Populated by ``crons/routines.py`` on every run
 6  and by the admin-triggered `/retry` endpoint.
 7  """
 8  import sqlalchemy as sa
 9  from alembic import op
10  
11  
12  revision = '045'
13  down_revision = '044'
14  branch_labels = None
15  depends_on = None
16  
17  
18  def upgrade():
19      try:
20          op.create_table(
21              'routine_execution_log',
22              sa.Column('id', sa.Integer(), primary_key=True, index=True),
23              sa.Column('routine_id', sa.Integer(), sa.ForeignKey('project_routines.id', ondelete='CASCADE'), nullable=False, index=True),
24              sa.Column('project_id', sa.Integer(), sa.ForeignKey('projects.id', ondelete='CASCADE'), nullable=False, index=True),
25              sa.Column('status', sa.String(16), nullable=False, server_default='ok'),
26              sa.Column('result', sa.Text(), nullable=True),
27              sa.Column('duration_ms', sa.Integer(), nullable=True),
28              sa.Column('manual', sa.Boolean(), nullable=False, server_default=sa.false()),
29              sa.Column('created_at', sa.DateTime(), nullable=False, index=True),
30          )
31      except Exception:
32          pass
33  
34  
35  def downgrade():
36      try:
37          op.drop_table('routine_execution_log')
38      except Exception:
39          pass