Skip to content

Commit

Permalink
Add index to scans.status (#171)
Browse files Browse the repository at this point in the history
* perf: Add index to `scans.status`

* Bump python from `58ae46e` to `c499230` (#167)

Bumps python from `58ae46e` to `c499230`.

---
updated-dependencies:
- dependency-name: python
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* perf: Add index to `download_urls.scan_id`

* chore: Update the index's down_revision

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bradley Reynolds <[email protected]>
  • Loading branch information
3 people committed Sep 27, 2023
1 parent 45cece3 commit eb377af
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
36 changes: 36 additions & 0 deletions alembic/versions/9ac5b6c4a36b_add_scans_status_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""add scans status index
Revision ID: 9ac5b6c4a36b
Revises: b6c8e52cd4f5f
Create Date: 2023-09-23 00:07:33.273030
"""
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "9ac5b6c4a36b"
down_revision = "b6c8e52cd4f5f"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_index(
op.f("ix_scans_status"),
"scans",
["status"],
unique=False,
postgresql_where=sa.text("status = 'QUEUED' OR status = 'PENDING'"),
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(
op.f("ix_scans_status"), table_name="scans", postgresql_where=sa.text("status = 'QUEUED' OR status = 'PENDING'")
)
# ### end Alembic commands ###
5 changes: 5 additions & 0 deletions src/mainframe/models/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import uuid
from datetime import datetime, timezone
from enum import Enum
from operator import or_
from typing import Optional

from sqlalchemy import (
Column,
DateTime,
FetchedValue,
ForeignKey,
Index,
Table,
UniqueConstraint,
)
Expand Down Expand Up @@ -88,6 +90,9 @@ class Scan(Base):
commit_hash: Mapped[Optional[str]]


Index(None, Scan.status, postgresql_where=or_(Scan.status == Status.QUEUED, Scan.status == Status.PENDING))


class DownloadURL(Base):
"""Download URLs"""

Expand Down

0 comments on commit eb377af

Please sign in to comment.