From patchwork Fri Jul 16 17:19:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 1506263 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.a=rsa-sha256 header.s=google header.b=HDbCv48h; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GRJ0V2Hndz9sS8 for ; Sat, 17 Jul 2021 03:20:26 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GRJ0V10Tbz3bY9 for ; Sat, 17 Jul 2021 03:20:26 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.a=rsa-sha256 header.s=google header.b=HDbCv48h; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=axtens.net (client-ip=2607:f8b0:4864:20::529; helo=mail-pg1-x529.google.com; envelope-from=dja@axtens.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.a=rsa-sha256 header.s=google header.b=HDbCv48h; dkim-atps=neutral Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4GRHzv0BCSz30D7 for ; Sat, 17 Jul 2021 03:19:54 +1000 (AEST) Received: by mail-pg1-x529.google.com with SMTP id y17so10558542pgf.12 for ; Fri, 16 Jul 2021 10:19:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PJLmcuFEMWebS/aQn+lpRmkkxVL5X/mjrbub/O95eA8=; b=HDbCv48hxycErUz67Y2+dMe37DAFLxqroW0B2aMB1KSFE6joFeTOGEZl5g2sOuSIXQ OPaZNR6q3vciPsgroe/5xI0hp5Ze46tgiTP0lz6hVKwbUHkCBTpUPshJO+2sL1Cjq6e4 SNir7o/r3JwpKOqOn1UbBCIpn11PK39V5CjJs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PJLmcuFEMWebS/aQn+lpRmkkxVL5X/mjrbub/O95eA8=; b=hkSirlj0lCZXdXGbGK6EMbw6qXU0JGL3BMhj8dMXnD8Lpmm5TUr+5Hgc//7gHcHArv 7to93aIhGWbrdSnY4EstqbEpBGiiwjbtOjOs6PL5tX/RenCy0/bU839JRViWY5NxB0iU AYUEhnaiPSY3eZ6iJh/o84KNOjw2JnOEnV0LhpCxN+VDjDFAm+2KZL9sOj7FDj86Gud2 EBcdVDnpVjT+xnbfNt7vMnJ1i2+2HeBfmw1Mb8msirtAyAOSHcmYR38hfRVz8t2XDc3b hAHLZ9iELarhqPV+fIhKy8JHu0Mkw7Tr1XDd/E3IayRkqJucLZm6hmkJIIz9vUX21Wv1 5LgA== X-Gm-Message-State: AOAM533Kx1aWLhDtnAnf64KUoZ3O4dIrurgT3QZkWtZxNM6e7PgTRK+G HIrj7x6p8Li4UzHxoG23WZGQB2ZmGzSG8g== X-Google-Smtp-Source: ABdhPJy8QFrZZxs03FzbG9AnzokJn5rAcWvwdLzxa2hgGXt22MawNrPK2ad1MAhMiExORxPuXU/rqQ== X-Received: by 2002:a63:3387:: with SMTP id z129mr10789987pgz.227.1626455992129; Fri, 16 Jul 2021 10:19:52 -0700 (PDT) Received: from localhost ([203.206.29.204]) by smtp.gmail.com with ESMTPSA id t6sm12217077pjo.4.2021.07.16.10.19.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 10:19:51 -0700 (PDT) From: Daniel Axtens To: patchwork@lists.ozlabs.org Subject: [PATCH 2/4] migrations: 0043_merge_patch_submission: do less work Date: Sat, 17 Jul 2021 03:19:38 +1000 Message-Id: <20210716171940.3827847-3-dja@axtens.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210716171940.3827847-1-dja@axtens.net> References: <20210716171940.3827847-1-dja@axtens.net> MIME-Version: 1.0 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jk@ozlabs.org Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" - we do a lot of legwork to prevent there being a column with the same name in a base class and subclass. This is purely for django's benefit as databases don't see the class relationship and handle column names being the same across tables just fine. Unfortunately renaming columns in MySQL/MariaDB is _extremely_ expensive. So just don't do it: lie to django about the names of the duplicate columns. - This means we don't have to worry about deleting the index and the unique_together constraints. Let deleting the table do all of that at once. - I don't think we gain anything from deleting foreign keys out of the patch table before deleting it. I initially thought this might relate to an ON DELETE CASCADE, but the ON DELETE rules in the patches table relate to what happens to the row in the patches tables if you delete an element from the associated table, not the other way around. Signed-off-by: Daniel Axtens Reviewed-by: Stephen Finucane --- .../migrations/0043_merge_patch_submission.py | 140 +++++++++--------- 1 file changed, 68 insertions(+), 72 deletions(-) diff --git a/patchwork/migrations/0043_merge_patch_submission.py b/patchwork/migrations/0043_merge_patch_submission.py index d351892ef7f2..465e527812ba 100644 --- a/patchwork/migrations/0043_merge_patch_submission.py +++ b/patchwork/migrations/0043_merge_patch_submission.py @@ -10,16 +10,16 @@ def migrate_data(apps, schema_editor): schema_editor.execute( """ UPDATE patchwork_submission - SET archived = patchwork_patch.archived2, - commit_ref = patchwork_patch.commit_ref2, - delegate_id = patchwork_patch.delegate2_id, - diff = patchwork_patch.diff2, - hash = patchwork_patch.hash2, - number = patchwork_patch.number2, - pull_url = patchwork_patch.pull_url2, - related_id = patchwork_patch.related2_id, - series_id = patchwork_patch.series2_id, - state_id = patchwork_patch.state2_id + SET archived = patchwork_patch.archived, + commit_ref = patchwork_patch.commit_ref, + delegate_id = patchwork_patch.delegate_id, + diff = patchwork_patch.diff, + hash = patchwork_patch.hash, + number = patchwork_patch.number, + pull_url = patchwork_patch.pull_url, + related_id = patchwork_patch.related_id, + series_id = patchwork_patch.series_id, + state_id = patchwork_patch.state_id FROM patchwork_patch WHERE patchwork_submission.id = patchwork_patch.submission_ptr_id """ @@ -28,16 +28,16 @@ def migrate_data(apps, schema_editor): schema_editor.execute( """ UPDATE patchwork_submission, patchwork_patch - SET patchwork_submission.archived = patchwork_patch.archived2, - patchwork_submission.commit_ref = patchwork_patch.commit_ref2, - patchwork_submission.delegate_id = patchwork_patch.delegate2_id, - patchwork_submission.diff = patchwork_patch.diff2, - patchwork_submission.hash = patchwork_patch.hash2, - patchwork_submission.number = patchwork_patch.number2, - patchwork_submission.pull_url = patchwork_patch.pull_url2, - patchwork_submission.related_id = patchwork_patch.related2_id, - patchwork_submission.series_id = patchwork_patch.series2_id, - patchwork_submission.state_id = patchwork_patch.state2_id + SET patchwork_submission.archived = patchwork_patch.archived, + patchwork_submission.commit_ref = patchwork_patch.commit_ref, + patchwork_submission.delegate_id = patchwork_patch.delegate_id, + patchwork_submission.diff = patchwork_patch.diff, + patchwork_submission.hash = patchwork_patch.hash, + patchwork_submission.number = patchwork_patch.number, + patchwork_submission.pull_url = patchwork_patch.pull_url, + patchwork_submission.related_id = patchwork_patch.related_id, + patchwork_submission.series_id = patchwork_patch.series_id, + patchwork_submission.state_id = patchwork_patch.state_id WHERE patchwork_submission.id = patchwork_patch.submission_ptr_id """ # noqa ) @@ -50,16 +50,16 @@ def migrate_data(apps, schema_editor): pull_url, related_id, series_id, state_id ) = ( SELECT - patchwork_patch.archived2, - patchwork_patch.commit_ref2, - patchwork_patch.delegate2_id, - patchwork_patch.diff2, - patchwork_patch.hash2, - patchwork_patch.number2, - patchwork_patch.pull_url2, - patchwork_patch.related2_id, - patchwork_patch.series2_id, - patchwork_patch.state2_id + patchwork_patch.archived, + patchwork_patch.commit_ref, + patchwork_patch.delegate_id, + patchwork_patch.diff, + patchwork_patch.hash, + patchwork_patch.number, + patchwork_patch.pull_url, + patchwork_patch.related_id, + patchwork_patch.series_id, + patchwork_patch.state_id FROM patchwork_patch WHERE patchwork_patch.submission_ptr_id = patchwork_submission.id ) @@ -152,39 +152,44 @@ class Migration(migrations.Migration): # rename all the fields on 'Patch' so we don't have duplicates when we # add them to 'Submission' - migrations.RemoveIndex( - model_name='patch', name='patch_list_covering_idx', - ), - migrations.AlterUniqueTogether(name='patch', unique_together=set([]),), - migrations.RenameField( - model_name='patch', old_name='archived', new_name='archived2', - ), - migrations.RenameField( - model_name='patch', old_name='commit_ref', new_name='commit_ref2', - ), - migrations.RenameField( - model_name='patch', old_name='delegate', new_name='delegate2', - ), - migrations.RenameField( - model_name='patch', old_name='diff', new_name='diff2', - ), - migrations.RenameField( - model_name='patch', old_name='hash', new_name='hash2', - ), - migrations.RenameField( - model_name='patch', old_name='number', new_name='number2', - ), - migrations.RenameField( - model_name='patch', old_name='pull_url', new_name='pull_url2', - ), - migrations.RenameField( - model_name='patch', old_name='related', new_name='related2', - ), - migrations.RenameField( - model_name='patch', old_name='series', new_name='series2', - ), - migrations.RenameField( - model_name='patch', old_name='state', new_name='state2', + # Again we only to rename these fields in the django view of the world (state) + # to avoid errors about the same fields being in the base class (Submission) + # and a subclass (Patch). The db doesn't care, and we migrate the data in raw + # SQL, so basically just lie to django here. + migrations.SeparateDatabaseAndState( + database_operations=[], + state_operations=[ + migrations.RenameField( + model_name='patch', old_name='archived', new_name='archived2', + ), + migrations.RenameField( + model_name='patch', old_name='commit_ref', new_name='commit_ref2', + ), + migrations.RenameField( + model_name='patch', old_name='delegate', new_name='delegate2', + ), + migrations.RenameField( + model_name='patch', old_name='diff', new_name='diff2', + ), + migrations.RenameField( + model_name='patch', old_name='hash', new_name='hash2', + ), + migrations.RenameField( + model_name='patch', old_name='number', new_name='number2', + ), + migrations.RenameField( + model_name='patch', old_name='pull_url', new_name='pull_url2', + ), + migrations.RenameField( + model_name='patch', old_name='related', new_name='related2', + ), + migrations.RenameField( + model_name='patch', old_name='series', new_name='series2', + ), + migrations.RenameField( + model_name='patch', old_name='state', new_name='state2', + ), + ], ), # add the fields found on 'Patch' to 'Submission' @@ -306,15 +311,6 @@ class Migration(migrations.Migration): ), ), - # remove the foreign key fields from the 'Patch' model - - migrations.RemoveField(model_name='patch', name='delegate2',), - migrations.RemoveField(model_name='patch', name='patch_project',), - migrations.RemoveField(model_name='patch', name='related2',), - migrations.RemoveField(model_name='patch', name='series2',), - migrations.RemoveField(model_name='patch', name='state2',), - migrations.RemoveField(model_name='patch', name='submission_ptr',), - # drop the 'Patch' model and rename 'Submission' to 'Patch' migrations.DeleteModel(name='Patch',),