Skip to content

Commit 75be4ae

Browse files
fix(seed): generate digest from actual seeded data instead of hardcoded
- Try to trigger real digest via /admin/slack/digest/trigger first - If Slack not configured, build digest SQL from actual index_recommendations - Digest content reflects real seeded data, not canned prose Co-authored-by: Venkat SF <venkatesh.sakamuri@stayflexi.com>
1 parent 8073fc3 commit 75be4ae

1 file changed

Lines changed: 61 additions & 31 deletions

File tree

‎scripts/self-host/seed-demo-data.sh‎

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -771,17 +771,51 @@ SELECT 'Digest preferences seeded' AS status;
771771
EOSQL
772772
echo " Digest preferences created."
773773

774-
# Now create an actual digest entry so it shows in the web UI
775-
echo " Creating sample digest entry (visible in web Digest section)..."
774+
# Trigger a real digest using DigestInsightAssemblerService
775+
# This generates content from actual demo data (index recommendations, slow queries, etc.)
776+
echo " Triggering real digest generation..."
776777

777-
# Get preference ID for linking
778-
pref_id="$(compose exec -T postgres psql -U postgres -d dba_agent -At -c \
779-
"SELECT id FROM digest_preferences WHERE user_id = ${admin_id} AND connection_id = '${connection_id}' LIMIT 1" 2>/dev/null || echo "")"
778+
trigger_result="$(curl -sS -b "$cookie_jar" \
779+
-H 'Content-Type: application/json' \
780+
-X POST "$base/admin/slack/digest/trigger" 2>/dev/null || echo "{}")"
780781

781-
compose exec -T postgres psql -U postgres -d dba_agent -v ON_ERROR_STOP=1 <<EOSQL
782-
-- Create a sample digest log entry that shows in the web Digest section
783-
-- This is a static demo digest showing what real digests look like
784-
782+
if [[ "$trigger_result" == *"triggered\":true"* ]]; then
783+
echo " Real digest generated successfully."
784+
# Wait a moment for the async digest to be written
785+
sleep 2
786+
else
787+
echo " Note: Digest trigger returned: $trigger_result"
788+
echo " This is expected if Slack is not configured - digest shows in web UI only."
789+
790+
# If no Slack, we need to manually call the assembler and save the result
791+
# The trigger endpoint requires Slack to be configured for actual delivery
792+
# For web-only display, insert a digest based on seeded index recommendations
793+
echo " Generating web-only digest from seeded data..."
794+
795+
pref_id="$(compose exec -T postgres psql -U postgres -d dba_agent -At -c \
796+
"SELECT id FROM digest_preferences WHERE user_id = ${admin_id} AND connection_id = '${connection_id}' LIMIT 1" 2>/dev/null || echo "")"
797+
798+
# Build digest content from actual seeded data
799+
compose exec -T postgres psql -U postgres -d dba_agent -v ON_ERROR_STOP=1 <<EOSQL
800+
-- Generate digest from actual seeded index recommendations
801+
-- This is deterministic content based on what was seeded, not hardcoded prose
802+
803+
WITH index_recs AS (
804+
SELECT table_name, index_name, priority, estimated_impact, reason
805+
FROM index_recommendations
806+
WHERE connection_id = '${connection_id}' AND status = 'PENDING'
807+
ORDER BY priority ASC, estimated_impact DESC
808+
LIMIT 3
809+
),
810+
rec_summary AS (
811+
SELECT
812+
COUNT(*) as rec_count,
813+
string_agg(
814+
'• *' || index_name || '* on ' || table_name || ' (' || priority || ' priority, ' || estimated_impact || '% impact)',
815+
E'\n'
816+
) as rec_list
817+
FROM index_recs
818+
)
785819
INSERT INTO slack_digest_log (
786820
connection_id, connection_name, channel_id, content, headline,
787821
sent_at, status, recipient_username, recipient_role, persona_tag,
@@ -790,42 +824,36 @@ INSERT INTO slack_digest_log (
790824
SELECT
791825
'${connection_id}',
792826
'${DEEPSQL_SEED_CONNECTION_NAME}',
793-
NULL, -- No Slack channel for web-only display
827+
NULL,
794828
'*🗄️ DB Health Briefing: ${DEEPSQL_SEED_CONNECTION_NAME}*
795-
_' || TO_CHAR(NOW(), 'FMDay, FMMonth DD') || ' · Quick Wins Ready_
829+
_' || TO_CHAR(NOW(), 'FMDay, FMMonth DD') || ' · ' || rec_count || ' Index Recommendations_
796830
797831
────────────────────────────────
798832
799-
*🔦 Performance Spotlight*
800-
801-
• *3 high-priority index recommendations* ready to apply
802-
- \`idx_orders_status_payment_created\` (orders): 85% estimated improvement
803-
- \`idx_audit_log_table_changed\` (audit_log): Fixes 89s slow queries
804-
- \`idx_products_name_trgm\` (products): Better ILIKE performance
833+
*🔦 Index Recommendations*
805834
806-
• Top slow query pattern: \`SELECT COUNT(*) FROM orders WHERE LOWER(status) = ...\`
807-
↳ Avg 45ms, called 1.2K times/day — index prevents full scan
835+
' || COALESCE(rec_list, 'No pending recommendations') || '
808836
809837
────────────────────────────────
810838
811-
*🎯 Quick Wins*
839+
*🎯 Quick Actions*
812840
813-
• *CREATE INDEX idx_orders_status_payment_created* — Estimated 38s daily savings
814-
• Review audit_log growth (50K+ rows, missing index on changed_at)
815-
• Consider trigram index for product search ILIKE patterns
841+
• Review slow queries in Performance tab (pg_stat_statements)
842+
• Apply high-priority indexes from Index Advisor
843+
• Check Brain notes for table documentation
816844
817845
────────────────────────────────
818846
819-
*📈 Brain Intelligence*
847+
*📈 Database Status*
820848
821-
• Workload analysis complete — 7 distinct query patterns identified
822-
• Database health score: Pending initial assessment
823-
• 5 curated schema notes ready for review
849+
• Connection: ${DEEPSQL_SEED_CONNECTION_NAME}
850+
• Role: deepsql_demo (read-only + pg_read_all_stats)
851+
• pg_stat_statements: Enabled and tracking queries
824852
825853
────────────────────────────────
826854
827-
_Powered by DeepSQL · This digest runs daily at 9:00 AM_',
828-
'Quick Wins Ready',
855+
_Powered by DeepSQL · Generated from actual database analysis_',
856+
rec_count || ' Index Recommendations',
829857
NOW(),
830858
'SENT',
831859
'${DEEPSQL_INITIAL_ADMIN_EMAIL}',
@@ -834,15 +862,17 @@ _Powered by DeepSQL · This digest runs daily at 9:00 AM_',
834862
'SLACK_DM',
835863
${pref_id:-NULL},
836864
true
865+
FROM rec_summary
837866
WHERE NOT EXISTS (
838867
SELECT 1 FROM slack_digest_log
839868
WHERE connection_id = '${connection_id}'
840869
AND recipient_username = '${DEEPSQL_INITIAL_ADMIN_EMAIL}'
841870
);
842871
843-
SELECT 'Sample digest entry created' AS status;
872+
SELECT 'Digest entry created from seeded data' AS status;
844873
EOSQL
845-
echo " Sample digest entry created."
874+
echo " Web-only digest created from actual seeded data."
875+
fi
846876
else
847877
echo " Skipping digest preferences (missing connection or admin ID)"
848878
fi

0 commit comments

Comments
 (0)