Skip to content

Commit

Permalink
fix error with custom migration to JSON schema of data field (#119)
Browse files Browse the repository at this point in the history
put the check for the email relay database alias in there, but it was unneeded -- especially if you are running the relay as a Docker container, which uses the relay db under the `default` alias.
  • Loading branch information
joshuadavidthomas committed Oct 31, 2023
1 parent c159e9f commit 6ba788b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 49 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/

## [Unreleased]

### Fixed

- Migration 0002 was not being applied to the `default` database, which is the norm when running the relay in Docker.

## [0.2.0]

**This release involves migrations.** Please read below for more information.
Expand Down
5 changes: 0 additions & 5 deletions src/email_relay/migrations/0002_auto_20231030_1304.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from django.db import migrations

from email_relay.conf import EMAIL_RELAY_DATABASE_ALIAS


def migrate_message_data_to_new_schema(apps, schema_editor):
"""Migrate the JSON data from the old schema to the new schema.
Expand All @@ -20,9 +18,6 @@ def migrate_message_data_to_new_schema(apps, schema_editor):
- "extra_headers"
- "alternatives"
"""
if schema_editor.connection.alias != EMAIL_RELAY_DATABASE_ALIAS:
return

Message = apps.get_model("email_relay", "Message")

for message in Message.objects.all():
Expand Down
44 changes: 0 additions & 44 deletions tests/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,47 +61,3 @@ class MockSchemaEditor:
assert message.data["alternatives"] == [
["<p>HTML</p>", "text/html"],
]


@pytest.mark.django_db(databases=["default", EMAIL_RELAY_DATABASE_ALIAS])
def test_migrate_message_data_to_new_schema_default_not_applied(
migrate_message_data_to_new_schema,
):
class MockSchemaEditor:
connection = connections["default"]

baker.make(
"email_relay.Message",
data={
"message": "Here is the message.",
"recipient_list": ["to@example.com"],
"html_message": "<p>HTML</p>",
},
_quantity=3,
)

for message in Message.objects.all():
assert message.data["message"] == "Here is the message."
assert message.data["recipient_list"] == ["to@example.com"]
assert message.data["html_message"] == "<p>HTML</p>"
assert not message.data.get("to")
assert not message.data.get("cc")
assert not message.data.get("bcc")
assert not message.data.get("reply_to")
assert not message.data.get("extra_headers")
assert not message.data.get("alternatives")

migrate_message_data_to_new_schema(apps, MockSchemaEditor())

assert Message.objects.count() == 3

for message in Message.objects.all():
assert message.data["message"] == "Here is the message."
assert message.data["recipient_list"] == ["to@example.com"]
assert message.data["html_message"] == "<p>HTML</p>"
assert not message.data.get("to")
assert not message.data.get("cc")
assert not message.data.get("bcc")
assert not message.data.get("reply_to")
assert not message.data.get("extra_headers")
assert not message.data.get("alternatives")

0 comments on commit 6ba788b

Please sign in to comment.