From 16922c4918d0d450bd721edb20a6d6abc24c0eed Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Mon, 13 Feb 2023 15:05:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E5=94=AF=E4=B8=80=E6=A0=A1=E9=AA=8C=20(#9518?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 增加作业中心唯一校验 * fix: 增加迁移文件 --------- Co-authored-by: Aaron3S --- .../ops/migrations/0028_auto_20230213_1503.py | 31 +++++++++++++++++++ apps/ops/models/adhoc.py | 2 +- apps/ops/models/job.py | 1 + apps/ops/models/playbook.py | 4 +++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 apps/ops/migrations/0028_auto_20230213_1503.py 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']