Skip to content

Commit ac72f2c

Browse files
committed
PB-1489: Skip non-prod datasets in bod_sync
1 parent 8c1b576 commit ac72f2c

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

app/bod/management/commands/bod_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def import_datasets(self) -> None:
254254
"""
255255

256256
processed = set()
257-
for bod_dataset in BodDataset.objects.all():
257+
for bod_dataset in BodDataset.objects.filter(staging='prod').all():
258258
# Keep track of processed BOD datasets for orphan removal
259259
legacy_id = bod_dataset.id
260260
processed.add(legacy_id)

app/bod/migrations/0001_initial.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 5.0.9 on 2024-10-03 13:55
1+
# Generated by Django 5.0.12 on 2025-03-11 11:57
22

33
from django.conf import settings
44
from django.db import migrations
@@ -39,6 +39,7 @@ class Migration(migrations.Migration):
3939
('id', models.AutoField(primary_key=True, serialize=False, unique=True)),
4040
('id_dataset', models.TextField()),
4141
('fk_contactorganisation_id', models.IntegerField(blank=True, null=True)),
42+
('staging', models.TextField(blank=True, null=True)),
4243
],
4344
options={
4445
'db_table': 'dataset',

app/bod/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class BodDataset(models.Model):
2828
id = models.AutoField(unique=True, primary_key=True)
2929
id_dataset = models.TextField()
3030
fk_contactorganisation_id = models.IntegerField(blank=True, null=True)
31+
staging = models.TextField(blank=True, null=True)
3132

3233
class Meta:
3334
managed = settings.TESTING

app/tests/bod/test_bod_sync_command.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def fixture_bod_dataset(bod_contact_organisation):
4141
yield BodDataset.objects.create(
4242
id=170,
4343
id_dataset="ch.bafu.auen-vegetationskarten",
44-
fk_contactorganisation_id=bod_contact_organisation.pk_contactorganisation_id
44+
fk_contactorganisation_id=bod_contact_organisation.pk_contactorganisation_id,
45+
staging="prod"
4546
)
4647

4748

@@ -237,7 +238,7 @@ def test_command_imports_datasets(bod_contact_organisation, bod_dataset):
237238
assert dataset.dataset_id == "ch.bafu.auen-vegetationskarten"
238239

239240

240-
def test_command_skips_invalid_datasets(bod_contact_organisation, bod_dataset):
241+
def test_command_skips_invalid_datasets(bod_dataset):
241242
out = StringIO()
242243
call_command(
243244
"bod_sync", providers=False, attributions=False, datasets=True, verbosity=2, stdout=out
@@ -252,6 +253,19 @@ def test_command_skips_invalid_datasets(bod_contact_organisation, bod_dataset):
252253
assert Dataset.objects.count() == 0
253254

254255

256+
def test_command_skips_non_prod_datasets(bod_dataset):
257+
bod_dataset.staging = 'test'
258+
259+
out = StringIO()
260+
call_command(
261+
"bod_sync", providers=False, attributions=False, datasets=True, verbosity=2, stdout=out
262+
)
263+
assert 'nothing to be done, already in sync' in out.getvalue()
264+
assert Provider.objects.count() == 0
265+
assert Attribution.objects.count() == 0
266+
assert Dataset.objects.count() == 0
267+
268+
255269
def test_command_updates(bod_contact_organisation, bod_dataset):
256270
# Add objects that will be updated
257271
provider = Provider.objects.create(

0 commit comments

Comments
 (0)