-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
44 lines (33 loc) · 1.13 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
from peewee import Model, PostgresqlDatabase
from playhouse.db_url import connect, parse
from peewee import CharField, IntegerField, \
DateTimeField, BooleanField, BigIntegerField, ForeignKeyField
from settings import DATABASE_URL
DEBUG = True
DB_ARGS = parse(DATABASE_URL)
DB = PostgresqlDatabase(**DB_ARGS)
class BaseModel(Model):
""" BaseModel for all Schema definitions in Opine """
class Meta:
database = DB
class Installation(BaseModel):
""" Represents a github app installation """
ghid = IntegerField(unique=True, null=False)
repo = CharField()
owner = CharField()
origin = CharField()
active = BooleanField()
created = DateTimeField()
updated = DateTimeField()
class Meta:
order_by = ('id', )
indexes = (
(('repo', 'owner', 'origin', 'active'), False),
)
class Stats(BaseModel):
""" Simple counters for app and number of comments against app """
installation = ForeignKeyField(Installation)
comments = BigIntegerField()
updated = DateTimeField()
if __name__ == '__main__':
DB.create_tables([Installation, Stats], safe=True)