2020-07-01 19:24:03 +00:00
|
|
|
# Copyright (C) 2020 by Thomas Lindner <tom@dl6tom.de>
|
|
|
|
# Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de>
|
2020-09-28 22:54:34 +00:00
|
|
|
# Copyright (C) 2020 by Martin Rey <martin.rey@mailbox.org>
|
2020-07-01 19:24:03 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: 0BSD
|
|
|
|
|
2020-10-13 09:38:33 +00:00
|
|
|
"""ORM Models for core."""
|
2020-07-11 10:54:07 +00:00
|
|
|
|
2020-07-01 19:24:03 +00:00
|
|
|
from databases import Database
|
2020-10-13 08:35:20 +00:00
|
|
|
from ormantic import Boolean, ForeignKey, Integer, Model, Text
|
|
|
|
from sqlalchemy import MetaData, create_engine
|
|
|
|
|
2020-07-01 19:24:03 +00:00
|
|
|
from kibicara.config import config
|
|
|
|
|
|
|
|
|
|
|
|
class Mapping:
|
|
|
|
database = Database(config['database_connection'])
|
|
|
|
metadata = MetaData()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def create_all(cls):
|
|
|
|
engine = create_engine(str(cls.database.url))
|
|
|
|
cls.metadata.create_all(engine)
|
|
|
|
|
2020-07-07 01:16:23 +00:00
|
|
|
@classmethod
|
|
|
|
def drop_all(cls):
|
|
|
|
engine = create_engine(str(cls.database.url))
|
|
|
|
cls.metadata.drop_all(engine)
|
|
|
|
|
2020-07-01 19:24:03 +00:00
|
|
|
|
|
|
|
class Admin(Model):
|
|
|
|
id: Integer(primary_key=True) = None
|
|
|
|
email: Text(unique=True)
|
|
|
|
passhash: Text()
|
|
|
|
|
|
|
|
class Mapping(Mapping):
|
|
|
|
table_name = 'admins'
|
|
|
|
|
|
|
|
|
|
|
|
class Hood(Model):
|
|
|
|
id: Integer(primary_key=True) = None
|
|
|
|
name: Text(unique=True)
|
|
|
|
landingpage: Text()
|
2020-07-18 11:53:11 +00:00
|
|
|
email_enabled: Boolean() = True
|
2020-07-01 19:24:03 +00:00
|
|
|
|
|
|
|
class Mapping(Mapping):
|
|
|
|
table_name = 'hoods'
|
|
|
|
|
|
|
|
|
|
|
|
class AdminHoodRelation(Model):
|
|
|
|
id: Integer(primary_key=True) = None
|
|
|
|
admin: ForeignKey(Admin)
|
|
|
|
hood: ForeignKey(Hood)
|
|
|
|
|
|
|
|
class Mapping(Mapping):
|
|
|
|
table_name = 'admin_hood_relations'
|
|
|
|
|
|
|
|
|
|
|
|
class Trigger(Model):
|
|
|
|
id: Integer(primary_key=True) = None
|
|
|
|
hood: ForeignKey(Hood)
|
|
|
|
pattern: Text()
|
|
|
|
|
|
|
|
class Mapping(Mapping):
|
|
|
|
table_name = 'triggers'
|
|
|
|
|
|
|
|
|
|
|
|
class BadWord(Model):
|
|
|
|
id: Integer(primary_key=True) = None
|
|
|
|
hood: ForeignKey(Hood)
|
|
|
|
pattern: Text()
|
|
|
|
|
|
|
|
class Mapping(Mapping):
|
|
|
|
table_name = 'badwords'
|