(url, idents)
| 99 | |
| 100 | @run_reap_dbs.for_db("mssql") |
| 101 | def _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") |
nothing calls this directly
no test coverage detected