summaryrefslogtreecommitdiff
path: root/api/v1/db.py
blob: 1d9f469a8fc10c095b7dfd43083b08f0df129b11 (plain)
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
from peewee import SqliteDatabase, ForeignKeyField, CharField, Model, IntegerField, DateTimeField, BooleanField

db = SqliteDatabase('datapackmanager.db')


class BaseModel(Model):
    class Meta:
        database = db


class User(BaseModel):
    name = CharField()
    id = IntegerField(primary_key=True)
    email = CharField()
    password_hash = CharField()


class Category(BaseModel):
    name = CharField()
    id = IntegerField(primary_key=True)


class Tag(BaseModel):
    name = CharField(primary_key=True)


class DataPack(BaseModel):
    id = IntegerField(primary_key=True)
    name = CharField()
    description = CharField(max_length=10000)
    category = ForeignKeyField(Category)
    author = ForeignKeyField(User)
    likes = IntegerField()
    dislikes = IntegerField()
    downloads = IntegerField()
    views = IntegerField()


class TagRelation(BaseModel):
    tags = ForeignKeyField(Tag)
    packs = ForeignKeyField(DataPack)


class Comment(BaseModel):
    id = IntegerField(primary_key=True)
    datapack = ForeignKeyField(DataPack)
    user = ForeignKeyField(User)
    mesage = CharField(max_length=2000)
    creation = DateTimeField()


class Version(BaseModel):
    id = IntegerField(primary_key=True)
    name = CharField()
    datapack = ForeignKeyField(DataPack)
    prerelease = BooleanField()
    releaedate = DateTimeField()


db.create_tables([DataPack, Category, Version, User, Comment, TagRelation, Tag])
__all__ = ['DataPack', 'Category', 'Version', 'User', 'Comment', 'TagRelation', 'Tag']