MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / drop_all_tables

Function drop_all_tables

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

Source from the content-addressed store, hash-verified

393
394
395def 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
451def 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