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

For those who come here to upgrade to django 3.0 and higher #21

Open
simkimsia opened this issue Jan 4, 2021 · 0 comments
Open

For those who come here to upgrade to django 3.0 and higher #21

simkimsia opened this issue Jan 4, 2021 · 0 comments

Comments

@simkimsia
Copy link

simkimsia commented Jan 4, 2021

this library is in maintenance mode. so you need to move away if you want to upgrade to django 3.0

I am in the midst of doing so.

here's how I'm upgrading.

if u use unique=True

General idea: switch to UniqueConstraint with condition available in django 2.2. see https://docs.djangoproject.com/en/3.0/ref/models/constraints/#condition for details

Step by Step

  1. remain in 2.2
  2. remove your unique index then makemigrations
  3. add in the uniqueconstraint then makemigrations
  4. run migrate
  5. repeat step 2-4 until all removed
  6. drop partial index
  7. upgrade to 3.0 or higher

Done.

Step 2 and 3 can be compressed into a single step after you run step 2 and 3 separately once to gain confidence.

2 and 3 can become "replace partialindex with uniqueconstraint then makemigrations"

An actual example I use

Originally

    class Meta:
        indexes = [
            PartialIndex(
                fields=["serial_number", "sheet"], unique=True, where=PQ(is_removed=False)
            ),
        ]

Now

    class Meta:
        constraints = [
            models.UniqueConstraint(
                fields=["serial_number", "sheet"],
                condition=models.Q(is_removed=False),
                name="unique_serial_number_in_sheet_for_nondeleted",
            )
        ]

I almost exclusively use this library to write partial unique constraints. So I have nothing to add about situations where partial index is used for non unique. Sorry.

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

No branches or pull requests

1 participant