From e30185d85ea977c80980bd92eef71afd1dfd4119 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Thu, 1 Jul 2021 00:30:20 -0700 Subject: [PATCH] flesh out schemas a bit --- xmrbackers/factory.py | 1 - xmrbackers/models.py | 49 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/xmrbackers/factory.py b/xmrbackers/factory.py index 98a88e9..8e9660a 100644 --- a/xmrbackers/factory.py +++ b/xmrbackers/factory.py @@ -23,5 +23,4 @@ def create_app(): app.register_blueprint(meta.bp) app.register_blueprint(api.bp) app.register_blueprint(filters.bp) - return cli(app) diff --git a/xmrbackers/models.py b/xmrbackers/models.py index 73cb7ec..05913e7 100644 --- a/xmrbackers/models.py +++ b/xmrbackers/models.py @@ -1,22 +1,17 @@ from datetime import datetime -from uuid import uuid4 import peewee as pw -from peewee import PostgresqlDatabase, SQL, ForeignKeyField from xmrbackers import config -db = PostgresqlDatabase( +db = pw.PostgresqlDatabase( config.DB_NAME, user=config.DB_USER, password=config.DB_PASS, host=config.DB_HOST, ) -def rand_id(): - return uuid4().hex - class Creator(pw.Model): id = pw.AutoField() @@ -43,3 +38,45 @@ class Backer(pw.Model): class Meta: database = db + + +class SubscriptionMeta(pw.Model): + id = pw.AutoField() + create_date = pw.DateTimeField(default=datetime.now) + creator = pw.ForeignKeyField(Creator) + atomic_xmr = pw.BigIntegerField() + number_hours = pw.IntegerField() + + def get_end_date(self) -> datetime: + # some timedelta shiz + pass + + class Meta: + database = db + + +class Subscription(pw.Model): + id = pw.AutoField() + subscribe_date = pw.DateTimeField(default=datetime.now) + active = pw.BooleanField(default=True) + creator = pw.ForeignKeyField(Creator) + backer = pw.ForeignKeyField(Backer) + meta = pw.ForeignKeyField(SubscriptionMeta) + xmr_address = pw.CharField(unique=True) + xmr_acct_idx = pw.BigIntegerField(unique=True) # in case it gets many subscribers + xmr_addr_idx = pw.BigIntegerField(unique=True) + + class Meta: + database = db + +class TextPost(pw.Model): + id = pw.AutoField() + post_date = pw.DateTimeField(default=datetime.now) + hidden = pw.BooleanField(default=False) + content = pw.TextField() + title = pw.CharField() + last_edit_date = pw.DateTimeField(default=datetime.now) + creator = pw.ForeignKeyField(Creator) + + class Meta: + database = db