an absolutely foolproof delete from all tables routine. dialects should override this to add special instructions like disable constraints etc.
(connection, cfg, metadata)
| 570 | |
| 571 | @register.init |
| 572 | def 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 |
nothing calls this directly
no test coverage detected