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

Django 4.2 upgrade #781

Merged
merged 11 commits into from
Oct 3, 2023
Merged

Django 4.2 upgrade #781

merged 11 commits into from
Oct 3, 2023

Conversation

davidfischer
Copy link
Collaborator

Upgrades Django to the latest LTS.

Upgrading Postgres

Important: Django 4.2 requires Postgres >= 12

Postgres data files aren't compatible between major versions. As a result, if you want to save your local database, you need to follow these steps

# Start the database
make dockershell

# In another terminal window, take a database backup
# The file is saved inside a docker volume
# This should be run on Postgres 11
docker-compose run --rm  postgres backup
# After running this, you can shut down the `make dockershell` from the first window

# Rebuild the docker-compose images with Postgres 15
make dockerbuild

# Stop docker-compose and remove the postgres data directory
docker-compose  down
docker volume rm ethical-ad-server_local_postgres_data

# Back in that first terminal window, start Postgres 15
# This also runs some basic initialization on the new database
make dockerserve
# Wait for Postgres to startup and initialize and create the DB
# Then ^+C `dockerserve`.
# Start the database again (but with no other things like celery connected)
make dockershell

# In the 2nd terminal window,
# restore your local database (no need to start the backup with /backups/)
# The filename comes from the output of `docker-compose run --rm  postgres backup` above
# Or get the filename with `docker-compose run --rm  postgres backups` (backups, plural)
docker-compose run --rm postgres restore backup_2023_08_DDTHH_MM_SS.sql.gz

Verifying in staging

Once this is deployed in staging, the following should be well tested since there were a few changes around those:

  • Verify that the Cloudflare GeoIP header is being checked correctly
  • Staticfiles are correctly collected and the filenames are hashed

Important: Django 4.2 requires Postgres >= 12
@davidfischer davidfischer requested a review from a team as a code owner August 17, 2023 23:40
@ericholscher
Copy link
Member

ericholscher commented Aug 18, 2023

This looks similar to our RTD upgrade, mainly admin and test changes. I guess we need to block this on a production DB upgrade? I think it should be simpleish to upgrade things, but will have to do the research.

Looks like we can hopefully do it with 1-click: https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-major-version-upgrade -- but it doesn't support read replicas... so we probably just need to handle it ourselves:

  • Spin up a new pg 14/15 server
  • Do an initial pg_dump/load to it
  • Swap over production to point at the new server
  • Backfill any Offer data that came in during the migration

I think if we can get the dump/load to a reasonable time (<5 mins), we can probably also just do a quick scheduled downtime for ad serving and do it without any data migration.

@davidfischer
Copy link
Collaborator Author

I'm seeing some form issues relating to the upgrade that I wasn't seeing in 3.x. Specifically, I'm seeing some duplicated field choice values:
Screenshot from 2023-08-21 16-35-53

I haven't investigated deeply enough to figure out if this is fixed in a later version of crispyforms or if we'll need to customize some form templates.

@davidfischer
Copy link
Collaborator Author

The form issues are fixed by upgrading crispy and the template pack.

@davidfischer davidfischer mentioned this pull request Aug 23, 2023
@davidfischer
Copy link
Collaborator Author

The prod database is updated. I'm going to merge this after it is approved.

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

Let's ship it!

@davidfischer davidfischer merged commit f24282e into main Oct 3, 2023
1 check passed
@davidfischer davidfischer deleted the davidfischer/django-42-upgrade branch October 3, 2023 20:22
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.

2 participants