From b57eac12cbe12ab42a166f32fe596b6c7322e6db Mon Sep 17 00:00:00 2001 From: chenker Date: Thu, 28 Apr 2022 02:16:32 +0000 Subject: [PATCH] Watcher DB upgrde compatibility consideration for add_apscheduler_jobs Change-Id: I8896ff5731bb8c1bf88a5d7b926bd2a884100ea8 --- .../versions/0f6042416884_add_apscheduler_jobs.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/watcher/db/sqlalchemy/alembic/versions/0f6042416884_add_apscheduler_jobs.py b/watcher/db/sqlalchemy/alembic/versions/0f6042416884_add_apscheduler_jobs.py index 56f4c8cd8..5f2854313 100644 --- a/watcher/db/sqlalchemy/alembic/versions/0f6042416884_add_apscheduler_jobs.py +++ b/watcher/db/sqlalchemy/alembic/versions/0f6042416884_add_apscheduler_jobs.py @@ -6,6 +6,7 @@ Create Date: 2017-03-24 11:21:29.036532 """ from alembic import op +from sqlalchemy import inspect import sqlalchemy as sa from watcher.db.sqlalchemy import models @@ -14,8 +15,17 @@ from watcher.db.sqlalchemy import models revision = '0f6042416884' down_revision = '001' +def _table_exists(table_name): + bind = op.get_context().bind + insp = inspect(bind) + names = insp.get_table_names() + return any(t == table_name for t in names) + def upgrade(): + if _table_exists('apscheduler_jobs'): + return + op.create_table( 'apscheduler_jobs', sa.Column('id', sa.Unicode(191, _warn_on_bytestring=False),