Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
Make migration 0020 multi-database friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Osvaldo Barrera committed Nov 19, 2020
1 parent 3dc7cd7 commit f54cf28
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion django_mercadopago/migrations/0002_auto_20150923_2328.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

def fake_data(apps, schema_editor):
db_alias = schema_editor.connection.alias

Account = apps.get_model("mp", "Account")
Notification = apps.get_model("mp", "Notification")
Payment = apps.get_model("mp", "Payment")
Expand All @@ -18,7 +19,11 @@ def fake_data(apps, schema_editor):
return

account = Account.objects.using(db_alias).create(
name="Auto-migrated", slug="_", app_id="_", secret_key="_", sandbox=True,
name="Auto-migrated",
slug="_",
app_id="_",
secret_key="_",
sandbox=True,
)
Notification.objects.using(db_alias).update(owner=account)

Expand Down
6 changes: 4 additions & 2 deletions django_mercadopago/migrations/0020_move_preference_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

def move_item_data(apps, schema_editor):
"""Move Item data from Preference into the new model."""
db_alias = schema_editor.connection.alias

Preference = apps.get_model("mp", "Preference")
Item = apps.get_model("mp", "Item")

for preference in Preference.objects.all():
Item.objects.create(
for preference in Preference.objects.using(db_alias).all():
Item.objects.using(db_alias).create(
preference=preference,
title=preference.title,
description=preference.description,
Expand Down

0 comments on commit f54cf28

Please sign in to comment.