Coverage for watcher/db/sqlalchemy/alembic/versions/0f6042416884_add_apscheduler_jobs.py: 84%
17 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-17 12:22 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-17 12:22 +0000
1"""Add apscheduler_jobs table to store background jobs
3Revision ID: 0f6042416884
4Revises: 001
5Create Date: 2017-03-24 11:21:29.036532
7"""
8from alembic import op
9from sqlalchemy import inspect
10import sqlalchemy as sa
12from watcher.db.sqlalchemy import models
14# revision identifiers, used by Alembic.
15revision = '0f6042416884'
16down_revision = '001'
18def _table_exists(table_name):
19 bind = op.get_context().bind
20 insp = inspect(bind)
21 names = insp.get_table_names()
22 return any(t == table_name for t in names)
25def upgrade():
26 if _table_exists('apscheduler_jobs'): 26 ↛ 27line 26 didn't jump to line 27 because the condition on line 26 was never true
27 return
29 op.create_table(
30 'apscheduler_jobs',
31 sa.Column('id', sa.Unicode(191),
32 nullable=False),
33 sa.Column('next_run_time', sa.Float(25), index=True),
34 sa.Column('job_state', sa.LargeBinary, nullable=False),
35 sa.Column('service_id', sa.Integer(), nullable=False),
36 sa.Column('tag', models.JSONEncodedDict(), nullable=True),
37 sa.PrimaryKeyConstraint('id'),
38 sa.ForeignKeyConstraint(['service_id'], ['services.id'])
39 )
42def downgrade():
43 op.drop_table('apscheduler_jobs')