orchestrator-core icon indicating copy to clipboard operation
orchestrator-core copied to clipboard

Manage subscriptions_search view through SQLalchemy

Open Mark90 opened this issue 1 year ago • 0 comments

subscriptions_search is a materialized view created manually through a migration. When running alembic's revision it creates the following migration

def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "subscriptions_search",
        sa.Column("subscription_id", sqlalchemy_utils.types.uuid.UUIDType(), nullable=False),
        sa.Column("tsv", sqlalchemy_utils.types.ts_vector.TSVectorType(), nullable=True),
        sa.ForeignKeyConstraint(
            ["subscription_id"],
            ["subscriptions.subscription_id"],
        ),
        sa.PrimaryKeyConstraint("subscription_id"),
    )
    op.create_index(
        op.f("ix_subscriptions_search_subscription_id"), "subscriptions_search", ["subscription_id"], unique=False
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_subscriptions_search_subscription_id"), table_name="subscriptions_search")
    op.drop_table("subscriptions_search")
    # ### end Alembic commands ###

With the following log messages:

2024-07-29 13:14:47 [info     ] Detected added table 'subscriptions_search' [alembic.autogenerate.compare]
2024-07-29 13:14:47 [info     ] Detected added index ''ix_subscriptions_search_subscription_id'' on '('subscription_id',)' [alembic.autogenerate.compare]

This is not correct and should be fixed by preferably modifying orchestrator.db.models.SubscriptionSearchView so that alembic recognizes it as a materialized view. If that is not possible, the model should be excluded from alembic altogether.

Mark90 avatar Jul 29 '24 13:07 Mark90