本文整理汇总了Python中sqlalchemy.schema.CreateSchema方法的典型用法代码示例。如果您正苦于以下问题:Python schema.CreateSchema方法的具体用法?Python schema.CreateSchema怎么用?Python schema.CreateSchema使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.schema
的用法示例。
在下文中一共展示了schema.CreateSchema方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_database
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateSchema [as 别名]
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)
schema = config_get('database', 'schema', raise_exception=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")
示例2: pg_schema_generator
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateSchema [as 别名]
def pg_schema_generator(cls, engine_copy, schema_name):
try:
if not engine_copy.dialect.has_schema(engine_copy, schema_name):
engine_copy.execute(schema.CreateSchema(schema_name))
cls.connection_manager_logger.info(
'[connection_manager]: Successfully generated schema: {} in respective database of '
'postgresql'.format(schema_name))
return True
cls.connection_manager_logger.info(
'[connection_manager]: Schema: {} already exists in respective database of '
'postgresql'.format(schema_name))
return True
except Exception as e:
cls.connection_manager_logger.exception(
'[connection_manager]: Error generating schema {} in Postgres. Stack trace to follow.'.format(
schema_name))
cls.connection_manager_logger.error(str(e))
示例3: schema
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateSchema [as 别名]
def schema(self, val):
self._schema = val
# TODO ... move to create() method
try:
if self._schema:
from sqlalchemy.schema import CreateSchema
self.engine.execute(CreateSchema(self._schema), checkfirst=True)
except Exception as e:
log.info("NOTE: couldn't create schema {0} (schema might already exist)\n{1}".format(self._schema, e))
for cls in self.classes:
cls.set_schema(self._schema)
示例4: create_company_schema
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateSchema [as 别名]
def create_company_schema(schema_name=None, locale=None):
if not schema_name:
schema_name = generate_company_schema()
engine = DBSession.get_bind()
engine.execute(CreateSchema(schema_name))
set_search_path(schema_name)
metadata = MetaData(schema=schema_name)
metadata.bind = engine
Base.metadata.create_all(
tables=[t.tometadata(metadata) for t in Base.metadata.sorted_tables]
)
transfer_data(schema_name, locale)
log.info(u'Company creation complete')
return schema_name
示例5: test_create_drop_schema
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateSchema [as 别名]
def test_create_drop_schema(self):
self.assert_compile(
schema.CreateSchema("sa_schema"), "CREATE SCHEMA sa_schema"
)
self.assert_compile(
schema.DropSchema("sa_schema"), "DROP SCHEMA sa_schema"
)
self.assert_compile(
schema.DropSchema("sa_schema", cascade=True),
"DROP SCHEMA sa_schema CASCADE",
)