當前位置: 首頁>>代碼示例>>Python>>正文


Python ScriptDirectory.from_config方法代碼示例

本文整理匯總了Python中alembic.script.ScriptDirectory.from_config方法的典型用法代碼示例。如果您正苦於以下問題:Python ScriptDirectory.from_config方法的具體用法?Python ScriptDirectory.from_config怎麽用?Python ScriptDirectory.from_config使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在alembic.script.ScriptDirectory的用法示例。


在下文中一共展示了ScriptDirectory.from_config方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: check_migrations

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def check_migrations(timeout):
    """
    Function to wait for all airflow migrations to complete.
    @param timeout:
    @return:
    """
    from alembic.runtime.migration import MigrationContext
    from alembic.script import ScriptDirectory

    config = _get_alembic_config()
    script_ = ScriptDirectory.from_config(config)
    with settings.engine.connect() as connection:
        context = MigrationContext.configure(connection)
        ticker = 0
        while True:
            source_heads = set(script_.get_heads())
            db_heads = set(context.get_current_heads())
            if source_heads == db_heads:
                break
            if ticker >= timeout:
                raise TimeoutError("There are still unapplied migrations after {} "
                                   "seconds.".format(ticker))
            ticker += 1
            time.sleep(1)
            log.info('Waiting for migrations... %s second(s)', ticker) 
開發者ID:apache,項目名稱:airflow,代碼行數:27,代碼來源:db.py

示例2: test_env_emits_warning

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def test_env_emits_warning(self):
        msg = (
            "File %s loaded twice! ignoring. "
            "Please ensure version_locations is unique."
            % (
                os.path.realpath(
                    os.path.join(
                        _get_staging_directory(),
                        "model1",
                        "%s_model1.py" % self.model1,
                    )
                )
            )
        )
        with assertions.expect_warnings(msg, regex=False):
            script = ScriptDirectory.from_config(self.cfg)
            script.revision_map.heads
            eq_(
                [rev.revision for rev in script.walk_revisions()],
                [self.model1, self.model2, self.model3],
            ) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:23,代碼來源:test_script_production.py

示例3: test_script_location_muliple

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def test_script_location_muliple(self):
        config = _multi_dir_testing_config()

        script = ScriptDirectory.from_config(config)

        def normpath(path):
            return path.replace("/", ":NORM:")

        normpath = mock.Mock(side_effect=normpath)

        with mock.patch("os.path.normpath", normpath):
            eq_(
                script._version_locations,
                [
                    os.path.abspath(
                        os.path.join(_get_staging_directory(), "model1/")
                    ).replace("/", ":NORM:"),
                    os.path.abspath(
                        os.path.join(_get_staging_directory(), "model2/")
                    ).replace("/", ":NORM:"),
                    os.path.abspath(
                        os.path.join(_get_staging_directory(), "model3/")
                    ).replace("/", ":NORM:"),
                ],
            ) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:27,代碼來源:test_script_production.py

示例4: create

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def create(force=False):
    """Create tables if the database has not been configured yet."""
    # Fail if there's an alembic version set
    engine = db.get_engine(flask.current_app)
    conn = engine.connect()
    context = MigrationContext.configure(conn)
    current_rev = context.get_current_revision()
    alembic_config = flask.current_app.extensions['migrate'].migrate.get_config(
            directory=migrate_path)
    script = ScriptDirectory.from_config(alembic_config)
    latest_rev = script.get_current_head()
    if current_rev == latest_rev and not force:
        print(u"You need to run 'evesrp -c config.py db migrate' to "
              u"migrate to the latest database schema.")
    else:
        db.create_all()
        if current_rev is None:
            stamp() 
開發者ID:paxswill,項目名稱:evesrp,代碼行數:20,代碼來源:manage.py

示例5: run_alembic_migration

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def run_alembic_migration(db_uri, log_handler=None, setup_app=True):
    if log_handler:
        logging.getLogger(migration_name).addHandler(log_handler)

    config = Config()
    config.set_main_option("script_location", "data:migrations")
    config.set_main_option("db_uri", db_uri)

    if setup_app:
        config.set_main_option("alembic_setup_app", "True")
    else:
        config.set_main_option("alembic_setup_app", "")

    script = ScriptDirectory.from_config(config)

    def fn(rev, context):
        return script._upgrade_revs("head", rev)

    with EnvironmentContext(config, script, fn=fn, destination_rev="head"):
        script.run_env() 
開發者ID:quay,項目名稱:quay,代碼行數:22,代碼來源:runmigration.py

