init_db (database)

mantis · database, sqlite-schema, schema-migration, db-init

Initializes the SQLite database schema with tables, indexes, and schema version enforcement, raising on mismatches.

# Source: https://github.com/google/mantis | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
def init_db(db_path: str):
    """Initialize the SQLite database with tables, unique indexes, and enforce schema versioning."""
    with _db(db_path, check_version=False) as conn:
        cursor = conn.cursor()
        cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='findings'")
        has_findings = cursor.fetchone() is not None

        cursor.execute("PRAGMA user_version")
        row = cursor.fetchone()
        v = row[0] if row else 0
        if has_findings and v != CURRENT_SCHEMA_VERSION:
            raise RuntimeError(
                f"Database schema vers

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key