-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
backend/alembic/versions/c7bf5721733e_add_has_been_indexed_to_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Add has_been_indexed to DocumentByConnectorCredentialPair | ||
Revision ID: c7bf5721733e | ||
Revises: fec3db967bf7 | ||
Create Date: 2025-01-13 12:39:05.831693 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "c7bf5721733e" | ||
down_revision = "fec3db967bf7" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# assume all existing rows have been indexed, no better approach | ||
op.add_column( | ||
"document_by_connector_credential_pair", | ||
sa.Column("has_been_indexed", sa.Boolean(), nullable=True), | ||
) | ||
op.execute( | ||
"UPDATE document_by_connector_credential_pair SET has_been_indexed = TRUE" | ||
) | ||
op.alter_column( | ||
"document_by_connector_credential_pair", | ||
"has_been_indexed", | ||
nullable=False, | ||
) | ||
|
||
# Add index to optimize get_document_counts_for_cc_pairs query pattern | ||
op.create_index( | ||
"idx_document_cc_pair_counts", | ||
"document_by_connector_credential_pair", | ||
["connector_id", "credential_id", "has_been_indexed"], | ||
unique=False, | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
# Remove the index first before removing the column | ||
op.drop_index( | ||
"idx_document_cc_pair_counts", | ||
table_name="document_by_connector_credential_pair", | ||
) | ||
op.drop_column("document_by_connector_credential_pair", "has_been_indexed") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters