2023-04-16 09:11:08 -04:00
|
|
|
from peewee import Model
|
|
|
|
from peewee import BigIntegerField, CharField, DateTimeField, DateField, ForeignKeyField
|
2022-11-26 12:22:25 -05:00
|
|
|
from playhouse.db_url import connect
|
2022-08-29 12:10:44 -04:00
|
|
|
|
2022-12-17 07:36:47 -05:00
|
|
|
from datetime import date, datetime
|
2023-04-16 09:11:08 -04:00
|
|
|
from config import db_url
|
2022-12-17 07:36:47 -05:00
|
|
|
|
2022-11-26 12:22:25 -05:00
|
|
|
db = connect(db_url)
|
2022-08-29 12:10:44 -04:00
|
|
|
|
2023-04-16 09:11:08 -04:00
|
|
|
|
2022-08-29 12:10:44 -04:00
|
|
|
class WebUser(Model):
|
|
|
|
username = CharField()
|
|
|
|
password_hash = CharField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
db_table = "webusers"
|
|
|
|
database = db
|
2022-12-11 08:51:44 -05:00
|
|
|
|
2023-04-16 09:11:08 -04:00
|
|
|
|
2022-12-11 08:51:44 -05:00
|
|
|
class Member(Model):
|
2023-04-16 09:11:08 -04:00
|
|
|
user_id = BigIntegerField()
|
2022-12-11 08:51:44 -05:00
|
|
|
first_name = CharField()
|
2023-04-16 09:11:08 -04:00
|
|
|
username = CharField(null=True)
|
2022-12-11 08:51:44 -05:00
|
|
|
|
|
|
|
role = CharField(default="member")
|
|
|
|
|
|
|
|
warns = BigIntegerField(default=0)
|
|
|
|
|
2023-04-16 09:11:08 -04:00
|
|
|
joined = DateField(default=date.today())
|
2022-12-11 08:51:44 -05:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
db_table = "members"
|
|
|
|
database = db
|
2022-08-29 12:10:44 -04:00
|
|
|
|
2023-04-16 09:11:08 -04:00
|
|
|
|
2022-12-11 08:51:44 -05:00
|
|
|
class Message(Model):
|
2023-04-16 09:11:08 -04:00
|
|
|
user = ForeignKeyField(Member, lazy_load=True)
|
|
|
|
timestamp = DateTimeField(default=datetime.now())
|
2022-12-14 09:12:57 -05:00
|
|
|
|
2022-12-11 08:51:44 -05:00
|
|
|
class Meta:
|
|
|
|
db_table = "messages"
|
|
|
|
database = db
|
2022-08-29 12:10:44 -04:00
|
|
|
|
2023-04-16 09:11:08 -04:00
|
|
|
|
2022-11-26 12:22:25 -05:00
|
|
|
def build_database():
|
2023-04-16 09:11:08 -04:00
|
|
|
db.create_tables([WebUser, Message])
|