MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _reap_mssql_dbs

Function _reap_mssql_dbs

lib/sqlalchemy/dialects/mssql/provision.py:101–125  ·  view source on GitHub ↗
(url, idents)

Source from the content-addressed store, hash-verified

99
100@run_reap_dbs.for_db("mssql")
101def _reap_mssql_dbs(url, idents):
102 log.info("db reaper connecting to %r", url)
103 eng = create_engine(url)
104 with eng.connect().execution_options(isolation_level="AUTOCOMMIT") as conn:
105 log.info("identifiers in file: %s", ", ".join(idents))
106
107 to_reap = conn.exec_driver_sql(
108 "select d.name from sys.databases as d where name "
109 "like 'TEST_%' and not exists (select session_id "
110 "from sys.dm_exec_sessions "
111 "where database_id=d.database_id)"
112 )
113 all_names = {dbname.lower() for (dbname,) in to_reap}
114 to_drop = set()
115 for name in all_names:
116 if name in idents:
117 to_drop.add(name)
118
119 dropped = total = 0
120 for total, dbname in enumerate(to_drop, 1):
121 if _mssql_drop_ignore(conn, dbname):
122 dropped += 1
123 log.info(
124 "Dropped %d out of %d stale databases detected", dropped, total
125 )
126
127
128@temp_table_keyword_args.for_db("mssql")

Callers

nothing calls this directly

Calls 9

create_engineFunction · 0.85
_mssql_drop_ignoreFunction · 0.85
lowerMethod · 0.80
infoMethod · 0.45
execution_optionsMethod · 0.45
connectMethod · 0.45
joinMethod · 0.45
exec_driver_sqlMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected