MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / drop_all_tables

Function drop_all_tables

lib/sqlalchemy/testing/util.py:436–489  ·  view source on GitHub ↗
(
    engine,
    inspector,
    schema=None,
    consider_schemas=(None,),
    include_names=None,
)

Source from the content-addressed store, hash-verified

434
435
436def drop_all_tables(
437 engine,
438 inspector,
439 schema=None,
440 consider_schemas=(None,),
441 include_names=None,
442):
443 if include_names is not None:
444 include_names = set(include_names)
445
446 if schema is not None:
447 assert consider_schemas == (
448 None,
449 ), "consider_schemas and schema are mutually exclusive"
450 consider_schemas = (schema,)
451
452 with engine.begin() as conn:
453 for table_key, fkcs in reversed(
454 inspector.sort_tables_on_foreign_key_dependency(
455 consider_schemas=consider_schemas
456 )
457 ):
458 if table_key:
459 if (
460 include_names is not None
461 and table_key[1] not in include_names
462 ):
463 continue
464 conn.execute(
465 DropTable(
466 Table(table_key[1], MetaData(), schema=table_key[0])
467 )
468 )
469 elif fkcs:
470 if not engine.dialect.supports_alter:
471 continue
472 for t_key, fkc in fkcs:
473 if (
474 include_names is not None
475 and t_key[1] not in include_names
476 ):
477 continue
478 tb = Table(
479 t_key[1],
480 MetaData(),
481 Column("x", Integer),
482 Column("y", Integer),
483 schema=t_key[0],
484 )
485 conn.execute(
486 DropConstraint(
487 ForeignKeyConstraint([tb.c.x], [tb.c.y], name=fkc)
488 )
489 )
490
491
492def teardown_events(event_cls):

Callers 1

goFunction · 0.85

Calls 9

DropTableClass · 0.85
MetaDataClass · 0.85
DropConstraintClass · 0.85
TableFunction · 0.70
ColumnFunction · 0.70
beginMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected