Add quay releases
This commit is contained in:
parent
666907f03e
commit
386c017d99
9 changed files with 174 additions and 3 deletions
|
@ -1,8 +1,11 @@
|
|||
from __future__ import with_statement
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from alembic import context
|
||||
from alembic.revision import ResolutionError
|
||||
from alembic.util import CommandError
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
from logging.config import fileConfig
|
||||
from urllib import unquote, quote
|
||||
|
@ -11,6 +14,7 @@ from peewee import SqliteDatabase
|
|||
from data.database import all_models, db
|
||||
from app import app
|
||||
from data.model.sqlalchemybridge import gen_sqlalchemy_metadata
|
||||
from release import GIT_HEAD, REGION, SERVICE
|
||||
from util.morecollections import AttrDict
|
||||
|
||||
config = context.config
|
||||
|
@ -21,6 +25,8 @@ config.set_main_option('sqlalchemy.url', unquote(app.config['DB_URI']))
|
|||
if config.config_file_name:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
|
@ -77,7 +83,23 @@ def run_migrations_online():
|
|||
|
||||
try:
|
||||
with context.begin_transaction():
|
||||
context.run_migrations(tables=tables)
|
||||
try:
|
||||
context.run_migrations(tables=tables)
|
||||
except (CommandError, ResolutionError) as ex:
|
||||
if 'No such revision' not in str(ex):
|
||||
raise
|
||||
|
||||
if not REGION or not GIT_HEAD:
|
||||
raise
|
||||
|
||||
from data.model.release import get_recent_releases
|
||||
|
||||
# ignore revision error if we're running the previous release
|
||||
releases = list(get_recent_releases(SERVICE, REGION).offset(1).limit(1))
|
||||
if releases and releases[0].version == GIT_HEAD:
|
||||
logger.warn('Skipping database migration because revision not found')
|
||||
else:
|
||||
raise
|
||||
finally:
|
||||
connection.close()
|
||||
|
||||
|
|
Reference in a new issue