(
engine,
inspector,
schema=None,
consider_schemas=(None,),
include_names=None,
)
| 393 | |
| 394 | |
| 395 | def drop_all_tables( |
| 396 | engine, |
| 397 | inspector, |
| 398 | schema=None, |
| 399 | consider_schemas=(None,), |
| 400 | include_names=None, |
| 401 | ): |
| 402 | if include_names is not None: |
| 403 | include_names = set(include_names) |
| 404 | |
| 405 | if schema is not None: |
| 406 | assert consider_schemas == ( |
| 407 | None, |
| 408 | ), "consider_schemas and schema are mutually exclusive" |
| 409 | consider_schemas = (schema,) |
| 410 | |
| 411 | with engine.begin() as conn: |
| 412 | for table_key, fkcs in reversed( |
| 413 | inspector.sort_tables_on_foreign_key_dependency( |
| 414 | consider_schemas=consider_schemas |
| 415 | ) |
| 416 | ): |
| 417 | if table_key: |
| 418 | if ( |
| 419 | include_names is not None |
| 420 | and table_key[1] not in include_names |
| 421 | ): |
| 422 | continue |
| 423 | conn.execute( |
| 424 | DropTable( |
| 425 | Table(table_key[1], MetaData(), schema=table_key[0]) |
| 426 | ) |
| 427 | ) |
| 428 | elif fkcs: |
| 429 | if not engine.dialect.supports_alter: |
| 430 | continue |
| 431 | for t_key, fkc in fkcs: |
| 432 | if ( |
| 433 | include_names is not None |
| 434 | and t_key[1] not in include_names |
| 435 | ): |
| 436 | continue |
| 437 | tb = Table( |
| 438 | t_key[1], |
| 439 | MetaData(), |
| 440 | Column("x", Integer), |
| 441 | Column("y", Integer), |
| 442 | schema=t_key[0], |
| 443 | ) |
| 444 | conn.execute( |
| 445 | DropConstraint( |
| 446 | ForeignKeyConstraint([tb.c.x], [tb.c.y], name=fkc) |
| 447 | ), |
| 448 | ) |
| 449 | |
| 450 | |
| 451 | def teardown_events(event_cls): |
no test coverage detected