本文整理汇总了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)
示例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)
示例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()