Skip to content

Commit

Permalink
Add in composite index for invoice_status_code and payment_account_id (
Browse files Browse the repository at this point in the history
  • Loading branch information
seeker25 authored Jul 16, 2024
1 parent 3a5557f commit cef2cab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pay-api/migrations/versions/2024_07_16_f98666d9809a_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Add in composite index for invoice_status_code and payment_account_id so our payment blocker check is fast.
Revision ID: f98666d9809a
Revises: f921d5e32835
Create Date: 2024-07-16 14:26:07.469225
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'f98666d9809a'
down_revision = 'f921d5e32835'
branch_labels = None
depends_on = None


def upgrade():
with op.batch_alter_table('invoices', schema=None) as batch_op:
batch_op.create_index('idx_invoice_invoice_status_code_payment_account_idx', ['payment_account_id', 'invoice_status_code'], unique=False)

def downgrade():
with op.batch_alter_table('invoices', schema=None) as batch_op:
batch_op.drop_index('idx_invoice_invoice_status_code_payment_account_idx')
4 changes: 4 additions & 0 deletions pay-api/src/pay_api/models/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ class Invoice(Audit): # pylint: disable=too-many-instance-attributes
references = relationship('InvoiceReference', lazy='joined')
corp_type = relationship('CorpType', foreign_keys=[corp_type_code], lazy='select', innerjoin=True)

__table_args__ = (
db.Index('idx_invoice_invoice_status_code_payment_account_idx', payment_account_id, invoice_status_code),
)

@classmethod
def update_invoices_for_revenue_updates(cls, fee_distribution_id: int):
"""Find and update all invoices using the distribution id."""
Expand Down

0 comments on commit cef2cab

Please sign in to comment.