From nobody Fri Apr 19 04:57:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=patchew-devel-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1663681181; cv=none; d=zohomail.com; s=zohoarc; b=dPjIFeXBDbg1pRvGnEsnn5ggT+tqaCCXO8Wez/x4mY4d+d2zU1O7xdVHaT2ZPuSKINkL3PZsacP8xsW8DBI0khDC/kgpB9zZJ7zneH9HPz409LjfKeVsc+gdoytAi65r/FHvd8JqdbSF5nOowkjp1uZybzu5Aiowgkhf+0te/FA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663681181; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nAXqrQWD0FeogBOofTPbz8ZpG48ZeYWs4zcTIWrIHyo=; b=KMqb4DlkrJJwmvtROffZCkYTWHRSwo6p61LkrFIZppoPuJuRAr4azc74ZOIHrIfPjVMACJkDKW0CWuLNhz+pe2GExRj1A/N/QDPvTbM0f56u1gYo4IEhPrgChnTaCNg57+TW1/MTLW6ioNhzgbytndzNlIpAMUlyoVe+YOEBYkc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1663681181209121.79937163636703; Tue, 20 Sep 2022 06:39:41 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-592-i8DddrN9No6b3zmzxOIFAw-1; Tue, 20 Sep 2022 09:39:38 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E7E511C08962; Tue, 20 Sep 2022 13:39:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFC2E40C6EC2; Tue, 20 Sep 2022 13:39:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8E0B519465A0; Tue, 20 Sep 2022 13:39:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B69691946588 for ; Tue, 20 Sep 2022 13:04:16 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A8444492B05; Tue, 20 Sep 2022 13:04:16 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast10.extmail.prod.ext.rdu2.redhat.com [10.11.55.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A119D492B04 for ; Tue, 20 Sep 2022 13:04:16 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5AE601E68191 for ; Tue, 20 Sep 2022 13:04:16 +0000 (UTC) Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-115-kBigYB0ONhe9JTreqmW9bA-1; Tue, 20 Sep 2022 09:04:12 -0400 Received: by mail-ej1-f71.google.com with SMTP id hp18-20020a1709073e1200b0078054727517so1372941ejc.0 for ; Tue, 20 Sep 2022 06:04:12 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id d6-20020a170906040600b00779dc23be62sm806586eja.120.2022.09.20.06.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 06:04:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663681180; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=nAXqrQWD0FeogBOofTPbz8ZpG48ZeYWs4zcTIWrIHyo=; b=JhcxDs4Pci9AlhPBzAyMP98MG7j9LuqFrJ6I9BMFkmwx08Emz+bCPXOhC103pwojTWBjaH coQ+QHFwcrOYw6HtNmkBJe58aj2hxKCOJEHN2kpNjvg6j12YCfCwlE1WrpG7ZZp9+IZ3Zl os/UsDZA3DnbJcvr+I1KJNo1RTV8k10= X-MC-Unique: i8DddrN9No6b3zmzxOIFAw-1 X-Original-To: patchew-devel@listman.corp.redhat.com X-MC-Unique: kBigYB0ONhe9JTreqmW9bA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=d9hn503PdNfvpiHaykCqG7EeddCGyrDCH7qbemMuHS0=; b=bnTsIw8ZfQLlIRLZwSSV+fTkb8vwOK7AZbxA2RXEw2Gp63JFkbOtc/CHrfROSzuNuv Z0dr6Sszs7xxldplZQOPvWuhpPwm/AxL+dcKAzl+gDHC2IfH3JImSZ1/JBr883rkSmYI li5xDghh+SlVCPFB8YJA4x5VaqkkcJVdj6Bw80Oqtyw761G4pR83rxUNJ9MPUboEsBoj yVvE3bmxqwvVhutHIXmjNHJbBeHJboqmuKxiYbOthODOEfV3cPN3z7dHHT0pbU197Sim U3OLiG8RPl2s0BGiwrPWo3MrvjDCU3l30bmW69KE/ZButZ3oYuIasJ2JQJFEG5ifQPmC TAhQ== X-Gm-Message-State: ACrzQf2/8ApcYFzCLrlSQjcS8qBdHXHB5PnRk4ZJdJDp53uvSmMqgiYU e6Sezp38kEAeEszrMWlMWRc+ApeYhYtmC7I4EgS8OTNzgn7BI3USCzNONpFGSqtfwccpTI3J17l AQ1E8awK6wHhKI1IIZn6wZiO1bxZ6knbbW897iIX4nmPLO5xtzIU65XM59p09s0o+chD6lozNfA == X-Received: by 2002:a17:907:9729:b0:77c:3742:137a with SMTP id jg41-20020a170907972900b0077c3742137amr16687749ejc.630.1663679051031; Tue, 20 Sep 2022 06:04:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Ni+7bGoACzpIbNlQcDN0BLKY2d25rAcS0f3sberktwrqO6+lbaleBRcCdiZJne/7BQ84Kyw== X-Received: by 2002:a17:907:9729:b0:77c:3742:137a with SMTP id jg41-20020a170907972900b0077c3742137amr16687719ejc.630.1663679050653; Tue, 20 Sep 2022 06:04:10 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Tue, 20 Sep 2022 15:04:02 +0200 Message-Id: <20220920130404.39806-3-pbonzini@redhat.com> In-Reply-To: <20220920130404.39806-1-pbonzini@redhat.com> References: <20220920130404.39806-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Subject: [Patchew-devel] [PATCH 2/4] models: populate denormalized project field X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dcaratti@redhat.com Errors-To: patchew-devel-bounces@redhat.com Sender: "Patchew-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1663681182360100001 Content-Type: text/plain; charset="utf-8" The field is now populated and need not be nullable. Signed-off-by: Paolo Bonzini --- api/migrations/0067_result_denormalize.py | 32 +++++++++++++++++++++++ api/migrations/0068_auto_20220919_1007.py | 19 ++++++++++++++ api/models.py | 2 +- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 api/migrations/0067_result_denormalize.py create mode 100644 api/migrations/0068_auto_20220919_1007.py diff --git a/api/migrations/0067_result_denormalize.py b/api/migrations/006= 7_result_denormalize.py new file mode 100644 index 0000000..8394256 --- /dev/null +++ b/api/migrations/0067_result_denormalize.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations +from django.db.models import F, Subquery, OuterRef + + +def populate_denormalized_project(apps, schema_editor): + Message =3D apps.get_model("api", "Message") + MessageResult =3D apps.get_model("api", "MessageResult") + ProjectResult =3D apps.get_model("api", "ProjectResult") + ProjectResult.objects.filter(project_denorm__isnull=3DTrue).update( + project_denorm=3D + Subquery(ProjectResult.objects.filter(result_ptr_id=3DOuterRef= ('pk')).values('project')[:1])) + MessageResult.objects.filter(project_denorm__isnull=3DTrue).update( + project_denorm=3D + Subquery(MessageResult.objects.filter(result_ptr_id=3DOuterRef= ('pk')).values('message__project')[:1])) + + +def populate_projectresult_project(apps, schema_editor): + ProjectResult =3D apps.get_model("api", "ProjectResult") + ProjectResult.update(project=3DF('project_denorm')) + + +class Migration(migrations.Migration): + + dependencies =3D [("api", "0066_auto_20220919_1004")] + + operations =3D [ + migrations.RunPython(populate_denormalized_project, populate_proje= ctresult_project) + ] + diff --git a/api/migrations/0068_auto_20220919_1007.py b/api/migrations/006= 8_auto_20220919_1007.py new file mode 100644 index 0000000..6e070a4 --- /dev/null +++ b/api/migrations/0068_auto_20220919_1007.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.14 on 2022-09-19 10:07 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies =3D [ + ('api', '0067_result_denormalize'), + ] + + operations =3D [ + migrations.AlterField( + model_name=3D'result', + name=3D'project_denorm', + field=3Dmodels.ForeignKey(on_delete=3Ddjango.db.models.deletio= n.CASCADE, related_name=3D'+', to=3D'api.project'), + ), + ] diff --git a/api/models.py b/api/models.py index 45c7f70..0728853 100644 --- a/api/models.py +++ b/api/models.py @@ -64,7 +64,7 @@ class Result(models.Model): data =3D jsonfield.JSONField(default=3D{}) =20 project_denorm =3D models.ForeignKey( - "Project", related_name=3D"+", on_delete=3Dmodels.CASCADE, null=3D= True + "Project", related_name=3D"+", on_delete=3Dmodels.CASCADE ) =20 class Meta: --=20 2.37.2 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://listman.redhat.com/mailman/listinfo/patchew-devel