More transactions enabled.

This commit is contained in:
Philip Sargent 2020-07-22 23:36:46 +01:00
parent 1ef5924f0c
commit 3e3cae507c
2 changed files with 22 additions and 21 deletions

View File

@ -41,6 +41,7 @@ from django.db import connection, close_old_connections, connections
from django.http import HttpResponse from django.http import HttpResponse
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import transaction
from troggle.core.models import get_process_memory from troggle.core.models import get_process_memory
from troggle.core.models_caves import Cave, Entrance from troggle.core.models_caves import Cave, Entrance
@ -100,23 +101,24 @@ def reinit_db():
print(" - done migration on: " + settings.DATABASES['default']['NAME']) print(" - done migration on: " + settings.DATABASES['default']['NAME'])
print("users in db already: ",len(User.objects.all())) print("users in db already: ",len(User.objects.all()))
try: with transaction.atomic():
print(" - Setting up admin user on: " + django.db.connections.databases['default']['NAME']) try:
print(" - user: {} ({:.5}...) <{}> ".format(expouser, expouserpass, expouseremail)) print(" - Setting up admin user on: " + django.db.connections.databases['default']['NAME'])
user = User.objects.create_user(expouser, expouseremail, expouserpass) print(" - user: {} ({:.5}...) <{}> ".format(expouser, expouserpass, expouseremail))
user.is_staff = True user = User.objects.create_user(expouser, expouseremail, expouserpass)
user.is_superuser = True user.is_staff = True
user.save() user.is_superuser = True
except: user.save()
print(" ! INTEGRITY ERROR user on: " + settings.DATABASES['default']['NAME']) except:
print(django.db.connections.databases['default']['NAME']) print(" ! INTEGRITY ERROR user on: " + settings.DATABASES['default']['NAME'])
print(" ! You probably have not got a clean db when you thought you had.\n") print(django.db.connections.databases['default']['NAME'])
print(" ! Also you are probably NOT running an in-memory db now.\n") print(" ! You probably have not got a clean db when you thought you had.\n")
print("users in db: ",len(User.objects.all())) print(" ! Also you are probably NOT running an in-memory db now.\n")
print("tables in db: ",len(connection.introspection.table_names())) print("users in db: ",len(User.objects.all()))
memdumpsql(fn='integrityfail.sql') print("tables in db: ",len(connection.introspection.table_names()))
django.db.connections.databases['default']['NAME'] = ':memory:' memdumpsql(fn='integrityfail.sql')
#raise django.db.connections.databases['default']['NAME'] = ':memory:'
#raise
def memdumpsql(fn): def memdumpsql(fn):
djconn = django.db.connection djconn = django.db.connection

View File

@ -59,15 +59,14 @@ def import_survex():
def import_loadpos(): def import_loadpos():
# when this import is moved to the top with the rest it all crashes horribly # when this import is moved to the top with the rest it all crashes horribly
with transaction.atomic():
import troggle.parsers.survex
print(" - Survex entrances x/y/z Positions")
import troggle.parsers.survex import troggle.parsers.survex
print(" - Survex entrances x/y/z Positions")
with transaction.atomic():
troggle.parsers.survex.LoadPositions() troggle.parsers.survex.LoadPositions()
def import_drawingsfiles(): def import_drawingsfiles():
print("-- Importing Drawings files") print("-- Importing Drawings files")
import troggle.parsers.survex with transaction.atomic():
troggle.parsers.surveys.LoadDrawingFiles() troggle.parsers.surveys.LoadDrawingFiles()
# Fossil. # Fossil.