示例6: test_sqlalchemy_store_detects_schema_mismatch

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def test_sqlalchemy_store_detects_schema_mismatch(
        tmpdir, db_url):  # pylint: disable=unused-argument
    def _assert_invalid_schema(engine):
        with pytest.raises(MlflowException) as ex:
            _verify_schema(engine)
            assert ex.message.contains("Detected out-of-date database schema.")

    # Initialize an empty database & verify that we detect a schema mismatch
    engine = sqlalchemy.create_engine(db_url)
    _assert_invalid_schema(engine)
    # Create legacy tables, verify schema is still out of date
    InitialBase.metadata.create_all(engine)
    _assert_invalid_schema(engine)
    # Run each migration. Until the last one, schema should be out of date
    config = _get_alembic_config(db_url)
    script = ScriptDirectory.from_config(config)
    revisions = list(script.walk_revisions())
    revisions.reverse()
    for rev in revisions[:-1]:
        command.upgrade(config, rev.revision)
        _assert_invalid_schema(engine)
    # Run migrations, schema verification should now pass
    invoke_cli_runner(mlflow.db.commands, ['upgrade', db_url])
    _verify_schema(engine) 
開發者ID:mlflow,項目名稱:mlflow,代碼行數:26,代碼來源:test_sqlalchemy_store_schema.py

示例7: show

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def show(cli_ctx, alembic_config):
    '''Show the current schema information.'''
    with cli_ctx.logger:
        alembic_cfg = Config(alembic_config)
        sa_url = alembic_cfg.get_main_option('sqlalchemy.url')
        engine = sa.create_engine(sa_url)
        with engine.begin() as connection:
            context = MigrationContext.configure(connection)
            current_rev = context.get_current_revision()

        script = ScriptDirectory.from_config(alembic_cfg)
        heads = script.get_heads()
        head_rev = heads[0] if len(heads) > 0 else None
        print(f'Current database revision: {current_rev}')
        print(f'The head revision of available migrations: {head_rev}') 
開發者ID:lablup,項目名稱:backend.ai-manager,代碼行數:17,代碼來源:dbschema.py

示例8: configure_db

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def configure_db(app):
    """
    0.10 is the first version of ARA that ships with a stable database schema.
    We can identify a database that originates from before this by checking if
    there is an alembic revision available.
    If there is no alembic revision available, assume we are running the first
    revision which contains the latest state of the database prior to this.
    """
    db.init_app(app)
    log = logging.getLogger(app.logger_name)

    if app.config.get('ARA_AUTOCREATE_DATABASE'):
        with app.app_context():
            migrations = app.config['DB_MIGRATIONS']
            flask_migrate.Migrate(app, db, directory=migrations)
            config = app.extensions['migrate'].migrate.get_config(migrations)

            # Verify if the database tables have been created at all
            inspector = Inspector.from_engine(db.engine)
            if len(inspector.get_table_names()) == 0:
                log.info('Initializing new DB from scratch')
                flask_migrate.upgrade(directory=migrations)

            # Get current alembic head revision
            script = ScriptDirectory.from_config(config)
            head = script.get_current_head()

            # Get current revision, if available
            connection = db.engine.connect()
            context = MigrationContext.configure(connection)
            current = context.get_current_revision()

            if not current:
                log.info('Unstable DB schema, stamping original revision')
                flask_migrate.stamp(directory=migrations,
                                    revision='da9459a1f71c')

            if head != current:
                log.info('DB schema out of date, upgrading')
                flask_migrate.upgrade(directory=migrations) 
開發者ID:dmsimard,項目名稱:ara-archive,代碼行數:42,代碼來源:webapp.py

示例9: from_config

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def from_config(cls, config):
        """Produce a new :class:`.ScriptDirectory` given a :class:`.Config`
        instance.

        The :class:`.Config` need only have the ``script_location`` key
        present.

        """
        script_location = config.get_main_option('script_location')
        if script_location is None:
            raise util.CommandError("No 'script_location' key "
                                    "found in configuration.")
        truncate_slug_length = config.get_main_option("truncate_slug_length")
        if truncate_slug_length is not None:
            truncate_slug_length = int(truncate_slug_length)

        version_locations = config.get_main_option("version_locations")
        if version_locations:
            version_locations = _split_on_space_comma.split(version_locations)
        return ScriptDirectory(
            util.coerce_resource_to_filename(script_location),
            file_template=config.get_main_option(
                'file_template',
                _default_file_template),
            truncate_slug_length=truncate_slug_length,
            sourceless=config.get_main_option("sourceless") == "true",
            output_encoding=config.get_main_option("output_encoding", "utf-8"),
            version_locations=version_locations
        ) 
開發者ID:jpush,項目名稱:jbox,代碼行數:31,代碼來源:base.py

