# Path: dockci/server.py
# APP = Flask(__name__)
# 
# def app_init():
#     """
#     Pre-run app setup
#     """
#     app_init_rollbar()
# 
#     logger = logging.getLogger('dockci.init')
# 
#     logger.info("Loading app config")
# 
#     APP.secret_key = CONFIG.secret
# 
#     APP.config['BUNDLE_ERRORS'] = True
# 
#     APP.config['MAIL_SERVER'] = CONFIG.mail_server
#     APP.config['MAIL_PORT'] = CONFIG.mail_port
#     APP.config['MAIL_USE_TLS'] = CONFIG.mail_use_tls
#     APP.config['MAIL_USE_SSL'] = CONFIG.mail_use_ssl
#     APP.config['MAIL_USERNAME'] = CONFIG.mail_username
#     APP.config['MAIL_PASSWORD'] = CONFIG.mail_password
#     APP.config['MAIL_DEFAULT_SENDER'] = CONFIG.mail_default_sender
# 
#     APP.config['SECURITY_PASSWORD_HASH'] = 'bcrypt'
#     APP.config['SECURITY_PASSWORD_SALT'] = CONFIG.security_password_salt
#     APP.config['SECURITY_REGISTERABLE'] = CONFIG.security_registerable_form
#     APP.config['SECURITY_RECOVERABLE'] = CONFIG.security_recoverable
#     APP.config['SECURITY_CHANGEABLE'] = True
#     APP.config['SECURITY_EMAIL_SENDER'] = CONFIG.mail_default_sender
#     APP.config['REMEMBER_COOKIE_NAME'] = 'dockci_remember_me'
#     APP.config['SESSION_COOKIE_NAME'] = 'dockci_session'
# 
#     APP.config['RABBITMQ_USER'] = os.environ.get(
#         'RABBITMQ_ENV_BACKEND_USER', 'guest')
#     APP.config['RABBITMQ_PASSWORD'] = os.environ.get(
#         'RABBITMQ_ENV_BACKEND_PASSWORD', 'guest')
#     APP.config['RABBITMQ_HOST'] = os.environ.get(
#         'RABBITMQ_PORT_5672_TCP_ADDR', 'localhost')
#     APP.config['RABBITMQ_PORT'] = int(os.environ.get(
#         'RABBITMQ_PORT_5672_TCP_PORT', 5672))
# 
#     APP.config['RABBITMQ_USER_FE'] = os.environ.get(
#         'RABBITMQ_ENV_FRONTEND_USER', 'guest')
#     APP.config['RABBITMQ_PASSWORD_FE'] = os.environ.get(
#         'RABBITMQ_ENV_FRONTEND_PASSWORD', 'guest')
# 
#     APP.config['REDIS_HOST'] = os.environ.get(
#         'REDIS_PORT_6379_TCP_ADDR', 'redis')
#     APP.config['REDIS_PORT'] = int(os.environ.get(
#         'REDIS_PORT_6379_TCP_PORT', 6379))
# 
#     if APP.config.get('SQLALCHEMY_DATABASE_URI', None) is None:
#         APP.config['SQLALCHEMY_DATABASE_URI'] = get_db_uri()
# 
#     mimetypes.add_type('application/x-yaml', 'yaml')
# 
#     from .forms import (ChangePasswordForm,
#                         ForgotPasswordForm,
#                         LoginForm,
#                         RegisterForm,
#                         ResetPasswordForm)
#     from .models.auth import DockciUserDatastore, User, Role
#     from .models.job import Job  # pylint:disable=unused-variable
#     from .models.project import Project  # pylint:disable=unused-variable
# 
#     if 'security' not in APP.blueprints:
#         SECURITY.init_app(
#             APP,
#             datastore=DockciUserDatastore(DB, User, Role),
#             login_form=LoginForm,
#             register_form=RegisterForm,
#             forgot_password_form=ForgotPasswordForm,
#             reset_password_form=ResetPasswordForm,
#             change_password_form=ChangePasswordForm,
#         )
# 
#     MAIL.init_app(APP)
#     DB.init_app(APP)
# 
#     if TOOLBAR is not None:
#         logging.warning('Debug initialized. Enabled: %s', APP.debug)
#         TOOLBAR.init_app(APP)
# 
#     app_init_oauth()
#     app_init_handlers()
#     app_init_api()
#     app_init_views()
# 
# DB = WrappedSQLAlchemy()


from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
from dockci.server import APP, app_init, DB
from dockci.models.auth import *
from dockci.models.job import *
from dockci.models.project import *
# ... etc.


def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = APP.config['SQLALCHEMY_DATABASE_URI']
    context.configure(
        url=url, target_metadata=target_metadata, literal_binds=True)

    with context.begin_transaction():
        context.run_migrations()


def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

