(db_path: Path)
| 64 | |
| 65 | |
| 66 | def _database_has_required_tables(db_path: Path) -> bool: |
| 67 | if not db_path.exists(): |
| 68 | return False |
| 69 | |
| 70 | try: |
| 71 | conn = sqlite3.connect(db_path) |
| 72 | try: |
| 73 | rows = conn.execute( |
| 74 | "SELECT name FROM sqlite_master WHERE type='table'" |
| 75 | ).fetchall() |
| 76 | finally: |
| 77 | conn.close() |
| 78 | except sqlite3.Error: |
| 79 | return False |
| 80 | |
| 81 | table_names = {row[0] for row in rows} |
| 82 | return REQUIRED_TABLES.issubset(table_names) |
| 83 | |
| 84 | |
| 85 | def ensure_database(root_dir: Path = PROJECT_ROOT) -> Path: |
no test coverage detected