From 9329cf04ad69d1c3c1f597d274d2ef997bb75a47 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sun, 13 Dec 2020 19:05:43 +0100 Subject: [PATCH] Create CoinbaseSubscription model --- app/models.py | 20 ++++++++++ .../versions/2020_121319_a20aeb9b0eac_.py | 39 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 migrations/versions/2020_121319_a20aeb9b0eac_.py diff --git a/app/models.py b/app/models.py index b9f1d647..0b6ec86a 100644 --- a/app/models.py +++ b/app/models.py @@ -1434,6 +1434,26 @@ class ManualSubscription(db.Model, ModelMixin): user = db.relationship(User) +class CoinbaseSubscription(db.Model, ModelMixin): + """ + For subscriptions using Coinbase Commerce + """ + + user_id = db.Column( + db.ForeignKey(User.id, ondelete="cascade"), nullable=False, unique=True + ) + + # an reminder is sent several days before the subscription ends + end_at = db.Column(ArrowType, nullable=False) + + # the Coinbase code + code = db.Column(db.String(64), nullable=True) + + user = db.relationship(User) + + def is_active(self): + return self.end_at > arrow.now() + # https://help.apple.com/app-store-connect/#/dev58bda3212 _APPLE_GRACE_PERIOD_DAYS = 16 diff --git a/migrations/versions/2020_121319_a20aeb9b0eac_.py b/migrations/versions/2020_121319_a20aeb9b0eac_.py new file mode 100644 index 00000000..9de5ea05 --- /dev/null +++ b/migrations/versions/2020_121319_a20aeb9b0eac_.py @@ -0,0 +1,39 @@ +"""empty message + +Revision ID: a20aeb9b0eac +Revises: 780a8344914b +Create Date: 2020-12-13 19:04:46.771429 + +""" +import sqlalchemy_utils +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'a20aeb9b0eac' +down_revision = '780a8344914b' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('coinbase_subscription', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('created_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=False), + sa.Column('updated_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True), + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('end_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=False), + sa.Column('code', sa.String(length=64), nullable=True), + sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='cascade'), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('user_id') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('coinbase_subscription') + # ### end Alembic commands ###