fix: move SET LOCAL inside transaction in quotation/media/comms migration scripts
This commit is contained in:
@@ -63,13 +63,12 @@ async def run() -> None:
|
|||||||
})
|
})
|
||||||
|
|
||||||
async with AsyncPgSession() as session:
|
async with AsyncPgSession() as session:
|
||||||
await session.execute(text("SET session_replication_role = replica"))
|
|
||||||
async with session.begin():
|
async with session.begin():
|
||||||
|
await session.execute(text("SET LOCAL session_replication_role = replica"))
|
||||||
stmt = pg_insert(CrmCommsLog).values(records)
|
stmt = pg_insert(CrmCommsLog).values(records)
|
||||||
stmt = stmt.on_conflict_do_nothing(index_elements=["id"])
|
stmt = stmt.on_conflict_do_nothing(index_elements=["id"])
|
||||||
await session.execute(stmt)
|
await session.execute(stmt)
|
||||||
dest_count = await pg_count(session, "crm_comms_log")
|
dest_count = await pg_count(session, "crm_comms_log")
|
||||||
await session.execute(text("SET session_replication_role = DEFAULT"))
|
|
||||||
|
|
||||||
if dest_count < source_count:
|
if dest_count < source_count:
|
||||||
msg = f"Count mismatch: source={source_count} postgres={dest_count}"
|
msg = f"Count mismatch: source={source_count} postgres={dest_count}"
|
||||||
|
|||||||
@@ -54,13 +54,12 @@ async def run() -> None:
|
|||||||
})
|
})
|
||||||
|
|
||||||
async with AsyncPgSession() as session:
|
async with AsyncPgSession() as session:
|
||||||
await session.execute(text("SET session_replication_role = replica"))
|
|
||||||
async with session.begin():
|
async with session.begin():
|
||||||
|
await session.execute(text("SET LOCAL session_replication_role = replica"))
|
||||||
stmt = pg_insert(CrmMedia).values(records)
|
stmt = pg_insert(CrmMedia).values(records)
|
||||||
stmt = stmt.on_conflict_do_nothing(index_elements=["id"])
|
stmt = stmt.on_conflict_do_nothing(index_elements=["id"])
|
||||||
await session.execute(stmt)
|
await session.execute(stmt)
|
||||||
dest_count = await pg_count(session, "crm_media")
|
dest_count = await pg_count(session, "crm_media")
|
||||||
await session.execute(text("SET session_replication_role = DEFAULT"))
|
|
||||||
|
|
||||||
if dest_count < source_count:
|
if dest_count < source_count:
|
||||||
msg = f"Count mismatch: source={source_count} postgres={dest_count}"
|
msg = f"Count mismatch: source={source_count} postgres={dest_count}"
|
||||||
|
|||||||
@@ -63,13 +63,12 @@ async def run() -> None:
|
|||||||
})
|
})
|
||||||
|
|
||||||
async with AsyncPgSession() as session:
|
async with AsyncPgSession() as session:
|
||||||
await session.execute(text("SET session_replication_role = replica"))
|
|
||||||
async with session.begin():
|
async with session.begin():
|
||||||
|
await session.execute(text("SET LOCAL session_replication_role = replica"))
|
||||||
stmt = pg_insert(CrmQuotationItem).values(records)
|
stmt = pg_insert(CrmQuotationItem).values(records)
|
||||||
stmt = stmt.on_conflict_do_nothing(index_elements=["id"])
|
stmt = stmt.on_conflict_do_nothing(index_elements=["id"])
|
||||||
await session.execute(stmt)
|
await session.execute(stmt)
|
||||||
dest_count = await pg_count(session, "crm_quotation_items")
|
dest_count = await pg_count(session, "crm_quotation_items")
|
||||||
await session.execute(text("SET session_replication_role = DEFAULT"))
|
|
||||||
|
|
||||||
if dest_count < source_count:
|
if dest_count < source_count:
|
||||||
msg = f"Count mismatch: source={source_count} postgres={dest_count}"
|
msg = f"Count mismatch: source={source_count} postgres={dest_count}"
|
||||||
|
|||||||
@@ -96,15 +96,13 @@ async def run() -> None:
|
|||||||
})
|
})
|
||||||
|
|
||||||
async with AsyncPgSession() as session:
|
async with AsyncPgSession() as session:
|
||||||
# Disable FK enforcement for this session so we can insert quotations
|
|
||||||
# before the referenced crm_customers rows arrive in Phase 2.
|
|
||||||
await session.execute(text("SET session_replication_role = replica"))
|
|
||||||
async with session.begin():
|
async with session.begin():
|
||||||
|
# Disable FK enforcement so we can insert before crm_customers arrives in Phase 2.
|
||||||
|
await session.execute(text("SET LOCAL session_replication_role = replica"))
|
||||||
stmt = pg_insert(CrmQuotation).values(records)
|
stmt = pg_insert(CrmQuotation).values(records)
|
||||||
stmt = stmt.on_conflict_do_nothing(index_elements=["id"])
|
stmt = stmt.on_conflict_do_nothing(index_elements=["id"])
|
||||||
await session.execute(stmt)
|
await session.execute(stmt)
|
||||||
dest_count = await pg_count(session, "crm_quotations")
|
dest_count = await pg_count(session, "crm_quotations")
|
||||||
await session.execute(text("SET session_replication_role = DEFAULT"))
|
|
||||||
|
|
||||||
if dest_count < source_count:
|
if dest_count < source_count:
|
||||||
msg = f"Count mismatch: source={source_count} postgres={dest_count}"
|
msg = f"Count mismatch: source={source_count} postgres={dest_count}"
|
||||||
|
|||||||
Reference in New Issue
Block a user