Skip to content

Commit 9af2033

Browse files
author
Riccardo Busetti
authored
feat(sourcemaps): Add deletion of bundles (#46366)
1 parent c2dc0fc commit 9af2033

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from ..base import ModelDeletionTask, ModelRelation
2+
3+
4+
class ArtifactBundleDeletionTask(ModelDeletionTask):
5+
def get_child_relations(self, instance):
6+
from sentry.models import (
7+
DebugIdArtifactBundle,
8+
ProjectArtifactBundle,
9+
ReleaseArtifactBundle,
10+
)
11+
12+
return [
13+
ModelRelation(ReleaseArtifactBundle, {"artifact_bundle_id": instance.id}),
14+
ModelRelation(DebugIdArtifactBundle, {"artifact_bundle_id": instance.id}),
15+
ModelRelation(ProjectArtifactBundle, {"artifact_bundle_id": instance.id}),
16+
]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from sentry.models import (
2+
ArtifactBundle,
3+
DebugIdArtifactBundle,
4+
File,
5+
ProjectArtifactBundle,
6+
ReleaseArtifactBundle,
7+
ScheduledDeletion,
8+
SourceFileType,
9+
)
10+
from sentry.tasks.deletion.scheduled import run_deletion
11+
from sentry.testutils import TransactionTestCase
12+
13+
14+
class DeleteArtifactBundleTest(TransactionTestCase):
15+
def test_simple(self):
16+
org = self.create_organization()
17+
project = self.create_project(organization=org)
18+
release = self.create_release(version="1.0", project=project)
19+
dist = release.add_dist("android")
20+
artifact_bundle = self.create_artifact_bundle(org=org)
21+
ReleaseArtifactBundle.objects.create(
22+
organization_id=org.id,
23+
release_name=release.version,
24+
dist_name=dist.name,
25+
artifact_bundle=artifact_bundle,
26+
)
27+
DebugIdArtifactBundle.objects.create(
28+
organization_id=org.id,
29+
debug_id="c29728de-4dbd-4c08-bd50-7509e1ee2535",
30+
source_file_type=SourceFileType.MINIFIED_SOURCE.value,
31+
artifact_bundle=artifact_bundle,
32+
)
33+
ProjectArtifactBundle.objects.create(
34+
organization_id=org.id, project_id=project.id, artifact_bundle=artifact_bundle
35+
)
36+
37+
deletion = ScheduledDeletion.schedule(artifact_bundle, days=0)
38+
deletion.update(in_progress=True)
39+
40+
with self.tasks():
41+
run_deletion(deletion.id)
42+
43+
assert not ArtifactBundle.objects.filter(id=artifact_bundle.id).exists()
44+
assert not ReleaseArtifactBundle.objects.filter(artifact_bundle=artifact_bundle).exists()
45+
assert not DebugIdArtifactBundle.objects.filter(artifact_bundle=artifact_bundle).exists()
46+
assert not ProjectArtifactBundle.objects.filter(artifact_bundle=artifact_bundle).exists()
47+
assert not File.objects.filter(id=artifact_bundle.file.id).exists()

0 commit comments

Comments
 (0)