forked from pmeinhardt/tlr
-
Notifications
You must be signed in to change notification settings - Fork 2
/
models.py
80 lines (64 loc) · 2.55 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from peewee import *
from database import *
import datetime
dbproxy = Proxy()
class Base(Model):
class Meta:
database = dbproxy
class User(Base):
id = PrimaryKeyField()
name = CharField(unique=True, null=False, index=True)
confirmed = BooleanField(default=False, null=False)
github_id = MSQLIntegerField(unsigned=True, null=True)
homepage_url = CharField(default=None, null=True)
avatar_url = CharField(default=None, null=True)
email = CharField(default=None, null=True)
salt = CharField(default=None, null=True)
password = CharField(default=None, null=True)
class Token(Base):
id = PrimaryKeyField()
value = CharField(unique=True, null=False, index=True)
user = ForeignKeyField(User, related_name="tokens", null=False)
seen = BooleanField(default=False, null=False)
desc = CharField(null=False)
class Repo(Base):
id = PrimaryKeyField(null=False)
user = ForeignKeyField(User, related_name="repos", null=False)
name = CharField(null=False, index=True)
desc = CharField(max_length=255)
private = BooleanField(default=False, null=False)
class Meta:
indexes = [(("user", "name"), True)]
class HMap(Base):
sha = MSQLBinaryField(length=20, primary_key=True)
val = CharField(max_length=2048, null=False)
class CSet(Base):
repo = ForeignKeyField(Repo, related_name="csets", null=False)
hkey = ForeignKeyField(HMap, null=False)
time = MSQLTimestampField(precision=0, null=False)
type = MSQLTinyIntegerField(unsigned=True, null=False)
len = MSQLMediumIntegerField(unsigned=True, null=False)
# created_at = DateTimeField(default=datetime.datetime.now)
# base = MSQLTimestampField(precision=3, null=False)
class Meta:
primary_key = CompositeKey("repo", "hkey", "time")
SNAPSHOT = 0
DELTA = 1
DELETE = 2
# TODO: Store blobs in a dedicated blobstore? (benchmark)
class CommitMessage(Base):
repo = ForeignKeyField(Repo, related_name="commitMessages", null=False)
hkey = ForeignKeyField(HMap, null=False)
time = MSQLTimestampField(precision=0, null=False)
message = CharField(max_length=512)
class Meta:
primary_key = CompositeKey("repo", "hkey", "time")
class Blob(Base):
repo = ForeignKeyField(Repo, related_name="blobs", null=False)
hkey = ForeignKeyField(HMap, null=False)
time = MSQLTimestampField(precision=0, null=False)
data = MSQLMediumBlobField()
class Meta:
primary_key = CompositeKey("repo", "hkey", "time")
def initialize(database, blobstore):
dbproxy.initialize(database)