-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
38 lines (25 loc) · 1 KB
/
models.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 datetime
import uuid
import os
import peewee
import playhouse.db_url
db = playhouse.db_url.connect(os.environ.get('DATABASE_URL') or 'sqlite:///cc-survey.db')
class ModelBase(peewee.Model):
class Meta:
database = db
class Submission(ModelBase):
"""Survey submission model.
Uses a UUID for the ID instead of an integer sequence so that survey
submissions cannot be linked to user hashes."""
id = peewee.UUIDField(default=uuid.uuid4, primary_key=True)
form = peewee.TextField()
sample = peewee.IntegerField()
time = peewee.DateTimeField(default=datetime.datetime.now)
version = peewee.IntegerField()
class UserHash(ModelBase):
"""User hash model."""
hash = peewee.TextField(primary_key=True)
class AuthorizationKey(ModelBase):
"""Can be created to allow users without RCS IDs to take the survey."""
key = peewee.TextField(primary_key=True)
db.create_tables([Submission, UserHash, AuthorizationKey], safe=True)