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