@staticmethod
def ensure_db(conn):
    """
        Ensure base tables setup
            :param conn: Connection to sqlite instance
        """
    cursor = conn.cursor()
    cursor.execute(
        """CREATE TABLE IF NOT EXISTS pieces (id INTEGER PRIMARY KEY ASC,
                                                path TEXT NOT NULL,
                                                name TEXT NOT NULL
                        )"""
        )
    cursor.execute(
        """CREATE TABLE IF NOT EXISTS parts (id INTEGER PRIMARY KEY ASC,
                                                piece_id INTEGER NOT NULL,
                                                name TEXT NOT NULL,
                        FOREIGN KEY (piece_id) REFERENCES pieces(id))"""
        )
    cursor.execute(
        """CREATE TABLE IF NOT EXISTS stemmers (id INTEGER PRIMARY KEY ASC,
                                                    name TEXT NOT NULL
                        )"""
        )
    cursor.execute(
        """CREATE TABLE IF NOT EXISTS snippets (id INTEGER PRIMARY KEY ASC,
                                                    piece_id INTEGER NOT NULL,
                                                    part_id INTEGER NOT NULL,
                                                    offset INTEGER NOT NULL,
                                                    FOREIGN KEY (part_id) REFERENCES parts(id),
                                                    FOREIGN KEY (piece_id) REFERENCES pieces(id),
                                                    CONSTRAINT unique_snippet UNIQUE (piece_id, part_id, offset)
                        )"""
        )
    cursor.execute(
        """CREATE TABLE IF NOT EXISTS stems (id INTEGER PRIMARY KEY ASC,
                                                stemmer_id INTEGER NOT NULL,
                                                stem TEXT NOT NULL,
                                                FOREIGN KEY (stemmer_id) REFERENCES stemmers(id),
                                                CONSTRAINT unique_stem UNIQUE (stemmer_id, stem)
                        )"""
        )
    cursor.execute(
        """CREATE TABLE IF NOT EXISTS entries (id INTEGER PRIMARY KEY ASC,
                                                stem_id INTEGER NOT NULL,
                                                snippet_id INTEGER NOT NULL,
                                                FOREIGN KEY (stem_id) REFERENCES stems(id),
                                                FOREIGN KEY (snippet_id) REFERENCES snippets(id),
                                                CONSTRAINT unique_entry UNIQUE (stem_id, snippet_id)
                        )"""
        )
    conn.commit()
    cursor.execute('CREATE INDEX IF NOT EXISTS piece_path_idx ON pieces(path)')
    cursor.execute(
        'CREATE INDEX IF NOT EXISTS stemmer_name_idx ON stemmers(name)')
    cursor.execute(
        'CREATE INDEX IF NOT EXISTS snippet_piece_idx ON snippets(piece_id)')
    cursor.execute(
        'CREATE INDEX IF NOT EXISTS snippet_part_idx ON snippets(part_id)')
    cursor.execute(
        'CREATE INDEX IF NOT EXISTS part_piece_idx ON parts(piece_id)')
    cursor.execute(
        'CREATE INDEX IF NOT EXISTS stem_stemmer_idx ON stems(stemmer_id)')
    cursor.execute('CREATE INDEX IF NOT EXISTS stem_stem_idx ON stems(stem)')
    cursor.execute(
        'CREATE INDEX IF NOT EXISTS entry_stem_idx ON entries(stem_id)')
