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

migration to delete all diffs b/c some could be incorrect #4581

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/infrahub/core/graph/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRAPH_VERSION = 15
GRAPH_VERSION = 16
2 changes: 2 additions & 0 deletions backend/infrahub/core/migrations/graph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .m013_convert_git_password_credential import Migration013
from .m014_remove_index_attr_value import Migration014
from .m015_diff_format_update import Migration015
from .m016_diff_delete_bug_fix import Migration016

if TYPE_CHECKING:
from infrahub.core.root import Root
Expand All @@ -39,6 +40,7 @@
Migration013,
Migration014,
Migration015,
Migration016,
]


Expand Down
36 changes: 36 additions & 0 deletions backend/infrahub/core/migrations/graph/m016_diff_delete_bug_fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from infrahub.core import registry
from infrahub.core.diff.repository.repository import DiffRepository
from infrahub.core.migrations.shared import MigrationResult
from infrahub.dependencies.registry import build_component_registry, get_component_registry
from infrahub.log import get_logger

from ..shared import ArbitraryMigration

if TYPE_CHECKING:
from infrahub.database import InfrahubDatabase

log = get_logger()


class Migration016(ArbitraryMigration):
name: str = "016_diff_delete_bug_fix_update"
minimum_version: int = 15

async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult:
result = MigrationResult()

return result

async def execute(self, db: InfrahubDatabase) -> MigrationResult:
default_branch = registry.get_branch_from_registry()
build_component_registry()
component_registry = get_component_registry()
diff_repo = await component_registry.get_component(DiffRepository, db=db, branch=default_branch)

diff_roots = await diff_repo.get_empty_roots()
await diff_repo.delete_diff_roots(diff_root_uuids=[d.uuid for d in diff_roots])
return MigrationResult()
Loading