-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmigrate.py
53 lines (43 loc) · 1.35 KB
/
migrate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from pprint import pprint
from typing import List
from decouple import config
from redis import StrictRedis
from redis_collections import Dict
import settings
from model import *
def reset_answers(users: List[User] = None):
if users is None:
UserAnswers.drop_table()
UserAnswers.create_table()
else:
return UserAnswers.delete().where(UserAnswers.user << users).execute()
def clear_redis(users: List[User] = None):
conn = StrictRedis.from_url(settings.REDIS_URL)
if users:
to_delete = []
for u in users:
to_delete.extend(conn.keys(rf'{u.id}*'))
for k in to_delete:
conn.delete(k)
else:
conn.flushdb()
def reset_all():
Update.drop_table(fail_silently=True, cascade=True)
Update.create_table()
User.drop_table(fail_silently=True, cascade=True)
User.create_table()
# User.insert(telegram_id=62056065, formal_address=False).execute()
Update.drop_table(fail_silently=True, cascade=True)
Update.create_table()
reset_answers()
clear_redis()
if __name__ == '__main__':
# reset_all()
users = User.select().where(
(User.facebook_id == 1841418505898164) |
(User.telegram_id == 62056065)
) # joscha
reset_answers([users])
clear_redis()
# for u in user:
# print(u.id, u.telegram_id, u.facebook_id)