Skip to content

Commit 2e3cdca

Browse files
authored
migration to delete all diffs b/c some could be incorrect (#4581)
1 parent 38458d2 commit 2e3cdca

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
GRAPH_VERSION = 15
1+
GRAPH_VERSION = 16

backend/infrahub/core/migrations/graph/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .m013_convert_git_password_credential import Migration013
1818
from .m014_remove_index_attr_value import Migration014
1919
from .m015_diff_format_update import Migration015
20+
from .m016_diff_delete_bug_fix import Migration016
2021

2122
if TYPE_CHECKING:
2223
from infrahub.core.root import Root
@@ -39,6 +40,7 @@
3940
Migration013,
4041
Migration014,
4142
Migration015,
43+
Migration016,
4244
]
4345

4446

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
from infrahub.core import registry
6+
from infrahub.core.diff.repository.repository import DiffRepository
7+
from infrahub.core.migrations.shared import MigrationResult
8+
from infrahub.dependencies.registry import build_component_registry, get_component_registry
9+
from infrahub.log import get_logger
10+
11+
from ..shared import ArbitraryMigration
12+
13+
if TYPE_CHECKING:
14+
from infrahub.database import InfrahubDatabase
15+
16+
log = get_logger()
17+
18+
19+
class Migration016(ArbitraryMigration):
20+
name: str = "016_diff_delete_bug_fix_update"
21+
minimum_version: int = 15
22+
23+
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult:
24+
result = MigrationResult()
25+
26+
return result
27+
28+
async def execute(self, db: InfrahubDatabase) -> MigrationResult:
29+
default_branch = registry.get_branch_from_registry()
30+
build_component_registry()
31+
component_registry = get_component_registry()
32+
diff_repo = await component_registry.get_component(DiffRepository, db=db, branch=default_branch)
33+
34+
diff_roots = await diff_repo.get_empty_roots()
35+
await diff_repo.delete_diff_roots(diff_root_uuids=[d.uuid for d in diff_roots])
36+
return MigrationResult()

0 commit comments

Comments
 (0)