本文整理汇总了Python中alembic.command.init方法的典型用法代码示例。如果您正苦于以下问题:Python command.init方法的具体用法?Python command.init怎么用?Python command.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alembic.command
的用法示例。
在下文中一共展示了command.init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: staging_env
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def staging_env(create=True, template="generic", sourceless=False):
from alembic import command, script
cfg = _testing_config()
if create:
path = os.path.join(_get_staging_directory(), 'scripts')
if os.path.exists(path):
shutil.rmtree(path)
command.init(cfg, path, template=template)
if sourceless:
try:
# do an import so that a .pyc/.pyo is generated.
util.load_python_file(path, 'env.py')
except AttributeError:
# we don't have the migration context set up yet
# so running the .env py throws this exception.
# theoretically we could be using py_compiler here to
# generate .pyc/.pyo without importing but not really
# worth it.
pass
make_sourceless(os.path.join(path, "env.py"))
sc = script.ScriptDirectory.from_config(cfg)
return sc
示例2: init_development_data
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def init_development_data(context, upgrade_db=True, skip_on_failure=False):
"""
Fill a database with development data like default users.
"""
if upgrade_db:
context.invoke_execute(context, 'app.db.upgrade')
log.info("Initializing development data...")
from migrations import initial_development_data
try:
initial_development_data.init()
except AssertionError as exception:
if not skip_on_failure:
log.error("%s", exception)
else:
log.debug(
"The following error was ignored due to the `skip_on_failure` flag: %s",
exception
)
log.info("Initializing development data step is skipped.")
else:
log.info("Fixtures have been successfully applied.")
示例3: test_init_file_exists_and_is_empty
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def test_init_file_exists_and_is_empty(self):
def access_(path, mode):
if "generic" in path or path == "foobar":
return True
else:
return False
def listdir_(path):
if path == "foobar":
return []
else:
return ["file1", "file2", "alembic.ini.mako"]
with mock.patch(
"alembic.command.os.access", side_effect=access_
), mock.patch("alembic.command.os.makedirs") as makedirs, mock.patch(
"alembic.command.os.listdir", side_effect=listdir_
), mock.patch(
"alembic.command.ScriptDirectory"
):
command.init(self.cfg, directory="foobar")
eq_(
makedirs.mock_calls,
[mock.call(os.path.normpath("foobar/versions"))],
)
示例4: test_init_file_doesnt_exist
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def test_init_file_doesnt_exist(self):
def access_(path, mode):
if "generic" in path:
return True
else:
return False
with mock.patch(
"alembic.command.os.access", side_effect=access_
), mock.patch("alembic.command.os.makedirs") as makedirs, mock.patch(
"alembic.command.ScriptDirectory"
):
command.init(self.cfg, directory="foobar")
eq_(
makedirs.mock_calls,
[
mock.call("foobar"),
mock.call(os.path.normpath("foobar/versions")),
],
)
示例5: test_init_w_package
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def test_init_w_package(self):
path = os.path.join(_get_staging_directory(), "foobar")
with mock.patch("alembic.command.open") as open_:
command.init(self.cfg, directory=path, package=True)
eq_(
open_.mock_calls,
[
mock.call(
os.path.abspath(os.path.join(path, "__init__.py")), "w"
),
mock.call().close(),
mock.call(
os.path.abspath(
os.path.join(path, "versions", "__init__.py")
),
"w",
),
mock.call().close(),
],
)
示例6: init
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def init(directory=None, multidb=False):
"""Generates a new migration"""
if directory is None:
directory = current_app.extensions['migrate'].directory
config = Config()
config.set_main_option('script_location', directory)
config.config_file_name = os.path.join(directory, 'alembic.ini')
config = current_app.extensions['migrate'].\
migrate.call_configure_callbacks(config)
if multidb:
command.init(config, directory, 'flask-multidb')
else:
command.init(config, directory, 'flask')
示例7: init_db
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def init_db(config):
"""Creates a new migration repository."""
directory = os.path.join('yui', 'migrations')
c = Config()
c.set_main_option('script_location', directory)
c.set_main_option('sqlalchemy.url', config.DATABASE_URL)
c.config_file_name = os.path.join(directory, 'alembic.ini')
command.init(c, directory, 'chatterbox')
示例8: init
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def init(context, directory='migrations', multidb=False):
"""Generates a new migration"""
config = Config()
config.set_main_option('script_location', directory)
config.config_file_name = os.path.join(directory, 'alembic.ini')
if multidb:
command.init(config, directory, 'flask-multidb')
else:
command.init(config, directory, 'flask')
示例9: staging_env
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def staging_env(create=True, template="generic", sourceless=False):
from alembic import command, script
cfg = _testing_config()
if create:
path = os.path.join(_get_staging_directory(), "scripts")
assert not os.path.exists(path), (
"staging directory %s already exists; poor cleanup?" % path
)
command.init(cfg, path, template=template)
if sourceless:
try:
# do an import so that a .pyc/.pyo is generated.
util.load_python_file(path, "env.py")
except AttributeError:
# we don't have the migration context set up yet
# so running the .env py throws this exception.
# theoretically we could be using py_compiler here to
# generate .pyc/.pyo without importing but not really
# worth it.
pass
assert sourceless in (
"pep3147_envonly",
"simple",
"pep3147_everything",
), sourceless
make_sourceless(
os.path.join(path, "env.py"),
"pep3147" if "pep3147" in sourceless else "simple",
)
sc = script.ScriptDirectory.from_config(cfg)
return sc
示例10: test_init_file_exists_and_is_not_empty
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def test_init_file_exists_and_is_not_empty(self):
with mock.patch(
"alembic.command.os.listdir", return_value=["file1", "file2"]
), mock.patch("alembic.command.os.access", return_value=True):
directory = "alembic"
assert_raises_message(
util.CommandError,
"Directory %s already exists and is not empty" % directory,
command.init,
self.cfg,
directory=directory,
)
示例11: init
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def init(self):
dirname = self.cfg.get_main_option('script_location')
alembic_cmd.init(self.cfg, dirname, template='lux')
示例12: make_parser
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def make_parser(self, subparsers):
parser = subparsers.add_parser('init', help=self.init.__doc__)
parser.add_argument('-d', '--directory', dest='directory', default=None,
help="migration script directory (default is 'migrations')")
return parser
示例13: run
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def run(self, parser, args):
self.init(**vars(args))
示例14: init
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def init(self, directory, **kwargs):
"""Generates a new migration"""
config = Config()
config.set_main_option('script_location', directory)
config.config_file_name = os.path.join(directory, 'alembic.ini')
command.init(config, directory, 'relengapi')
示例15: staging_env
# 需要导入模块: from alembic import command [as 别名]
# 或者: from alembic.command import init [as 别名]
def staging_env(create=True, template="generic", sourceless=False):
from alembic import command, script
cfg = _testing_config()
if create:
path = os.path.join(_get_staging_directory(), 'scripts')
if os.path.exists(path):
shutil.rmtree(path)
command.init(cfg, path, template=template)
if sourceless:
try:
# do an import so that a .pyc/.pyo is generated.
util.load_python_file(path, 'env.py')
except AttributeError:
# we don't have the migration context set up yet
# so running the .env py throws this exception.
# theoretically we could be using py_compiler here to
# generate .pyc/.pyo without importing but not really
# worth it.
pass
assert sourceless in (
"pep3147_envonly", "simple", "pep3147_everything"), sourceless
make_sourceless(
os.path.join(path, "env.py"),
"pep3147" if "pep3147" in sourceless else "simple"
)
sc = script.ScriptDirectory.from_config(cfg)
return sc