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

Manage subscriptions_search view through SQLalchemy #724

Closed
Mark90 opened this issue Jul 29, 2024 · 1 comment · Fixed by #877
Closed

Manage subscriptions_search view through SQLalchemy #724

Mark90 opened this issue Jul 29, 2024 · 1 comment · Fixed by #877
Assignees
Labels
bug Something isn't working maintenance Keeping the framework up to date

Comments

@Mark90
Copy link
Contributor

Mark90 commented Jul 29, 2024

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 Mark90 added the maintenance Keeping the framework up to date label Jul 29, 2024
@hanstrompert hanstrompert added the bug Something isn't working label Mar 3, 2025
@hanstrompert
Copy link
Member

Can probably be solved by adding extra meta data to the model.

@torkashvand torkashvand self-assigned this Mar 5, 2025
torkashvand pushed a commit that referenced this issue Mar 6, 2025
…togeneration

The subscriptions_search view is a manually created materialized view and should not be managed by Alembic. This commit adds an info flag to the view’s table definition and updates the include_object logic to skip any table marked as a materialized view. This prevents erroneous migration generation for subscriptions_search. Resolves #724.
torkashvand pushed a commit that referenced this issue Mar 6, 2025
…togeneration

The subscriptions_search view is a manually created materialized view and should not be managed by Alembic. This commit adds an info flag to the view’s table definition and updates the include_object logic to skip any table marked as a materialized view. This prevents erroneous migration generation for subscriptions_search. Resolves #724.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working maintenance Keeping the framework up to date
Projects
None yet
3 participants