本文整理汇总了Python中alembic.command.downgrade方法的典型用法代码示例。如果您正苦于以下问题:Python command.downgrade方法的具体用法?Python command.downgrade怎么用?Python command.downgrade使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alembic.command
的用法示例。
在下文中一共展示了command.downgrade方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_upgrade_and_downgrade
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [as 别名]
def test_upgrade_and_downgrade(uri_left, alembic_config_left):
"""Test all migrations up and down.
Tests that we can apply all migrations from a brand new empty
database, and also that we can remove them all.
"""
ah.load_premigration_sql(uri_left)
engine, script = prepare_schema_from_migrations(
uri_left, alembic_config_left
)
head = get_head_revision(alembic_config_left, engine, script)
current = get_current_revision(alembic_config_left, engine, script)
assert head == current
while current is not None:
command.downgrade(alembic_config_left, '-1')
current = get_current_revision(alembic_config_left, engine, script)
示例2: test_err_correctly_raised_on_dupe_rows_no_pk
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [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",
)
示例3: _inline_enum_script
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [as 别名]
def _inline_enum_script(self):
write_script(
self.script,
self.rid,
"""
revision = '%s'
down_revision = None
from alembic import op
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy import Column
def upgrade():
op.create_table("sometable",
Column("data", ENUM("one", "two", "three", name="pgenum"))
)
def downgrade():
op.drop_table("sometable")
"""
% self.rid,
)
示例4: test_data_migrations
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [as 别名]
def test_data_migrations(
alembic_config, postgres_engine, rev_base: str, rev_head: str,
on_init: Callable, on_upgrade: Callable, on_downgrade: Callable
):
# Upgrade to previous migration before target and add some data,
# that would be changed by tested migration.
upgrade(alembic_config, rev_base)
on_init(engine=postgres_engine)
# Perform upgrade in tested migration.
# Check that data is migrated correctly in on_upgrade callback
upgrade(alembic_config, rev_head)
on_upgrade(engine=postgres_engine)
# Perform downgrade in tested migration.
# Check that changes are reverted back using on_downgrade callback
downgrade(alembic_config, rev_base)
on_downgrade(engine=postgres_engine)
示例5: downgrade
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [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)
示例6: drop_tables
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [as 别名]
def drop_tables(ctx):
""" Alias for 'alembic downgrade base'.
Downgrade to no database tables
"""
current_session = get_current_session()
command.downgrade(setup_alembic_config(url=current_session.url),
revision='base', sql=False, tag=None)
示例7: downgrade
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [as 别名]
def downgrade(config, revision: str, sql: bool, tag: str):
"""Revert to a previous version."""
bot = Bot(config)
directory = os.path.join('yui', 'migrations')
c = Config(os.path.join(directory, 'alembic.ini'))
c.set_main_option('script_location', directory)
c.set_main_option('sqlalchemy.url', bot.config.DATABASE_URL)
c.attributes['Base'] = bot.orm_base
command.downgrade(c, revision, sql=sql, tag=tag)
示例8: downgrade
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [as 别名]
def downgrade(self, revision):
alembic_command.downgrade(self.config(), revision)
示例9: test_upgrade_heads_downgrade_base
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [as 别名]
def test_upgrade_heads_downgrade_base(self):
self.upgrade('heads')
self.downgrade('base')
示例10: test_upgrade_heads_downgrade_base_upgrade_heads
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [as 别名]
def test_upgrade_heads_downgrade_base_upgrade_heads(self):
self.upgrade('heads')
self.downgrade('base')
self.upgrade('heads')
示例11: downgrade
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [as 别名]
def downgrade(self):
downgrade(self.alembic_config, 'base')
示例12: run
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [as 别名]
def run(parser, options, args):
if len(args) not in (1, 2):
parser.error('Bad number of parameters')
# Read the configuration of the application
try:
application = args[1]
except IndexError:
application = 'kansha'
cfg = _build_alembic_config()
_set_sqlalchemy_uri(cfg, application, parser.error)
command.downgrade(cfg, args[0])
示例13: downgrade
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [as 别名]
def downgrade(context, directory='migrations', revision='-1', sql=False, tag=None, x_arg=None):
"""Revert to a previous version"""
config = _get_config(directory, x_arg=x_arg)
if sql and revision == '-1':
revision = 'head:-1'
command.downgrade(config, revision, sql=sql, tag=tag)
示例14: test_not_requires_connection
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [as 别名]
def test_not_requires_connection(self):
env_file_fixture(
"""
assert not context.requires_connection()
"""
)
command.upgrade(self.cfg, a, sql=True)
command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True)
示例15: test_requires_connection
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import downgrade [as 别名]
def test_requires_connection(self):
env_file_fixture(
"""
assert context.requires_connection()
"""
)
command.upgrade(self.cfg, a)
command.downgrade(self.cfg, a)