CREATE VIEW service_meta_indices AS
WITH
    tables AS (
        SELECT tbl_name AS table_name, sql
        FROM sqlite_master
        WHERE type = 'table'
          AND name NOT LIKE 'sqlite_%'
    ),
    index_list AS (
        SELECT table_name, name AS index_name, "unique", origin, partial
        FROM tables AS t, pragma_index_list(t.table_name)
    ),
    index_columns AS (
        SELECT il.*, name AS col_name, cid, seqno, "desc", coll, "key"
        FROM index_list AS il, pragma_index_xinfo(il.index_name)
        ORDER BY index_name, seqno
    ),
    noddl_indices AS (
        SELECT table_name, index_name,
               json_group_array(col_name) AS col_names,
               "unique", origin, partial
        FROM index_columns
        GROUP BY index_name
    ),
    indices AS (
        SELECT bi.*, sm.sql
        FROM noddl_indices AS bi, sqlite_master AS sm
        WHERE type = 'index' AND index_name = name
        ORDER BY table_name, index_name
    )
SELECT * FROM indices;