hamster-tools/hamstertools/db.py
2023-10-29 13:40:03 +00:00

78 lines
1.8 KiB
Python

import logging
from peewee import SqliteDatabase, Model, CharField, ForeignKeyField, DateTimeField
from textual.logging import TextualHandler
logger = logging.getLogger("peewee")
logger.addHandler(TextualHandler())
logger.setLevel(logging.DEBUG)
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):
name = CharField()
class Meta:
database = db
table_name = "kimai_customers"
class KimaiProject(Model):
name = CharField()
customer = ForeignKeyField(KimaiCustomer, backref="projects")
class Meta:
database = db
table_name = "kimai_projects"
class KimaiActivity(Model):
name = CharField()
project = ForeignKeyField(KimaiProject, backref="activities", null=True)
class Meta:
database = db
table_name = "kimai_activities"
class HamsterKimaiMapping(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"