diff --git a/app/dashboard/views/lifetime_licence.py b/app/dashboard/views/lifetime_licence.py index f1cdc865..2a2a8130 100644 --- a/app/dashboard/views/lifetime_licence.py +++ b/app/dashboard/views/lifetime_licence.py @@ -37,6 +37,7 @@ def lifetime_licence(): if coupon and coupon.nb_used > 0: coupon.nb_used -= 1 current_user.lifetime = True + current_user.lifetime_coupon_id = coupon.id if coupon.paid: current_user.paid_lifetime = True db.session.commit() diff --git a/app/models.py b/app/models.py index 63dd5a1c..28ad898b 100644 --- a/app/models.py +++ b/app/models.py @@ -266,6 +266,11 @@ class User(db.Model, ModelMixin, UserMixin, PasswordOracle): paid_lifetime = db.Column( db.Boolean, default=False, nullable=False, server_default="0" ) + lifetime_coupon_id = db.Column( + db.ForeignKey("lifetime_coupon.id", ondelete="SET NULL"), + nullable=True, + default=None, + ) # user can use all premium features until this date trial_end = db.Column( diff --git a/migrations/versions/2021_100417_0b1c9ea11aef_.py b/migrations/versions/2021_100417_0b1c9ea11aef_.py new file mode 100644 index 00000000..1c4f1309 --- /dev/null +++ b/migrations/versions/2021_100417_0b1c9ea11aef_.py @@ -0,0 +1,31 @@ +"""empty message + +Revision ID: 0b1c9ea11aef +Revises: 4913cb3f5a05 +Create Date: 2021-10-04 17:14:01.414396 + +""" +import sqlalchemy_utils +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '0b1c9ea11aef' +down_revision = '4913cb3f5a05' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('users', sa.Column('lifetime_coupon_id', sa.Integer(), nullable=True)) + op.create_foreign_key(None, 'users', 'lifetime_coupon', ['lifetime_coupon_id'], ['id'], ondelete='SET NULL') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(None, 'users', type_='foreignkey') + op.drop_column('users', 'lifetime_coupon_id') + # ### end Alembic commands ###