hamster-tools/hamstertools/db.py

96 lines
2.2 KiB
Python

from datetime import datetime
from peewee import (
SqliteDatabase,
Model,
CharField,
ForeignKeyField,
DateTimeField,
SmallIntegerField,
BooleanField,
)
db = SqliteDatabase(None)
class HamsterCategory(Model):
name = CharField()
class Meta:
database = db
table_name = "categories"
class HamsterActivity(Model):
name = CharField()
category = ForeignKeyField(HamsterCategory, backref="activities")
class Meta:
database = db
table_name = "activities"
class HamsterFact(Model):
activity = ForeignKeyField(HamsterActivity, backref="facts")
start_time = DateTimeField()
end_time = DateTimeField(null=True)
description = CharField()
class Meta:
database = db
table_name = "facts"
class KimaiCustomer(Model):
visible = BooleanField(default=True)
name = CharField()
class Meta:
database = db
table_name = "kimai_customers"
class KimaiProject(Model):
name = CharField()
customer = ForeignKeyField(KimaiCustomer, backref="projects")
visible = BooleanField(default=True)
allow_global_activities = BooleanField(default=True)
class Meta:
database = db
table_name = "kimai_projects"
class KimaiActivity(Model):
name = CharField()
project = ForeignKeyField(KimaiProject, backref="activities", null=True)
visible = BooleanField(default=True)
class Meta:
database = db
table_name = "kimai_activities"
class HamsterActivityKimaiMapping(Model):
hamster_activity = ForeignKeyField(HamsterActivity, backref="mappings")
kimai_customer = ForeignKeyField(KimaiCustomer, backref="mappings")
kimai_project = ForeignKeyField(KimaiProject, backref="mappings")
kimai_activity = ForeignKeyField(KimaiActivity, backref="mappings")
kimai_description = CharField()
kimai_tags = CharField()
class Meta:
database = db
table_name = "hamster_kimai_mappings"
class HamsterFactKimaiImport(Model):
hamster_fact = ForeignKeyField(HamsterFact, backref="imports")
kimai_id = SmallIntegerField()
imported = DateTimeField(default=datetime.now)
class Meta:
database = db
table_name = "hamster_fact_kimai_imports"