Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move publish status fields out of Website and into a separate model? #819

Open
mbertrand opened this issue Nov 17, 2021 · 0 comments
Open

Comments

@mbertrand
Copy link
Member

mbertrand commented Nov 17, 2021

The number of fields in the Website model for tracking publishing status is getting very large. It might be beneficial to split them out into a separate model, something like this:

Designs and Mockups

class WebsitePublishStatus(TimestampedModel):
    website = models.ForeignKey(Website)
    version = models.CharField(choices=zip(VERSIONS, VERSIONS),)
    has_unpublished = models.BooleanField(default=True)
    publish_date = models.DateTimeField(null=True, blank=True)
    publish_status = models.CharField(
        max_length=20,
        null=True,
        choices=zip(constants.PUBLISH_STATUSES, constants.PUBLISH_STATUSES),
    )
    latest_build_id = models.IntegerField(null=True)
    publish_status_updated_on = models.DateTimeField(null=True, blank=True)
    last_published_by = models.ForeignKey(User, blank=True, null=True)

    class Meta:
        constraints = [
            UniqueConstraint(name="unique_website_version", fields=["website", "version"]),
        ]

In migration:

def create_website_publish_status_from_website(apps, schema_editor):
    """
    Copy over existing data from the Website model objects to WebsiteStatus objects
    """
    Website = apps.get_model("websites", "Website")
    WebsitePublishStatus = apps.get_model("websites", "WebsitePublishStatus")
    for website in Website.objects.iterator():
        WebsitePublishStatus.objects.update_or_create(
            version=VERSION_DRAFT,
            website=website,
            defaults={
                "has_unpublished": website.has_unpublished_draft,
                "publish_date": website.draft_publish_date,
                "publish_status": website.draft_publish_status,
                "publish_status_updated_on": website.draft_publish_status_updated_on,
                "latest_build_id": website.latest_build_id_draft,
            }
        )
        WebsitePublishStatus.objects.update_or_create(
            version=VERSION_LIVE,
            website=website,
            defaults={
                "has_unpublished": website.has_unpublished_live,
                "publish_date": website.publish_date,
                "publish_status": website.live_publish_status,
                "publish_status_updated_on": website.live_publish_status_updated_on,
                "latest_build_id": website.latest_build_id_live,
            }
        )

But this would also require refactoring lots of other code like the serializers and various celery tasks and views.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant