Skip to content

motherduckdb/agent-skills / plugins/motherduck-skills-claude/skills/motherduck-enable-self-serve-analytics

motherduck-enable-self-serve-analytics

Verified

Roll out governed MotherDuck analytics to internal teams, choosing trusted datasets, access boundaries, and owners.

artifacts/self_serve_rollout_example.py

View on GitHub
import json
import sys
from pathlib import Path

import duckdb

sys.path.append(str(Path(__file__).resolve().parents[3]))

from scripts._lib.motherduck_artifact_utils import artifact_session


def fetch_rows(conn: duckdb.DuckDBPyConnection, sql: str) -> list[dict]:
    cursor = conn.execute(sql)
    columns = [col[0] for col in cursor.description]
    return [dict(zip(columns, row)) for row in cursor.fetchall()]


def main() -> None:
    with artifact_session(
        slug="motherduck-enable-self-serve-analytics",
        database_keys=["analytics"],
    ) as session:
        conn = session.conn
        accounts_table = session.table("analytics", "main", "accounts")
        customer_health_view = session.table("analytics", "main", "customer_health")
        conn.execute(
            f"""
            CREATE TABLE {accounts_table} (
                team VARCHAR,
                account_id INTEGER,
                status VARCHAR,
                arr DOUBLE
            )
            """
        )
        conn.executemany(
            f"INSERT INTO {accounts_table} VALUES (?, ?, ?, ?)",
            [
                ("sales", 1, "healthy", 12000.0),
                ("sales", 2, "watch", 7000.0),
                ("success", 3, "healthy", 9000.0),
                ("success", 4, "risk", 5000.0),
            ],
        )
        conn.execute(
            f"""
            CREATE OR REPLACE VIEW {customer_health_view} AS
            SELECT team, account_id, status, arr
            FROM {accounts_table}
            WHERE status IS NOT NULL
            """
        )

        result = {
            "backend": session.describe(),
            "first_audience": "customer success",
            "first_asset": f"team KPI Dive on top of {customer_health_view}",
            "team_kpis": fetch_rows(
                conn,
                f"""
                SELECT team, COUNT(*) AS total_accounts, SUM(arr) AS total_arr
                FROM {customer_health_view}
                GROUP BY 1
                ORDER BY total_arr DESC
                """,
            ),
        }
        print(json.dumps(result, indent=2))


if __name__ == "__main__":
    main()
deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall