diff --git a/apps/ops/migrations/0028_auto_20230213_1503.py b/apps/ops/migrations/0028_auto_20230213_1503.py new file mode 100644 index 000000000..dbb6c3b90 --- /dev/null +++ b/apps/ops/migrations/0028_auto_20230213_1503.py @@ -0,0 +1,31 @@ +# Generated by Django 3.2.16 on 2023-02-13 07:03 + +from django.conf import settings +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('ops', '0027_auto_20230206_1927'), + ] + + operations = [ + migrations.AlterModelOptions( + name='playbook', + options={'ordering': ['date_created']}, + ), + migrations.AlterUniqueTogether( + name='adhoc', + unique_together={('name', 'org_id', 'creator')}, + ), + migrations.AlterUniqueTogether( + name='job', + unique_together={('name', 'org_id', 'creator')}, + ), + migrations.AlterUniqueTogether( + name='playbook', + unique_together={('name', 'org_id', 'creator')}, + ), + ] diff --git a/apps/ops/models/adhoc.py b/apps/ops/models/adhoc.py index b6c84183d..5718252e3 100644 --- a/apps/ops/models/adhoc.py +++ b/apps/ops/models/adhoc.py @@ -17,7 +17,6 @@ logger = get_logger(__file__) class AdHoc(JMSOrgBaseModel): - id = models.UUIDField(default=uuid.uuid4, primary_key=True) name = models.CharField(max_length=128, verbose_name=_('Name')) pattern = models.CharField(max_length=1024, verbose_name=_("Pattern"), default='all') @@ -42,4 +41,5 @@ class AdHoc(JMSOrgBaseModel): return "{}: {}".format(self.module, self.args) class Meta: + unique_together = [('name', 'org_id', 'creator')] verbose_name = _("AdHoc") diff --git a/apps/ops/models/job.py b/apps/ops/models/job.py index ebc6b6dca..c0e45529b 100644 --- a/apps/ops/models/job.py +++ b/apps/ops/models/job.py @@ -96,6 +96,7 @@ class Job(JMSOrgBaseModel, PeriodTaskModelMixin): class Meta: verbose_name = _("Job") + unique_together = [('name', 'org_id', 'creator')] ordering = ['date_created'] diff --git a/apps/ops/models/playbook.py b/apps/ops/models/playbook.py index 0e649532e..efcd87730 100644 --- a/apps/ops/models/playbook.py +++ b/apps/ops/models/playbook.py @@ -33,3 +33,7 @@ class Playbook(JMSOrgBaseModel): def work_dir(self): work_dir = os.path.join(settings.DATA_DIR, "ops", "playbook", self.id.__str__()) return work_dir + + class Meta: + unique_together = [('name', 'org_id', 'creator')] + ordering = ['date_created']