diff --git a/app/models.py b/app/models.py index e93aefd3..1a77c3b2 100644 --- a/app/models.py +++ b/app/models.py @@ -173,6 +173,9 @@ class Hibp(db.Model, ModelMixin): name = db.Column(db.String(), nullable=False, unique=True, index=True) breached_aliases = db.relationship("Alias", secondary="alias_hibp") + description = db.Column(db.Text) + date = db.Column(ArrowType, nullable=True) + def __repr__(self): return f"" diff --git a/cron.py b/cron.py index 5e83ba6f..1f25dae7 100644 --- a/cron.py +++ b/cron.py @@ -729,7 +729,9 @@ async def check_hibp(): LOG.d("Updating list of known breaches") r = requests.get("https://haveibeenpwned.com/api/v3/breaches") for entry in r.json(): - Hibp.get_or_create(name=entry["Name"]) + hibp_entry = Hibp.get_or_create(name=entry["Name"]) + hibp_entry.date = arrow.get(entry["BreachDate"]) + hibp_entry.description = entry["Description"] db.session.commit() LOG.d("Updated list of known breaches") diff --git a/migrations/versions/2021_072908_05e3af59929a_.py b/migrations/versions/2021_072908_05e3af59929a_.py new file mode 100644 index 00000000..cf41b819 --- /dev/null +++ b/migrations/versions/2021_072908_05e3af59929a_.py @@ -0,0 +1,31 @@ +"""empty message + +Revision ID: 05e3af59929a +Revises: dfee471558bd +Create Date: 2021-07-29 08:50:42.388094 + +""" +import sqlalchemy_utils +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '05e3af59929a' +down_revision = 'dfee471558bd' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('hibp', sa.Column('date', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True)) + op.add_column('hibp', sa.Column('description', sa.Text(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('hibp', 'description') + op.drop_column('hibp', 'date') + # ### end Alembic commands ###