Ejemplo n.º 1
0
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 = engine_from_config(config.get_section(
        config.config_ini_section),
                                     prefix='sqlalchemy.',
                                     poolclass=pool.NullPool)

    # we can get the table prefix via the tag object
    tag = context.get_tag_argument()
    if tag and isinstance(tag, dict):
        table_prefix = tag.get('table_prefix', '')
    else:
        table_prefix = ''

    with connectable.connect() as connection:
        context.configure(connection=connection,
                          target_metadata=target_metadata,
                          version_table=table_prefix + 'alembic_version')

        with context.begin_transaction():
            context.run_migrations(table_prefix=table_prefix)
Ejemplo n.º 2
0
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 = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)

    # we can get the table prefix via the tag object
    tag = context.get_tag_argument()
    if tag and isinstance(tag, dict):
        table_prefix = tag.get('table_prefix', '')
    else:
        table_prefix = ''

    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata,
            version_table=table_prefix + 'alembic_version'
        )

        with context.begin_transaction():
            context.run_migrations(table_prefix=table_prefix)
Ejemplo n.º 3
0
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.

    """
    tag = context.get_tag_argument()
    db_url = config.get_section(tag)
    #url = config.get_main_option("sqlalchemy.url")
    context.configure(
        url=db_url, target_metadata=target_metadata, literal_binds=True)

    with context.begin_transaction():
        context.run_migrations()
Ejemplo n.º 4
0
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.

    """
    tag = context.get_tag_argument()
    connectable = engine_from_config(
        config.get_section(tag),
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)

    with connectable.connect() as connection:
        context.configure(
            connection=connection,
            target_metadata=target_metadata
        )

        with context.begin_transaction():
            context.run_migrations()
Ejemplo n.º 5
0
from __future__ import with_statement
import sys
import os
import argparse
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig

sys.path.append(os.path.dirname(os.path.abspath(__file__ + '/..')))

from pajbot.bot import Bot
from pajbot.tbutil import load_config

tag = context.get_tag_argument()

parser = argparse.ArgumentParser()
parser.add_argument('--config',
                    '-c',
                    default='config.ini',
                    help='Specify which config file to use '
                    '(default: config.ini)')
custom_args = None
if tag is not None:
    custom_args = tag.replace('"', '').split()
args, unknown = parser.parse_known_args(args=custom_args)

print('Loading config from {0}'.format(args.config))
tb_config = load_config(args.config)

from pajbot.models.db import Base
# from pajbot.models.user import User
Ejemplo n.º 6
0
import os
import argparse
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig


sys.path.append(os.path.dirname(os.path.abspath(__file__ + '/..')))

from pajbot.bot import Bot
from pajbot.tbutil import load_config
from pajbot.models.webcontent import WebContent
from pajbot.modules import PredictModule
import pajbot.models.hsbet

tag = context.get_tag_argument()

parser = argparse.ArgumentParser()
parser.add_argument('--config', '-c',
                    default='config.ini',
                    help='Specify which config file to use '
                            '(default: config.ini)')
custom_args = None
if tag is not None:
    custom_args = tag.replace('"', '').split()
args, unknown = parser.parse_known_args(args=custom_args)

print('Loading config from {0}'.format(args.config))
tb_config = load_config(args.config)

from pajbot.models.db import Base
Ejemplo n.º 7
0
from __future__ import with_statement
import json
import sys
from alembic import context

from logging.config import fileConfig

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
alembic_config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(alembic_config.config_file_name)

# If alembic was invoked with --tag=test, override these main config values
if context.get_tag_argument() == 'test':
    from inbox.config import config
    with open('../etc/config-test.json') as f:
        config.update(json.load(f))
        if not config.get('MYSQL_HOSTNAME') == "localhost":
            sys.exit("Tests should only be run on localhost DB!")


# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
from inbox.models.base import MailSyncBase
target_metadata = MailSyncBase.metadata

from inbox.ignition import main_engine
Ejemplo n.º 8
0
# add your model's MetaData object here
# for 'autogenerate' support
target_metadata = models.Base.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.

# support for passing database URL on the command line
# usage:  alembic -x db_url=postgresql://localhost/orcmdb upgrade head
cmd_line_url = context.get_x_argument(as_dictionary=True).get('db_url')
# support passing database URL as tag in upgrade() function call.
# usage:  command.upgrade(Config(alembic_ini), "head", tag=db_url)
tag_url = context.get_tag_argument()

missing_db_url_msg = ("Please set the database connection string in "
                      "either 'PG_DB_URL' environment variable or specify "
                      "it in the schema_migration config file under "
                      "'sqlalchemy.url'.\nConnection string pattern:\n"
                      "postgresql[+<driver>://[<username>[:<password>]]"
                      "@<server>[:<port>]/<database>\n\n"
                      "http://docs.sqlalchemy.org/en/latest/core/"
                      "engines.html#database-urls")

DB_URL_ENVIRONMENT_VAR = 'PG_DB_URL'

def run_migrations_offline():
    """Run migrations in 'offline' mode.
Ejemplo n.º 9
0
Archivo: env.py Proyecto: caitp/inbox
from logging.config import fileConfig

from inbox.server.config import load_config

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)

# If alembic was invoked with --tag=test, load the test Inbox config. Otherwise
# load the default config.
if context.get_tag_argument() == 'test':
    load_config('tests/config.cfg')
else:
    load_config()

from inbox.server.models.tables.base import register_backends
table_mod_for = register_backends()

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
from inbox.server.models import Base
target_metadata = Base.metadata

from inbox.server.models.ignition import db_uri
Ejemplo n.º 10
0
# add your model's MetaData object here
# for 'autogenerate' support
target_metadata = models.Base.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.

# support for passing database URL on the command line
# usage:  alembic -x db_url=postgresql://localhost/orcmdb upgrade head
cmd_line_url = context.get_x_argument(as_dictionary=True).get('db_url')
# support passing database URL as tag in upgrade() function call.
# usage:  command.upgrade(Config(alembic_ini), "head", tag=db_url)
tag_url = context.get_tag_argument()

missing_db_url_msg = ("Please set the database connection string in "
                      "either 'PG_DB_URL' environment variable or specify "
                      "it in the schema_migration config file under "
                      "'sqlalchemy.url'.\nConnection string pattern:\n"
                      "postgresql[+<driver>://[<username>[:<password>]]"
                      "@<server>[:<port>]/<database>\n\n"
                      "http://docs.sqlalchemy.org/en/latest/core/"
                      "engines.html#database-urls")

DB_URL_ENVIRONMENT_VAR = 'PG_DB_URL'


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