-
Notifications
You must be signed in to change notification settings - Fork 195
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
offer MYSQL_COMPATIBILITY setting to remove unique from the model #267
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7ee74a5
offer MYSQL_COMPATIBILITY setting to remove unique from the model
tuky 79fcf01
Merge branch 'master' into master
tuky b9a9514
Update 0010_unique_registration_id.py
tuky 08139e5
Update 0011_fcmdevice_fcm_django_registration_id_user_id_idx.py
tuky 076d02e
black
tuky 3a046a6
explain edge case and document alternative to get the best of both wo…
tuky a7db9c5
add missing new line
tuky d018f66
improve section order
tuky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -422,7 +422,7 @@ If you don't want default table appears in the DB then you should remove ``fcm_d | |
|
||
After setup your own ``Model`` don't forget to create ``migrations`` for your app and call ``migrate`` command. | ||
|
||
After removing ``"fcm_django"`` out of ``INSTALLED_APPS``. You will need to re-register the Device in order to see it in the admin panel. | ||
After removing ``"fcm_django"`` out of ``INSTALLED_APPS``. You will need to re-register the Device in order to see it in the admin panel. | ||
This can be accomplished as follows at ``your_app/admin.py``: | ||
|
||
.. code-block:: python | ||
|
@@ -442,12 +442,46 @@ If you choose to move forward with swapped models then: | |
1. On existed project you have to keep in mind there are required manual work to move data from one table to anther. | ||
2. If there's any tables with FK to swapped model then you have to deal with them on your own. | ||
|
||
Note: This functionality based on `Swapper <https://pypi.org/project/swapper/>`_ that based on functionality | ||
Note: This functionality based on `Swapper <https://pypi.org/project/swapper/>`_ that based on functionality | ||
that allow to use a `custom User model <https://docs.djangoproject.com/en/4.2/topics/auth/customizing/#substituting-a-custom-user-model>`_. | ||
So this functionality have the same limitations. | ||
The most is important limitation it is that is difficult to start out with a default (non-swapped) model | ||
So this functionality have the same limitations. | ||
The most is important limitation it is that is difficult to start out with a default (non-swapped) model | ||
and then later to switch to a swapped implementation without doing some migration hacking. | ||
|
||
MySQL compatibility | ||
------------------- | ||
MySQL has a limit for indices and therefore the `registration_id` field cannot be made unique in MySQL. | ||
We detect the database backend and remove the unique constraint for MySQL in the migration files. However, | ||
to ensure that the constraint is removed from the actual model you have to add the following to your settings | ||
to be able to run your django tests with MySQL and without running all migrations: | ||
|
||
.. code-block:: python | ||
|
||
FCM_DJANGO_SETTINGS = { | ||
"MYSQL_COMPATIBILITY": True, | ||
# [...] your other settings | ||
} | ||
|
||
As an alternative, you can use a custom model (see above) and either remove the unique constraint manually | ||
or use a length limited CharField for the `registration_id` field. There are no guarantees on the max length of | ||
FCM tokens, but in practice they are less than 200 characters long. Therefore, a CharField with a length of 600 | ||
should be sufficient and you can make it unique and index it even with MySQL: | ||
|
||
.. code-block:: python | ||
|
||
from fcm_django.models import AbstractFCMDevice, FCMDevice as OriginalFCMDevice | ||
|
||
|
||
class CustomFCMDevice(AbstractFCMDevice): | ||
registration_id = models.CharField( | ||
verbose_name="Registration token", | ||
unique=True, | ||
max_length=600, # https://stackoverflow.com/a/64902685 better to be safe than sorry | ||
) | ||
|
||
class Meta(OriginalFCMDevice.Meta): | ||
pass | ||
|
||
Python 3 support | ||
---------------- | ||
- ``fcm-django`` is fully compatible with Python 3.7+ | ||
|
@@ -481,11 +515,11 @@ Because there's possibility to use swapped models therefore tests contains two c | |
1. with default settings and non swapped models ``settings/default.py`` | ||
2. and with overwritten settings only that required by swapper - ``settings/swap.py`` | ||
|
||
To run tests locally you could use ``pytest``, and if you need to check migrations on different DB then you have to specify environment variable ``DATABASE_URL`` ie | ||
To run tests locally you could use ``pytest``, and if you need to check migrations on different DB then you have to specify environment variable ``DATABASE_URL`` ie | ||
|
||
.. code-block:: console | ||
|
||
export DATABASE_URL=postgres://postgres:[email protected]:5432/postgres | ||
export DJANGO_SETTINGS_MODULE=tests.settings.default | ||
export DJANGO_SETTINGS_MODULE=tests.settings.default | ||
# or export DJANGO_SETTINGS_MODULE=tests.settings.swap | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why explicitly check this? It should skip it if it's mysql anway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make
makemigrations
happy. After addingto the
default
test settings:1st execution of
makemigrations
is with the check.2nd execution is without it.