Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a last_used column for the api_key #2091

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ class ApiKey(BaseModel, Versioned):
created_by = db.relationship("User")
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey("users.id"), index=True, nullable=False)
compromised_key_info = db.Column(JSONB(none_as_null=True), nullable=True, default={})
last_used_timestamp = db.Column(db.DateTime, index=False, unique=False, nullable=True, default=None)

__table_args__ = (
Index(
Expand Down
22 changes: 22 additions & 0 deletions migrations/versions/0443_add_apikey_last_used_column.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Revision ID: 0443_add_apikey_last_used_column
Revises: 0442_add_heartbeat_templates
Create Date: 2022-09-21 00:00:00
"""
from datetime import datetime

import sqlalchemy as sa
from alembic import op

revision = "0443_add_apikey_last_used_column"
down_revision = "0442_add_heartbeat_templates"


def upgrade():
op.add_column("api_keys", sa.Column("last_used_timestamp", sa.DateTime(), nullable=True))
op.add_column("api_keys_history", sa.Column("last_used_timestamp", sa.DateTime(), nullable=True))


def downgrade():
op.drop_column("api_keys", "last_used_timestamp")
op.drop_column("api_keys_history", "last_used_timestamp")
1 change: 1 addition & 0 deletions tests/app/dao/test_api_key_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_save_api_key_should_create_new_api_key_and_history(sample_service):
assert len(all_api_keys) == 1
assert all_api_keys[0] == api_key
assert api_key.version == 1
assert api_key.last_used_timestamp is None

all_history = api_key.get_history_model().query.all()
assert len(all_history) == 1
Expand Down