示例10: init_db

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def init_db():
    """
    Initialize the database; call
    :py:meth:`sqlalchemy.schema.MetaData.create_all` on the metadata object.
    """
    logger.debug('Initializing database')
    # import all modules here that might define models so that
    # they will be registered properly on the metadata.  Otherwise
    # you will have to import them first before calling init_db()
    alembic_ini = pkg_resources.resource_filename(
        pkg_resources.Requirement.parse('biweeklybudget'),
        'biweeklybudget/alembic/alembic.ini'
    )
    topdir = os.path.abspath(
        os.path.join(os.path.dirname(alembic_ini), '..', '..')
    )
    logger.debug('Alembic configuration: %s', alembic_ini)
    with in_directory(topdir):
        alembic_config = Config(alembic_ini)
        script = ScriptDirectory.from_config(alembic_config)
        curr_rev = _alembic_get_current_rev(alembic_config, script)
        head_rev = script.get_revision("head").revision
        if curr_rev is None:
            # alembic not initialized at all; stamp with current version
            logger.warning(
                'Alembic not setup; creating all models and stamping'
            )
            logger.debug('Creating all models')
            Base.metadata.create_all(engine)
            command.stamp(alembic_config, "head")
            logger.debug("DB stamped at %s", head_rev)
        elif curr_rev != head_rev:
            logger.warning("Alembic head is %s but this DB is at %s; "
                           "running migrations", head_rev, curr_rev)
            command.upgrade(alembic_config, "head")
            logger.info("Migrations complete")
        else:
            logger.debug('Alembic is at the correct head version (%s)',
                         curr_rev)
    logger.debug('Done initializing DB')
    init_event_listeners(db_session, engine) 
開發者ID:jantman,項目名稱:biweeklybudget,代碼行數:43,代碼來源:db.py

示例11: _get_current_rev

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def _get_current_rev(self, alembic_conf, engine):
        script = ScriptDirectory.from_config(alembic_conf)
        with engine.connect() as conn:
            with EnvironmentContext(alembic_conf, script) as env_context:
                env_context.configure(conn, version_table="alembic_version")
                migration_context = env_context.get_context()
                revision = migration_context.get_current_revision()
        return revision 
開發者ID:jantman,項目名稱:biweeklybudget,代碼行數:10,代碼來源:migration_test_helpers.py

示例12: _rev_list

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def _rev_list(self, alembic_conf):
        script = ScriptDirectory.from_config(alembic_conf)
        revs = []
        for sc in script.walk_revisions(base="base", head="heads"):
            revs.append({
                'down_revision': sc.down_revision,
                'revision': sc.revision,
                'doc': sc.doc
            })
        revs.reverse()
        return revs 
開發者ID:jantman,項目名稱:biweeklybudget,代碼行數:13,代碼來源:migration_test_helpers.py

示例13: test_only_single_head_revision_in_migrations

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def test_only_single_head_revision_in_migrations(self):
        config = Config()
        config.set_main_option("script_location", "airflow:migrations")
        script = ScriptDirectory.from_config(config)

        # This will raise if there are multiple heads
        # To resolve, use the command `alembic merge`
        script.get_current_head() 
開發者ID:apache,項目名稱:airflow,代碼行數:10,代碼來源:test_db.py

示例14: check_current_db_revision

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def check_current_db_revision():
    current_rev = current_db_revision()
    if current_rev is None:
        return False

    config = db.alembic_config
    script = ScriptDirectory.from_config(config)
    module_rev = script.get_current_head()
    if current_rev != module_rev:
        return False

    return True 
開發者ID:chainer,項目名稱:chainerui,代碼行數:14,代碼來源:db_revision.py

示例15: from_config

# 需要導入模塊: from alembic.script import ScriptDirectory [as 別名]
# 或者: from alembic.script.ScriptDirectory import from_config [as 別名]
def from_config(cls, config):
        """Produce a new :class:`.ScriptDirectory` given a :class:`.Config`
        instance.

        The :class:`.Config` need only have the ``script_location`` key
        present.

        """
        script_location = config.get_main_option("script_location")
        if script_location is None:
            raise util.CommandError(
                "No 'script_location' key " "found in configuration."
            )
        truncate_slug_length = config.get_main_option("truncate_slug_length")
        if truncate_slug_length is not None:
            truncate_slug_length = int(truncate_slug_length)

        version_locations = config.get_main_option("version_locations")
        if version_locations:
            version_locations = _split_on_space_comma.split(version_locations)

        return ScriptDirectory(
            util.coerce_resource_to_filename(script_location),
            file_template=config.get_main_option(
                "file_template", _default_file_template
            ),
            truncate_slug_length=truncate_slug_length,
            sourceless=config.get_main_option("sourceless") == "true",
            output_encoding=config.get_main_option("output_encoding", "utf-8"),
            version_locations=version_locations,
            timezone=config.get_main_option("timezone"),
            hook_config=config.get_section("post_write_hooks", {}),
        ) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:35,代碼來源:base.py


注:本文中的alembic.script.ScriptDirectory.from_config方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。