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

Use django-safemigrate for migrations #11087

Merged
merged 9 commits into from
Feb 14, 2024
Merged

Use django-safemigrate for migrations #11087

merged 9 commits into from
Feb 14, 2024

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Feb 1, 2024

  • djago-safemigrations package added
  • Wrote a new guide explaining how to avoid downtime when doing migrations, and the usage of django-safemigrations.
  • To test things out, I went ahead and completed some migrations that we had pending.
  • All other models that had a created/updated field added already had a data migration for the null fields, except for Version, so there is one data migration for that.
  • Update for deploy scripts https://github.com/readthedocs/readthedocs-ops/pull/1441.

Closes #10964


📚 Documentation previews 📚

stsewd added a commit to readthedocs/common that referenced this pull request Feb 1, 2024
stsewd added a commit to readthedocs/common that referenced this pull request Feb 5, 2024
@stsewd
Copy link
Member Author

stsewd commented Feb 5, 2024

pre-commit fails because we are installing the requirements from main, not from the current file https://github.com/readthedocs/common/blob/e598102991c5a927024f06f187f51f7000e67023/pre-commit-config.yaml#L98-L101

@stsewd stsewd marked this pull request as ready for review February 5, 2024 21:02
@stsewd stsewd requested review from a team as code owners February 5, 2024 21:02
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I only have some questions about where these migrations need to be called and why there are some data migrations missing.

docs/dev/migrations.rst Outdated Show resolved Hide resolved
common Outdated Show resolved Hide resolved
docs/dev/migrations.rst Outdated Show resolved Hide resolved
Comment on lines +75 to +76
- #. After the deploy has been completed, create a new migration to set the field as non-nullable (let's call this migration ``app 0003``).
Run this migration on a new deploy, you can mark it as ``Safe.before_deploy`` or ``Safe.always``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this migration be created in the same deploy and marked as after_deploy to make everything in the same deploy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if that will work, but we still need to another deploy to remove all handling of the null case in the code.

docs/dev/migrations.rst Show resolved Hide resolved
docs/dev/migrations.rst Outdated Show resolved Hide resolved
at https://github.com/readthedocs/readthedocs.org/commit/d72ee6e27dc398b97e884ccec8a8cf135134faac.
"""
Version = apps.get_model("builds", "Version")
date = datetime.datetime(2020, 11, 23, tzinfo=datetime.timezone.utc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use a date that it's obvious it's wrong to avoid confusions here? Like 1999-01-01 or similar.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would add more confusion, for us and users (if we expose this field).

@stsewd stsewd merged commit 501ecfa into main Feb 14, 2024
5 of 6 checks passed
@stsewd stsewd deleted the use-django-safemigrate branch February 14, 2024 14:10
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

Successfully merging this pull request may close these issues.

DB: use django-safemigrations for safer deploys
2 participants