-
Notifications
You must be signed in to change notification settings - Fork 2
Guide_Upgrading to 2.0
The following guide seeks to alleviate potential issues when upgrading from django-wm<2.0
to django-wm>=2.0
.
⚠ Breaking change ⚠
Prior versions of django-wm
omitted migration files for the mentions
app that this package provides. This was an oversight: when running manage.py makemigrations
, one or more migration files would be generated within the django-wm
package installation. This can cause issues when/if django-wm
is upgraded with changes to its concrete models.
Starting in v2.0.1, migrations for mentions
app's concrete models - models that are NOT abstract base classes - will be included with the package distribution. This way, new changes to those concrete models can be smoothly migrated in any environment that uses django-wm
.
The following models are affected by the change:
mentions.HCard
mentions.OutgoingWebmentionStatus
mentions.SimpleMention
mentions.Webmention
Notes:
- Database tables created by mentions models in v1.3.1 are identical to those created with v2.0.1. Any database environment with up-to-date model migrations as of v1.3.1 should be able to upgrade to v2.0 with no impacts on data or database schemas.
-
Model mixins are not affected. Mixins are abstract base classes, and do not generate migrations in the
mentions
app under any circumstances. - Models that inherit from mixins are also not affected. You do not need to generate new migrations for your own apps if you inherit from these mixin classes.
If you are uncertain if your app will be adversely affected by this change, you may take the following steps to safely migrate your existing environment to django-wm>=2.0
. This is a one-time process for the upgrade to v2.0+. All future upgrades for django-wm
do not need to follow this same process.
⚠ DO NOT upgrade the django-wm
package yet! You will need the generated migration files from your current installation in order to follow this guide.
- Backup any existing migrations for the
mentions
app from inside the Python environment wheredjango-wm
is installed. - Upgrade
django-wm
, then remove its migration files (don't runmanage.py migrate
). - Replace your old migrations, then run
manage.py makemigrations
to generate changes between your old migrations and the new code indjango-wm
package. - Use
migrate mentions zero --fake
to remove the records of your old migrations from yourdjango_migrations
database table. - Uninstall then reinstall the
django-wm
package, resetting migrations back to the versions from this package (instead of those generated by your app). - Use
migration mentions --fake
to reset thedjango_migrations
records in your database.
-
Navigate to the Python installation or virtual environment where
django-wm
is installed, and locate thelib/site-packages/mentions
directory (where the installed code for this package resides). From there, copy themigrations
directory and its contents to a safe location outside the Python virtual environment.- The migration files here will be ones your Django project generated using the
makemigrations
command in v1.3.1 and below.
- The migration files here will be ones your Django project generated using the
-
Upgrade
django-wm
usingpip install --upgrade django-wm
(preferably, specify the version withdjango-wm==2.0.1
).- This will install the new migration file(s) introduced in v2.0+.
-
Again, navigate to
lib/site-packages/mentions
in the Python virtual environment. This time, remove themigrations
directory entirely. -
Move your old migration files (from Step 1) back to
lib/site-packages/mentions
within your Python virtual environment.- Running
manage.py showmigrations mentions
from your Django project should show a list of your old migration files.
- Running
-
From your Django project, run
manage.py makemigrations mentions
- This may create new migration files in the
mentions
app. These will cover the differences between your old migrations and any new changes introduced in v2.0+.
- This may create new migration files in the
-
Run
manage.py migrate
- Now your database should match the expected schema for
django-wm>=2.0
.
- Now your database should match the expected schema for
-
Run
manage.py migrate mentions zero --fake
- With
--fake
, your database schema remains unchanged. Only thedjango_migrations
table is altered, adding or removing records of migrations that have been applied in that database. -
zero
removes records for all migrations for the app, making Django believe thementions
app has never been migrated before. - ⚠ Don't forget that
--fake
flag, or it will DROP the tables for your models!
- With
-
Use
pip uninstall django-wm
to completely remove the package, thenpip install django-wm
to reinstall it.- This deletes your old migration files and replaces them with the new one(s) from PyPI.
- If you specified a version (as is recommended) in Step 2, you should specify the same version now!
-
Run
manage.py migrate mentions --fake
- Similar to Step 7, this "fakes" the migrations for
mentions
back up to the latest available, adding records back to thedjango_migrations
table. - ⚠ This assumes that all prior steps have been followed, so that the state of your database exactly matches the state of the migration file(s) included with your new
django-wm
installation. If, for any reason, the newly-installedmention
migrations do not match your new database schema, you may end up with broken migrations, a mismatched schema, or data loss.
- Similar to Step 7, this "fakes" the migrations for
🎉 That's it! You are now ready to use and upgrade django-wm
safely in the future, along with any migration files for new changes to its own concrete models. 😊