MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / delete_from_all_tables

Function delete_from_all_tables

lib/sqlalchemy/testing/provision.py:572–601  ·  view source on GitHub ↗

an absolutely foolproof delete from all tables routine. dialects should override this to add special instructions like disable constraints etc.

(connection, cfg, metadata)

Source from the content-addressed store, hash-verified

570
571@register.init
572def delete_from_all_tables(connection, cfg, metadata):
573 """an absolutely foolproof delete from all tables routine.
574
575 dialects should override this to add special instructions like
576 disable constraints etc.
577
578 """
579 savepoints = getattr(cfg.requirements, "savepoints", False)
580 if savepoints:
581 savepoints = savepoints.enabled
582
583 inspector = inspect(connection)
584
585 for table in reversed(
586 [
587 t
588 for (t, fks) in sort_tables_and_constraints(
589 metadata.tables.values()
590 )
591 if t is not None
592 # remember that inspector.get_table_names() is cached,
593 # so this emits SQL once per unique schema name
594 and t.name in inspector.get_table_names(schema=t.schema)
595 ]
596 ):
597 if savepoints:
598 with connection.begin_nested():
599 connection.execute(table.delete())
600 else:
601 connection.execute(table.delete())
602
603
604@register.init

Callers

nothing calls this directly

Calls 7

inspectFunction · 0.90
valuesMethod · 0.45
get_table_namesMethod · 0.45
begin_nestedMethod · 0.45
executeMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected