fixed db import transactions
This commit is contained in:
parent
6b5e386469
commit
060ca72eb4
1 changed files with 5 additions and 4 deletions
|
|
@ -743,15 +743,15 @@ def _importSingleDb(payload: dict, dbName: str, mode: str, protectedIds: List[st
|
||||||
conn = _getConnection(dbName)
|
conn = _getConnection(dbName)
|
||||||
try:
|
try:
|
||||||
existingTables = set(_listTables(conn))
|
existingTables = set(_listTables(conn))
|
||||||
|
conn.rollback()
|
||||||
|
|
||||||
# Ensure all import tables exist (create missing ones from export schema)
|
# Ensure all import tables exist (create missing ones from export schema)
|
||||||
|
conn.autocommit = True
|
||||||
for tableName, rows in tables.items():
|
for tableName, rows in tables.items():
|
||||||
if tableName in excluded or not isinstance(rows, list) or not rows:
|
if tableName in excluded or not isinstance(rows, list) or not rows:
|
||||||
continue
|
continue
|
||||||
if tableName not in existingTables:
|
if tableName not in existingTables:
|
||||||
conn.autocommit = True
|
|
||||||
_createTableFromExport(conn, tableName, rows)
|
_createTableFromExport(conn, tableName, rows)
|
||||||
conn.autocommit = False
|
|
||||||
existingTables.add(tableName)
|
existingTables.add(tableName)
|
||||||
logger.info("Pre-created missing table %s.%s", dbName, tableName)
|
logger.info("Pre-created missing table %s.%s", dbName, tableName)
|
||||||
|
|
||||||
|
|
@ -770,9 +770,9 @@ def _importSingleDb(payload: dict, dbName: str, mode: str, protectedIds: List[st
|
||||||
|
|
||||||
# Phase 1 (replace only): DELETE children first (reverse topological order)
|
# Phase 1 (replace only): DELETE children first (reverse topological order)
|
||||||
if mode == "replace":
|
if mode == "replace":
|
||||||
|
conn.autocommit = False
|
||||||
for tableName in reversed(importOrder):
|
for tableName in reversed(importOrder):
|
||||||
try:
|
try:
|
||||||
conn.autocommit = False
|
|
||||||
_deleteNonProtected(conn, tableName, protectedIdSet)
|
_deleteNonProtected(conn, tableName, protectedIdSet)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -781,12 +781,13 @@ def _importSingleDb(payload: dict, dbName: str, mode: str, protectedIds: List[st
|
||||||
logger.warning("DELETE from %s.%s failed: %s", dbName, tableName, e)
|
logger.warning("DELETE from %s.%s failed: %s", dbName, tableName, e)
|
||||||
|
|
||||||
# Phase 2: INSERT parents first (topological order)
|
# Phase 2: INSERT parents first (topological order)
|
||||||
|
conn.autocommit = False
|
||||||
for tableName in importOrder:
|
for tableName in importOrder:
|
||||||
try:
|
try:
|
||||||
conn.autocommit = False
|
|
||||||
rows = tables[tableName]
|
rows = tables[tableName]
|
||||||
physicalCols = _getPhysicalColumns(conn, tableName)
|
physicalCols = _getPhysicalColumns(conn, tableName)
|
||||||
if not physicalCols:
|
if not physicalCols:
|
||||||
|
conn.rollback()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
filteredRows = []
|
filteredRows = []
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue