コード例 #1
0
ファイル: env.py プロジェクト: pmontagnier/irma-frontend
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.

    """
    global URL
    conf = config.get_section(config.config_ini_section)
    conf["sqlalchemy.url"] = get_sql_url()
    print(conf)
    connectable = engine_from_config(
        conf,
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)

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

        with context.begin_transaction():
            context.run_migrations()
コード例 #2
0
ファイル: env.py プロジェクト: pmontagnier/irma-frontend
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.

    """
    context.configure(
        url=get_sql_url(),
        target_metadata=target_metadata,
        literal_binds=True,
        compare_type=True)

    with context.begin_transaction():
        context.run_migrations()
コード例 #3
0
ファイル: create_user.py プロジェクト: vaginessa/irma
dirname = os.path.dirname(db_name)
if not os.path.exists(dirname):
    print("SQL directory does not exist {0}" "..creating".format(dirname))
    os.makedirs(dirname)
    os.chmod(dirname, 0o777)
elif not (os.path.isdir(dirname)):
    print("Error. SQL directory is a not a dir {0}" "".format(dirname))
    raise IrmaDatabaseError("Can not create Brain database dir")

if not os.path.exists(db_name):
    # touch like method to create a rw-rw-rw- file for db
    open(db_name, 'a').close()
    os.chmod(db_name, 0o666)

# Retrieve database informations
url = config.get_sql_url()
engine = create_engine(url, echo=config.sql_debug_enabled())
# and create Database in case
Base.metadata.create_all(engine)

with session_transaction() as session:
    try:
        user = User.get_by_rmqvhost(session, rmqvhost=rmqvhost)
        print("rmqvhost {0} is already assigned to user {1}. "
              "Updating with new parameters.".format(user.name, user.rmqvhost))
        user = user.load(user.id, session)
        user.name = name
        user.ftpuser = ftpuser
        user.update(['name', 'ftpuser'], session)
    except IrmaDatabaseResultNotFound:
        user = User(name=name, rmqvhost=rmqvhost, ftpuser=ftpuser)
コード例 #4
0
import sys
sys.path.append(".")

from config.parser import get_sql_url
from api.common.models import Base
import api.files.models
import api.files_ext.models
import api.scans.models
import api.tags.models
target_metadata = 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.
url = get_sql_url()


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.

    """
    context.configure(
コード例 #5
0
ファイル: create_user.py プロジェクト: deloittem/irma-brain
    print("SQL directory does not exist {0}"
          "..creating".format(dirname))
    os.makedirs(dirname)
    os.chmod(dirname, 0777)
elif not (os.path.isdir(dirname)):
    print("Error. SQL directory is a not a dir {0}"
          "".format(dirname))
    raise IrmaDatabaseError("Can not create Brain database dir")

if not os.path.exists(db_name):
    # touch like method to create a rw-rw-rw- file for db
    open(db_name, 'a').close()
    os.chmod(db_name, 0666)

# Retrieve database informations
url = config.get_sql_url()
engine = create_engine(url, echo=config.sql_debug_enabled())
# and create Database in case
Base.metadata.create_all(engine)

with session_transaction() as session:
    try:
        user = User.get_by_rmqvhost(session, rmqvhost=rmqvhost)
        print("rmqvhost {0} is already assigned to user {1}. "
              "Updating with new parameters.".format(user.name, user.rmqvhost))
        user = user.load(user.id, session)
        user.name = name
        user.ftpuser = ftpuser
        user.update(['name', 'ftpuser'], session)
    except IrmaDatabaseResultNotFound:
        user = User(name=name, rmqvhost=rmqvhost, ftpuser=ftpuser)