當前位置: 首頁>>代碼示例>>Python>>正文


Python schema.CreateSchema方法代碼示例

本文整理匯總了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") 
開發者ID:rucio,項目名稱:rucio,代碼行數:19,代碼來源:util.py

示例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)) 
開發者ID:PruthviKumarBK,項目名稱:PROTON,代碼行數:19,代碼來源:connection_manager.py

示例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) 
開發者ID:OpenTransitTools,項目名稱:gtfsdb,代碼行數:15,代碼來源:db.py

示例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 
開發者ID:mazvv,項目名稱:travelcrm,代碼行數:16,代碼來源:companies_utils.py

示例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",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:14,代碼來源:test_metadata.py


注:本文中的sqlalchemy.schema.CreateSchema方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。