Skip to content

Commit d3da0b6

Browse files
feat(P0-3): Fix demo seed and prioritize pg_stat_statements
- Fix varchar(36) bug in seed script by using gen_random_uuid() - Create read-only deepsql_demo role with pg_read_all_stats - Add real workload generator (~60s) for genuine slow queries - Add sample plain-SQL dashboard that works without LLM key - Seed digest preferences to fix 'Legacy mode' display - Add curated Brain notes (exclude pg_stat_* noise) - Add sample index recommendations and performance actions - Make pg_stat_statements the primary Performance page source - Add auto-analysis on first load - Add demo-specific prompts for Agent tab (Demo Shop connection) - Add 'Use demo database' option in onboarding Exit codes: 0=success, 1=prerequisites, 2=auth, 3=connection, 4=database Co-authored-by: Venkat SF <venkatesh.sakamuri@stayflexi.com>
1 parent 27d07ea commit d3da0b6

6 files changed

Lines changed: 753 additions & 626 deletions

File tree

‎docker/postgres/init/10_create_demo_shop.sql‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,53 @@ ANALYZE audit_log;
645645
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO postgres;
646646
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO postgres;
647647

648+
-- ============================================================================
649+
-- Create read-only demo role for DeepSQL connections
650+
-- ============================================================================
651+
-- This role is used by the seed script to register demo_shop as a connection.
652+
-- Using a dedicated read-only role instead of the superuser:
653+
-- 1. Demonstrates best practices for DeepSQL connections
654+
-- 2. Avoids exposing superuser credentials in the UI
655+
-- 3. Shows realistic RBAC patterns users would follow
656+
657+
-- Drop and recreate for idempotency (role is cluster-global, not per-DB)
658+
\connect postgres
659+
DO $$
660+
BEGIN
661+
-- Terminate any connections using the role before dropping
662+
PERFORM pg_terminate_backend(pid)
663+
FROM pg_stat_activity
664+
WHERE usename = 'deepsql_demo' AND pid <> pg_backend_pid();
665+
EXCEPTION WHEN OTHERS THEN
666+
NULL; -- Ignore if no connections
667+
END $$;
668+
669+
DROP ROLE IF EXISTS deepsql_demo;
670+
CREATE ROLE deepsql_demo WITH
671+
LOGIN
672+
PASSWORD 'deepsql_demo_password'
673+
NOSUPERUSER
674+
NOCREATEDB
675+
NOCREATEROLE;
676+
677+
-- Grant pg_read_all_stats for pg_stat_statements access
678+
GRANT pg_read_all_stats TO deepsql_demo;
679+
680+
-- Grant connect to demo_shop
681+
GRANT CONNECT ON DATABASE demo_shop TO deepsql_demo;
682+
683+
-- Reconnect to demo_shop to grant table permissions
684+
\connect demo_shop
685+
686+
-- Grant read access to all tables in demo_shop
687+
GRANT USAGE ON SCHEMA public TO deepsql_demo;
688+
GRANT SELECT ON ALL TABLES IN SCHEMA public TO deepsql_demo;
689+
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO deepsql_demo;
690+
691+
-- Ensure future tables are also readable
692+
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO deepsql_demo;
693+
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON SEQUENCES TO deepsql_demo;
694+
648695
SELECT 'Demo shop database created successfully!' AS status;
649696
SELECT 'Tables: ' || COUNT(*)::text FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE';
650697
SELECT 'Products: ' || COUNT(*)::text FROM products;

0 commit comments

Comments
 (0)