mozilla / fx-private-relay

Keep your email safe from hackers and trackers. Make an email alias with 1 click, and keep your address to yourself.
https://relay.firefox.com
Other
1.44k stars 166 forks source link

MPP-3827: Move Profile and RegisteredSubdomain models to privaterelay #4763

Open jwhitlock opened 3 weeks ago

jwhitlock commented 3 weeks ago

This PR moves Django models and related code from emails to privaterelay.

It does not update the database. The moved models have the Meta.db_table property set to ensure the table names do not change (still emails_profile and emails_registeredsubdomain. The migrations use the SeparateDatabaseAndState operation to avoid SQL. Deployment will work, and that the terraform SQL will continue to work. Thanks to https://davit.hashnode.dev/django-move-model for explaining this technique.

It may be possible to smoothly rename the tables as well. PostgreSQL views are updatable, so we could create a emails_profile view that allows existing code to continue to query, insert, and update to emails_profile while the table is named privaterelay_profile. There are two issues. One is the SQLite does not have updatable views, so I'd need to craft triggers to make tests pass. The second is that if a test needs to run in a transaction, TRUNCATE is used and further complicates things. Both could be handled. SQLite triggers are possible to write, just hard. I eliminated all the transaction tests, and an upstream contribution to pytest_django is possible. We could also just say "dev and migration tests are broken for a bit". In any case, I'd like to avoid any table renames in this PR.

How to test

CircleCI does all of the validation that this works. The migrations tests are especially important. If you want to verify they run no SQL:

./manage.py sqlmigrate privaterelay 0010
./manage.py sqlmigrate emails 0062

both return:

BEGIN;
--
-- Custom state/database change combination
--
-- (no-op)
COMMIT;

Previous PRs

The initial spike was broken up into smaller, focused PRs. Thanks to @groovecoder and @say-yawn for the reviews and making this a better change.