当前位置: 首页>>代码示例>>Python>>正文


Python command.revision方法代码示例

本文整理汇总了Python中alembic.command.revision方法的典型用法代码示例。如果您正苦于以下问题:Python command.revision方法的具体用法?Python command.revision怎么用?Python command.revision使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在alembic.command的用法示例。


在下文中一共展示了command.revision方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [as 别名]
def main(argv=sys.argv):
    if len(argv) < 3:
        usage(argv)
    config_uri = argv[1]
    message = argv[2]
    options = parse_vars(argv[3:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)

    durl = os.environ.get("DATABASE_URL")  # heroku
    if durl:
        settings['sqlalchemy.url'] = durl

    murl = os.environ.get("MEMCACHED_URL")
    if murl:
        settings['urlcache_url'] = murl

    revision(settings, message, options) 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:20,代码来源:generate_revision.py

示例2: _test_005_nextrev

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [as 别名]
def _test_005_nextrev(self):
        script = env.generate_revision(
            def_, "this is the next rev", refresh=True
        )
        assert os.access(
            os.path.join(
                env.dir, "versions", "%s_this_is_the_next_rev.py" % def_
            ),
            os.F_OK,
        )
        eq_(script.revision, def_)
        eq_(script.down_revision, abc)
        eq_(env.get_revision(abc).nextrev, set([def_]))
        assert script.module.down_revision == abc
        assert callable(script.module.upgrade)
        assert callable(script.module.downgrade)
        eq_(env.get_heads(), [def_])
        eq_(env.get_base(), abc) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:20,代码来源:test_script_production.py

示例3: test_renders_added_directives_no_autogen

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [as 别名]
def test_renders_added_directives_no_autogen(self):
        m = sa.MetaData()

        def process_revision_directives(context, rev, generate_revisions):
            generate_revisions[0].upgrade_ops.ops.append(
                ops.CreateIndexOp("some_index", "some_table", ["a", "b"])
            )

        with self._env_fixture(process_revision_directives, m):
            rev = command.revision(
                self.cfg, message="some message", head="model1@head", sql=True
            )

        with mock.patch.object(rev.module, "op") as op_mock:
            rev.module.upgrade()
        eq_(
            op_mock.mock_calls,
            [
                mock.call.create_index(
                    "some_index", "some_table", ["a", "b"], unique=False
                )
            ],
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:25,代码来源:test_script_production.py

示例4: test_multiple_dir_chooses_base

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [as 别名]
def test_multiple_dir_chooses_base(self):
        command.revision(
            self.cfg,
            message="x",
            head="base",
            version_path=os.path.join(_get_staging_directory(), "model1"),
        )

        script2 = command.revision(
            self.cfg,
            message="y",
            head="base",
            version_path=os.path.join(_get_staging_directory(), "model2"),
        )

        script3 = command.revision(
            self.cfg, message="y2", head=script2.revision
        )

        eq_(
            os.path.dirname(script3.path),
            os.path.abspath(os.path.join(_get_staging_directory(), "model2")),
        )
        assert os.access(script3.path, os.F_OK) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:26,代码来源:test_script_production.py

示例5: test_tmpl_args_revision

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [as 别名]
def test_tmpl_args_revision(self):
        env_file_fixture(
            """
context.configure(dialect_name='sqlite', template_args={"somearg":"somevalue"})
"""
        )
        script_file_fixture(
            """
# somearg: ${somearg}
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
"""
        )

        command.revision(self.cfg, message="some rev")
        script = ScriptDirectory.from_config(self.cfg)

        rev = script.get_revision("head")
        with open(rev.path) as f:
            text = f.read()
        assert "somearg: somevalue" in text 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:23,代码来源:test_script_production.py

示例6: test_bad_render

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [as 别名]
def test_bad_render(self):
        env_file_fixture(
            """
context.configure(dialect_name='sqlite', template_args={"somearg":"somevalue"})
"""
        )
        script_file_fixture(
            """
    <% z = x + y %>
"""
        )

        try:
            command.revision(self.cfg, message="some rev")
        except CommandError as ce:
            m = re.match(
                r"^Template rendering failed; see (.+?) "
                "for a template-oriented",
                str(ce),
            )
            assert m, "Command error did not produce a file"
            with open(m.group(1)) as handle:
                contents = handle.read()
            os.remove(m.group(1))
            assert "<% z = x + y %>" in contents 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:27,代码来源:test_script_production.py

示例7: test_env_emits_warning

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [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

示例8: test_create_rev_autogen_db_not_up_to_date_multi_heads

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [as 别名]
def test_create_rev_autogen_db_not_up_to_date_multi_heads(self):
        self._env_fixture()
        command.revision(self.cfg)
        rev2 = command.revision(self.cfg)
        rev3a = command.revision(self.cfg)
        command.revision(self.cfg, head=rev2.revision, splice=True)
        command.upgrade(self.cfg, "heads")
        command.revision(self.cfg, head=rev3a.revision)

        assert_raises_message(
            util.CommandError,
            "Target database is not up to date.",
            command.revision,
            self.cfg,
            autogenerate=True,
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:18,代码来源:test_command.py

示例9: test_create_rev_plain_db_not_up_to_date_multi_heads

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [as 别名]
def test_create_rev_plain_db_not_up_to_date_multi_heads(self):
        self._env_fixture()
        command.revision(self.cfg)
        rev2 = command.revision(self.cfg)
        rev3a = command.revision(self.cfg)
        command.revision(self.cfg, head=rev2.revision, splice=True)
        command.upgrade(self.cfg, "heads")
        command.revision(self.cfg, head=rev3a.revision)

        assert_raises_message(
            util.CommandError,
            "Multiple heads are present; please specify the head revision "
            "on which the new revision should be based, or perform a merge.",
            command.revision,
            self.cfg,
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:18,代码来源:test_command.py

示例10: test_err_correctly_raised_on_dupe_rows_no_pk

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [as 别名]
def test_err_correctly_raised_on_dupe_rows_no_pk(self):
        self._env_fixture(version_table_pk=False)
        command.revision(self.cfg)
        r2 = command.revision(self.cfg)
        db = _sqlite_file_db()
        command.upgrade(self.cfg, "head")
        with db.connect() as conn:
            conn.execute(
                text("insert into alembic_version values ('%s')" % r2.revision)
            )
        assert_raises_message(
            util.CommandError,
            "Online migration expected to match one row when "
            "updating .* in 'alembic_version'; 2 found",
            command.downgrade,
            self.cfg,
            "-1",
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:20,代码来源:test_command.py

示例11: revision

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [as 别名]
def revision(directory=None, message=None, autogenerate=False, sql=False,
             head='head', splice=False, branch_label=None, version_path=None,
             rev_id=None):
    """Create a new revision file."""
    config = current_app.extensions['migrate'].migrate.get_config(directory)
    if alembic_version >= (0, 7, 0):
        command.revision(config, message, autogenerate=autogenerate, sql=sql,
                         head=head, splice=splice, branch_label=branch_label,
                         version_path=version_path, rev_id=rev_id)
    else:
        command.revision(config, message, autogenerate=autogenerate, sql=sql) 
开发者ID:jpush,项目名称:jbox,代码行数:13,代码来源:__init__.py

示例12: migrate

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [as 别名]
def migrate(directory=None, message=None, sql=False, head='head', splice=False,
            branch_label=None, version_path=None, rev_id=None):
    """Alias for 'revision --autogenerate'"""
    config = current_app.extensions['migrate'].migrate.get_config(
        directory, opts=['autogenerate'])
    if alembic_version >= (0, 7, 0):
        command.revision(config, message, autogenerate=True, sql=sql,
                         head=head, splice=splice, branch_label=branch_label,
                         version_path=version_path, rev_id=rev_id)
    else:
        command.revision(config, message, autogenerate=True, sql=sql) 
开发者ID:jpush,项目名称:jbox,代码行数:13,代码来源:__init__.py

示例13: edit

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [as 别名]
def edit(revision='current', directory=None):
    """Edit current revision."""
    if alembic_version >= (0, 8, 0):
        config = current_app.extensions['migrate'].migrate.get_config(
            directory)
        command.edit(config, revision)
    else:
        raise RuntimeError('Alembic 0.8.0 or greater is required') 
开发者ID:jpush,项目名称:jbox,代码行数:10,代码来源:__init__.py

示例14: upgrade

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [as 别名]
def upgrade(directory=None, revision='head', sql=False, tag=None, x_arg=None):
    """Upgrade to a later version"""
    config = current_app.extensions['migrate'].migrate.get_config(directory,
                                                                  x_arg=x_arg)
    command.upgrade(config, revision, sql=sql, tag=tag) 
开发者ID:jpush,项目名称:jbox,代码行数:7,代码来源:__init__.py

示例15: downgrade

# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import revision [as 别名]
def downgrade(directory=None, revision='-1', sql=False, tag=None, x_arg=None):
    """Revert to a previous version"""
    config = current_app.extensions['migrate'].migrate.get_config(directory,
                                                                  x_arg=x_arg)
    if sql and revision == '-1':
        revision = 'head:-1'
    command.downgrade(config, revision, sql=sql, tag=tag) 
开发者ID:jpush,项目名称:jbox,代码行数:9,代码来源:__init__.py


注:本文中的alembic.command.revision方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。