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


Python migrate.SqliteMigrator方法代碼示例

本文整理匯總了Python中playhouse.migrate.SqliteMigrator方法的典型用法代碼示例。如果您正苦於以下問題:Python migrate.SqliteMigrator方法的具體用法?Python migrate.SqliteMigrator怎麽用?Python migrate.SqliteMigrator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在playhouse.migrate的用法示例。


在下文中一共展示了migrate.SqliteMigrator方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: init_sqlite

# 需要導入模塊: from playhouse import migrate [as 別名]
# 或者: from playhouse.migrate import SqliteMigrator [as 別名]
def init_sqlite(url):
    global DB

    dbfile = os.path.join("/", *url.path.split("/"))
    dirname = os.path.dirname(dbfile)

    log.info('Opening sqlite database: %s', dbfile)

    if not os.path.exists(dirname):
        os.makedirs(dirname)

    DB.initialize(SqliteDatabase(dbfile))
    log.info("Database initialized as '%s'. Checking migrations...", dbfile)
    return DB, SqliteMigrator(DB) 
開發者ID:mosquito,項目名稱:pypi-server,代碼行數:16,代碼來源:__init__.py

示例2: setup_db

# 需要導入模塊: from playhouse import migrate [as 別名]
# 或者: from playhouse.migrate import SqliteMigrator [as 別名]
def setup_db():
    global home, database
    database_url = config.get("db", "sqlite:///diffengine.db")
    logging.debug("connecting to db %s", database_url)
    database_handler = connect(database_url)
    database.initialize(database_handler)
    database.connect()
    database.create_tables([Feed, Entry, FeedEntry, EntryVersion, Diff], safe=True)

    if isinstance(database_handler, SqliteDatabase):
        try:
            migrator = SqliteMigrator(database_handler)
            migrate(migrator.add_index("entryversion", ("url",), False))
        except OperationalError as e:
            logging.debug(e) 
開發者ID:DocNow,項目名稱:diffengine,代碼行數:17,代碼來源:__init__.py

示例3: db_upgrade

# 需要導入模塊: from playhouse import migrate [as 別名]
# 或者: from playhouse.migrate import SqliteMigrator [as 別名]
def db_upgrade(old_version):
    migrator = SqliteMigrator(_db)
    if old_version < 2:
        User_login.create_table()
        migrate(
            migrator.add_column('clan_member', 'remaining_status',
                                TextField(null=True)),
            migrator.add_column('clan_challenge', 'message',
                                TextField(null=True)),
            migrator.add_column('clan_group', 'boss_lock_type',
                                IntegerField(default=0)),
            migrator.drop_column('user', 'last_save_slot'),
        )
    if old_version < 3:
        migrate(
            migrator.drop_column('user', 'auth_cookie'),
            migrator.drop_column('user', 'auth_cookie_expire_time'),
        )
    if old_version < 4:
        migrate(
            migrator.add_column('user', 'deleted',
                                BooleanField(default=False)),
        )
    if old_version < 5:
        migrate(
            migrator.add_column('user', 'must_change_password',
                                BooleanField(default=True)),
        )
    if old_version < 6:
        User.update({User.authority_group: 1}).where(
            User.authority_group == 2).execute()
    if old_version < 7:
        migrate(
            migrator.drop_column('clan_challenge', 'comment'),
            migrator.add_column('clan_challenge', 'behalf',
                                IntegerField(null=True)),
            migrator.drop_column('clan_subscribe', 'comment'),
            migrator.add_column('clan_subscribe', 'message',
                                TextField(null=True)),
            migrator.add_column('clan_group', 'apikey',
                                CharField(max_length=16, default=rand_string)),
        )
    if old_version < 8:
        migrate(
            migrator.add_column('clan_group', 'deleted',
                                BooleanField(default=False)),
            migrator.add_column('clan_group', 'battle_id',
                                IntegerField(default=0)),
            migrator.add_column('clan_challenge', 'bid',
                                IntegerField(default=0)),
            migrator.add_index('clan_challenge', ('bid', 'gid'), False)
        )
    if old_version < 9:
        migrate(
            migrator.add_index('clan_member', ('qqid',), False)
        )

    DB_schema.replace(key='version', value=str(_version)).execute() 
開發者ID:yuudi,項目名稱:yobot,代碼行數:60,代碼來源:ybdata.py


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