本文整理匯總了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",
)