Skip to content

Commit

Permalink
[#724] Exclude subscriptions_search materialized view from Alembic au…
Browse files Browse the repository at this point in the history
…togeneration (#877)

* [#724] Exclude subscriptions_search materialized view from Alembic autogeneration

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.

---------

Co-authored-by: Mohammad Torkashvand <[email protected]>
  • Loading branch information
torkashvand and torkashvandmt authored Mar 7, 2025
1 parent 712df12 commit 438d1a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions orchestrator/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ def find_by_subscription_id(subscription_id: str) -> SubscriptionMetadataTable |

class SubscriptionSearchView(BaseModel):
__tablename__ = "subscriptions_search"
__table_args__ = {"info": {"materialized_view": True}}

subscription_id = mapped_column(
UUIDType, ForeignKey("subscriptions.subscription_id"), nullable=False, index=True, primary_key=True
)
Expand Down
15 changes: 14 additions & 1 deletion orchestrator/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
# ... etc.


def include_object(object, name, type_, reflected, compare_to): # type: ignore
"""Determines if an object should be included."""

if type_ == "table" and object.info.get("materialized_view", False):
return False
return True


def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
Expand All @@ -55,7 +63,11 @@ def run_migrations_offline() -> None:
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True, dialect_opts={"paramstyle": "named"}
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
include_object=include_object,
)

with context.begin_transaction():
Expand Down Expand Up @@ -90,6 +102,7 @@ def process_revision_directives(context, revision, directives): # type: ignore
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
compare_type=True,
include_object=include_object,
)

try:
Expand Down

0 comments on commit 438d1a2

Please sign in to comment.