v0.1.28 - Version bump and editor/throughput updates
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -457,19 +457,27 @@ def migrate():
|
||||
# Re-enable FK checks
|
||||
dst_conn.execute(text("SET session_replication_role = 'origin'"))
|
||||
|
||||
# Reset auto-increment sequences
|
||||
# Reset auto-increment sequences for EVERY table with an id sequence — not
|
||||
# just the ones we copied above — so later inserts (e.g. editor_change_events)
|
||||
# don't collide with pre-existing ids. Leaving a sequence behind MAX(id) is
|
||||
# what makes "create new mix" fail with a duplicate-key error on Postgres.
|
||||
print("\n Resetting sequences...")
|
||||
with dst.begin() as conn:
|
||||
for table_name in TABLE_ORDER:
|
||||
try:
|
||||
conn.execute(text(
|
||||
f"SELECT setval("
|
||||
f" pg_get_serial_sequence('{table_name}', 'id'),"
|
||||
f" COALESCE((SELECT MAX(id) FROM {table_name}), 1)"
|
||||
f")"
|
||||
))
|
||||
except Exception:
|
||||
pass
|
||||
all_tables = inspect(dst).get_table_names()
|
||||
for table_name in all_tables:
|
||||
sequence = conn.execute(text(
|
||||
"SELECT pg_get_serial_sequence(:table, 'id')"
|
||||
), {"table": table_name}).scalar()
|
||||
if not sequence:
|
||||
continue
|
||||
max_id = conn.execute(text(f'SELECT MAX(id) FROM "{table_name}"')).scalar()
|
||||
if max_id is None:
|
||||
continue
|
||||
conn.execute(text("SELECT setval(:sequence, :value, true)"), {
|
||||
"sequence": sequence,
|
||||
"value": int(max_id),
|
||||
})
|
||||
print(f" SEQ {table_name:<45} -> {max_id}")
|
||||
|
||||
print(f"\n Migration complete. {sum(totals.values())} rows across {len(totals)} tables.")
|
||||
return totals
|
||||
|
||||
Reference in New Issue
Block a user