# Path: dockci/server.py
# APP = Flask(__name__)
# 
# def app_init():
#     """
#     Pre-run app setup
#     """
#     app_init_rollbar()
# 
#     logger = logging.getLogger('dockci.init')
# 
#     logger.info("Loading app config")
# 
#     APP.secret_key = CONFIG.secret
# 
#     APP.config['BUNDLE_ERRORS'] = True
# 
#     APP.config['MAIL_SERVER'] = CONFIG.mail_server
#     APP.config['MAIL_PORT'] = CONFIG.mail_port
#     APP.config['MAIL_USE_TLS'] = CONFIG.mail_use_tls
#     APP.config['MAIL_USE_SSL'] = CONFIG.mail_use_ssl
#     APP.config['MAIL_USERNAME'] = CONFIG.mail_username
#     APP.config['MAIL_PASSWORD'] = CONFIG.mail_password
#     APP.config['MAIL_DEFAULT_SENDER'] = CONFIG.mail_default_sender
# 
#     APP.config['SECURITY_PASSWORD_HASH'] = 'bcrypt'
#     APP.config['SECURITY_PASSWORD_SALT'] = CONFIG.security_password_salt
#     APP.config['SECURITY_REGISTERABLE'] = CONFIG.security_registerable_form
#     APP.config['SECURITY_RECOVERABLE'] = CONFIG.security_recoverable
#     APP.config['SECURITY_CHANGEABLE'] = True
#     APP.config['SECURITY_EMAIL_SENDER'] = CONFIG.mail_default_sender
#     APP.config['REMEMBER_COOKIE_NAME'] = 'dockci_remember_me'
#     APP.config['SESSION_COOKIE_NAME'] = 'dockci_session'
# 
#     APP.config['RABBITMQ_USER'] = os.environ.get(
#         'RABBITMQ_ENV_BACKEND_USER', 'guest')
#     APP.config['RABBITMQ_PASSWORD'] = os.environ.get(
#         'RABBITMQ_ENV_BACKEND_PASSWORD', 'guest')
#     APP.config['RABBITMQ_HOST'] = os.environ.get(
#         'RABBITMQ_PORT_5672_TCP_ADDR', 'localhost')
#     APP.config['RABBITMQ_PORT'] = int(os.environ.get(
#         'RABBITMQ_PORT_5672_TCP_PORT', 5672))
# 
#     APP.config['RABBITMQ_USER_FE'] = os.environ.get(
#         'RABBITMQ_ENV_FRONTEND_USER', 'guest')
#     APP.config['RABBITMQ_PASSWORD_FE'] = os.environ.get(
#         'RABBITMQ_ENV_FRONTEND_PASSWORD', 'guest')
# 
#     APP.config['REDIS_HOST'] = os.environ.get(
#         'REDIS_PORT_6379_TCP_ADDR', 'redis')
#     APP.config['REDIS_PORT'] = int(os.environ.get(
#         'REDIS_PORT_6379_TCP_PORT', 6379))
# 
#     if APP.config.get('SQLALCHEMY_DATABASE_URI', None) is None:
#         APP.config['SQLALCHEMY_DATABASE_URI'] = get_db_uri()
# 
#     mimetypes.add_type('application/x-yaml', 'yaml')
# 
#     from .forms import (ChangePasswordForm,
#                         ForgotPasswordForm,
#                         LoginForm,
#                         RegisterForm,
#                         ResetPasswordForm)
#     from .models.auth import DockciUserDatastore, User, Role
#     from .models.job import Job  # pylint:disable=unused-variable
#     from .models.project import Project  # pylint:disable=unused-variable
# 
#     if 'security' not in APP.blueprints:
#         SECURITY.init_app(
#             APP,
#             datastore=DockciUserDatastore(DB, User, Role),
#             login_form=LoginForm,
#             register_form=RegisterForm,
#             forgot_password_form=ForgotPasswordForm,
#             reset_password_form=ResetPasswordForm,
#             change_password_form=ChangePasswordForm,
#         )
# 
#     MAIL.init_app(APP)
#     DB.init_app(APP)
# 
#     if TOOLBAR is not None:
#         logging.warning('Debug initialized. Enabled: %s', APP.debug)
#         TOOLBAR.init_app(APP)
# 
#     app_init_oauth()
#     app_init_handlers()
#     app_init_api()
#     app_init_views()
# 
# DB = WrappedSQLAlchemy()


# Path: alembic/env.py
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
from dockci.server import APP, app_init, DB
from dockci.models.auth import *
from dockci.models.job import *
from dockci.models.project import *

# ... etc.


def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    url = APP.config['SQLALCHEMY_DATABASE_URI']
    context.configure(
        url=url, target_metadata=target_metadata, literal_binds=True)

    with context.begin_transaction():
        context.run_migrations()


def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """

    connectable = DB.engine