File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change 1
1
# Third party
2
2
from django .conf import settings
3
3
from django .db import router , transaction as django_transaction
4
- from gcloudc .db import transaction as datastore_transaction
5
4
6
5
# Mass Migration
7
6
from massmigration .models import MigrationRecord
13
12
# That said, should you be allowed to run the same migration on two different databases?
14
13
15
14
16
- def get_transaction (db_alias ):
17
- engine = settings .DATABASES [db_alias ]["ENGINE" ]
18
- if engine == "gcloudc.db.backends.datastore" :
19
- return datastore_transaction
20
- return django_transaction
15
+ def get_transaction ():
16
+ connection = router .db_for_write (MigrationRecord )
17
+ engine = settings .DATABASES [connection ]["ENGINE" ]
18
+ transaction = django_transaction
19
+ if engine .startswith ("gcloudc.db.backends" ):
20
+ try :
21
+ from gcloudc .db import transaction as gcloudc_transaction
22
+ transaction = gcloudc_transaction
23
+ except ImportError :
24
+ # Newer versions of gcloudc use Django transactions.
25
+ pass
26
+ return transaction
You can’t perform that action at this time.
0 commit comments