forked from Zverik/osmstreak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
38 lines (29 loc) · 856 Bytes
/
db.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
import config
from playhouse.db_url import connect
from peewee import (
Model,
CharField,
IntegerField,
ForeignKeyField,
BooleanField,
DateField
)
database = connect(config.DATABASE_URI)
class BaseModel(Model):
class Meta:
database = database
class User(BaseModel):
uid = IntegerField(primary_key=True)
name = CharField(max_length=250)
email = CharField(max_length=250, null=True)
score = IntegerField(default=0)
streak = IntegerField(default=0)
level = IntegerField(default=1)
class Task(BaseModel):
user = ForeignKeyField(User, related_name='tasks', index=True)
day = DateField(index=True)
task = CharField(max_length=50)
changeset = IntegerField(null=True)
correct = BooleanField(null=True)
def create_tables():
database.create_tables([User, Task], safe=True)