本文整理汇总了Python中playhouse.migrate.PostgresqlMigrator方法的典型用法代码示例。如果您正苦于以下问题:Python migrate.PostgresqlMigrator方法的具体用法?Python migrate.PostgresqlMigrator怎么用?Python migrate.PostgresqlMigrator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类playhouse.migrate
的用法示例。
在下文中一共展示了migrate.PostgresqlMigrator方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_postgres
# 需要导入模块: from playhouse import migrate [as 别名]
# 或者: from playhouse.migrate import PostgresqlMigrator [as 别名]
def init_postgres(url):
global DB
db_name = url.path.strip("/")
DB.initialize(PostgresqlDatabase(
database=db_name,
user=url.user or None,
password=url.password or None,
host=url.host,
autocommit=bool(url.get('autocommit', True)),
autorollback=bool(url.get('autorollback', True))
))
log.info("Database initialized as '%s'. Checking migrations...", db_name)
return DB, PostgresqlMigrator(DB)
示例2: migrate
# 需要导入模块: from playhouse import migrate [as 别名]
# 或者: from playhouse.migrate import PostgresqlMigrator [as 别名]
def migrate(migrations=MIGRATIONS):
db = get_db()
migrator = m.PostgresqlMigrator(db)
for migration in migrations:
migration(db, migrator)
示例3: __init__
# 需要导入模块: from playhouse import migrate [as 别名]
# 或者: from playhouse.migrate import PostgresqlMigrator [as 别名]
def __init__(self, rules, func):
self.rules = rules
self.func = func
self.actions = []
self.raw_actions = []
self.m = PostgresqlMigrator(database)
示例4: run_migrate
# 需要导入模块: from playhouse import migrate [as 别名]
# 或者: from playhouse.migrate import PostgresqlMigrator [as 别名]
def run_migrate(*args):
'''
running some migration.
'''
print('Begin migrate ...')
torcms_migrator = migrate.PostgresqlMigrator(config.DB_CON)
memo_field = migrate.TextField(null=False, default='', help_text='Memo', )
try:
migrate.migrate(torcms_migrator.add_column('tabpost', 'memo', memo_field))
except:
pass
desc_field = migrate.CharField(null=False, default='', max_length=255, help_text='')
try:
migrate.migrate(torcms_migrator.add_column('tabentity', 'desc', desc_field))
except:
pass
extinfo_field = BinaryJSONField(null=False, default={}, help_text='Extra data in JSON.')
try:
migrate.migrate(torcms_migrator.add_column('tabmember', 'extinfo', extinfo_field))
except:
pass
par_id_field = migrate.CharField(null=False, default='', max_length=4,
help_text='父类id,对于label,top_id为""')
try:
migrate.migrate(torcms_migrator.add_column('tabpost2tag', 'par_id', par_id_field))
except:
pass
category_field = migrate.CharField(null=False, default='0', max_length=1,
help_text='0为评论,1为回复')
try:
migrate.migrate(torcms_migrator.add_column('tabreply', 'category', category_field))
except:
pass
try:
migrate.migrate(torcms_migrator.drop_column('tabentity2user', 'count'))
# print('删除字段成功:count.')
except:
pass
user_ip_field = migrate.CharField(null=False, default='0', help_text='User IP Address', )
try:
migrate.migrate(torcms_migrator.add_column('tabentity2user', 'user_ip', user_ip_field))
# print('添加字段成功:user_ip.')
except:
pass
print('Migration finished.')