예제 #1
0
def work():
    sql_execute(
        '''ALTER TABLE "user" ALTER COLUMN number SET DEFAULT nextval('user_count_seq');'''
    )
    sql_execute(
        'ALTER TABLE "user" ADD phone_verified boolean DEFAULT FALSE NULL;')
    sql_execute(
        'ALTER TABLE "user" ADD change_nickname_chance int DEFAULT 0 NULL;')

    sql_execute('ALTER TABLE "user" ALTER COLUMN email DROP NOT NULL;')
    sql_execute('ALTER TABLE "user" ALTER COLUMN email SET DEFAULT NULL;')

    sql_execute('ALTER TABLE "user" ALTER COLUMN phone DROP NOT NULL;')
    sql_execute('ALTER TABLE "user" ALTER COLUMN phone SET DEFAULT null;')
    sql_execute('CREATE UNIQUE INDEX user_phone ON "user" (phone);')
    sql_execute('ALTER TABLE "user" ALTER COLUMN nickname DROP NOT NULL;')

    sql_execute('ALTER TABLE "user" RENAME COLUMN reputation TO repute;')
    sql_execute(
        'ALTER TABLE "user" ADD is_new_user BOOLEAN DEFAULT TRUE  NOT NULL;')

    # 注册的激活机制改了,变通一下吧
    for i in UserModel.select().where(UserModel.group == USER_GROUP.INACTIVE):
        i.group = USER_GROUP.NORMAL
        i.save()

    # 老用户全部设置为非新用户
    for i in UserModel.select().where(UserModel.is_new_user == False):
        i.is_new_user = True
        i.save()
예제 #2
0
def work():
    try:
        db.execute_sql(
            'ALTER TABLE public.comment ADD reply_to_cmt_id BYTEA NULL;')
    except:
        db.rollback()

    for i in UserModel.select().execute():
        try:
            UserNotifRecord.create(id=i.id, update_time=int(time.time()))
        except peewee.IntegrityError:
            db.rollback()
예제 #3
0
파일: u10-u11.py 프로젝트: yisan/Icarus
def work():
    sql_execute(
        'ALTER TABLE "topic" ADD COLUMN "update_time" BIGINT NULL DEFAULT NULL ;'
    )
    sql_execute(
        'ALTER TABLE "user" ADD COLUMN "ip_registered" inet NULL DEFAULT NULL;'
    )
    sql_execute('drop table "notif";')
    sql_execute('drop table "mention";')
    sql_execute('drop table "user_notif_record";')

    db.create_tables([UserNotifLastInfo], safe=True)
    for i in UserModel.select().execute():
        try:
            UserNotifLastInfo.create(id=i.id, update_time=int(time.time()))
        except peewee.IntegrityError as e:
            print(e)
            db.rollback()
예제 #4
0
def nickname_exists_check(name):
    if list(UserModel.select().where(UserModel.nickname == name)):
        raise ValidationError('此昵称已被占用')
    return True
예제 #5
0
def email_exists_check(email):
    if list(UserModel.select().where(UserModel.email == email)):
        raise ValidationError('此邮箱已注册')
    return True
예제 #6
0
def email_exists_check(form, field):
    email = field.data
    if list(UserModel.select().where(UserModel.email == email)):
        raise ValidationError('此邮箱已注册')
    return True
예제 #7
0
def nickname_exists_check(form, field):
    name = field.data
    if list(UserModel.select().where(UserModel.nickname == name)):
        raise ValidationError('此昵称已被占用')
    return True
예제 #8
0
파일: notif.py 프로젝트: yisan/Icarus
        def pack_notif(i: Dict):
            i.update({'id': config.LONG_ID_GENERATOR().to_bin()})
            # 注意,insert_many 要求所有列一致,因此不能出现有的数据独有a列,有的数据独有b列
            # 要都有才行,因此全部进行默认填充
            i.setdefault('related_type', None)
            i.setdefault('related_id', None)
            i.setdefault('brief', None)
            i.setdefault('data', None)
            return i

        newlst = r.get_notifications(True)
        newlst.sort(key=lambda x: x['time'], reverse=True)
        newlst = list(map(pack_notif, newlst))

        if newlst:
            cls.insert_many(newlst).execute()
        return len(newlst)

    class Meta:
        db_table = 'notif'


if __name__ == '__main__':
    u: UserModel = UserModel.select().where(UserModel.nickname == '折影').get()
    r: UserNotifLastInfo = UserNotifLastInfo.get_by_pk(u.id)
    for i in r.get_notifications():
        print(i)
    print('------')
    # Notification.refresh(u.id)