mirror of
https://github.com/simple-login/app.git
synced 2025-02-25 00:03:03 +08:00
add client.referral_id column
This commit is contained in:
parent
a99ac24b72
commit
f19655fc93
2 changed files with 37 additions and 1 deletions
|
@ -985,8 +985,13 @@ class Client(Base, ModelMixin):
|
|||
approved = sa.Column(sa.Boolean, nullable=False, default=False, server_default="0")
|
||||
description = sa.Column(sa.Text, nullable=True)
|
||||
|
||||
# a referral can be attached to a client
|
||||
# so all users who sign up via the authorize screen are counted towards this referral
|
||||
referral_id = sa.Column(sa.ForeignKey("referral.id"), nullable=True)
|
||||
|
||||
icon = orm.relationship(File)
|
||||
user = orm.relationship(User)
|
||||
referral = orm.relationship("Referral")
|
||||
|
||||
def nb_user(self):
|
||||
return ClientUser.filter_by(client_id=self.id).count()
|
||||
|
@ -2251,7 +2256,7 @@ class Referral(Base, ModelMixin):
|
|||
|
||||
code = sa.Column(sa.String(128), unique=True, nullable=False)
|
||||
|
||||
user = orm.relationship(User, foreign_keys=[user_id])
|
||||
user = orm.relationship(User, foreign_keys=[user_id], backref="referrals")
|
||||
|
||||
@property
|
||||
def nb_user(self) -> int:
|
||||
|
|
31
migrations/versions/2021_102611_d67eab226ecd_.py
Normal file
31
migrations/versions/2021_102611_d67eab226ecd_.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: d67eab226ecd
|
||||
Revises: a06066e3fbeb
|
||||
Create Date: 2021-10-26 11:35:13.448796
|
||||
|
||||
"""
|
||||
import sqlalchemy_utils
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'd67eab226ecd'
|
||||
down_revision = 'a06066e3fbeb'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('client', sa.Column('referral_id', sa.Integer(), nullable=True))
|
||||
op.create_foreign_key(None, 'client', 'referral', ['referral_id'], ['id'])
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(None, 'client', type_='foreignkey')
|
||||
op.drop_column('client', 'referral_id')
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in a new issue