Exemplo n.º 1
0
def build_database(echo=True, tests=False):
    """ Applies the schema to the database. Run this command once to build the database. """
    engine = session.get_engine(echo=echo)
    models.register_models(engine)

    # Put the database under version control
    alembic_cfg = Config(config_get('alembic', 'cfg'))
    command.stamp(alembic_cfg, "head")
Exemplo n.º 2
0
def build_database():
    """ Applies the schema to the database. Run this command once to build the database. """
    engine = get_engine()

    schema = config_get('database', 'schema', raise_exception=False, check_config_table=False)
    if schema:
        print('Schema set in config, trying to create schema:', schema)
        try:
            engine.execute(CreateSchema(schema))
        except Exception as e:
            print('Cannot create schema, please validate manually if schema creation is needed, continuing:', e)

    models.register_models(engine)

    # Put the database under version control
    alembic_cfg = Config(config_get('alembic', 'cfg'))
    command.stamp(alembic_cfg, "head")
Exemplo n.º 3
0
def init_rucio_database(echo=True, tests=False):
    """ Applies the schema to the database. Run this command once to build the database. """

    rucio_cfg_file = os.environ["RUCIO_HOME"]+"/etc/rucio.cfg"
    alembic_cfg_file = os.environ["RUCIO_HOME"]+"/etc/alembic.ini"
    alembic_script_location = os.environ["RUCIO_HOME"]+"/rucio/db/sqla/migrate_repo"

    # Apply database schema to the provided endpoint
    print("Rucio configuration file: ", rucio_cfg_file)
    print("Alembic.ini configuration file: ", alembic_cfg_file)
    print("Applying the Rucio database schema to database endpoint: "+config_get('database', 'default')+"... ", end='', flush=True)
    engine = get_temp_engine(echo=echo)
    register_models(engine)
    print("done")

    # Put the database under version control
    print("Stamping databse version in alembic... ", end='', flush=True)
    alembic_cfg = AlConfig(alembic_cfg_file)
    alembic_cfg.set_main_option("script_location", alembic_script_location)
    command.stamp(alembic_cfg, "head")
    print("done")
Exemplo n.º 4
0
def dump_schema():
    """ Creates a schema dump to a specific database. """
    engine = get_dump_engine()
    models.register_models(engine)