diff --git a/app/models.py b/app/models.py index 6725fb66..5325be24 100644 --- a/app/models.py +++ b/app/models.py @@ -850,6 +850,9 @@ class AliasUsedOn(db.Model, ModelMixin): ) alias_id = db.Column(db.ForeignKey(Alias.id, ondelete="cascade"), nullable=False) + user_id = db.Column(db.ForeignKey(User.id, ondelete="cascade"), nullable=True) + + alias = db.relationship(Alias) hostname = db.Column(db.String(1024), nullable=False) diff --git a/migrations/versions/2020_032012_4e4a759ac4b5_.py b/migrations/versions/2020_032012_4e4a759ac4b5_.py new file mode 100644 index 00000000..c3540641 --- /dev/null +++ b/migrations/versions/2020_032012_4e4a759ac4b5_.py @@ -0,0 +1,31 @@ +"""empty message + +Revision ID: 4e4a759ac4b5 +Revises: dbd80d290f04 +Create Date: 2020-03-20 12:12:45.699045 + +""" +import sqlalchemy_utils +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '4e4a759ac4b5' +down_revision = 'dbd80d290f04' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('alias_used_on', sa.Column('user_id', sa.Integer(), nullable=True)) + op.create_foreign_key(None, 'alias_used_on', 'users', ['user_id'], ['id'], ondelete='cascade') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(None, 'alias_used_on', type_='foreignkey') + op.drop_column('alias_used_on', 'user_id') + # ### end Alembic commands ###