@caddis/cli 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +150 -1
- package/bundles/antigravity-plugin/agents/code-reviewer.md +47 -0
- package/bundles/antigravity-plugin/agents/preflight.md +53 -0
- package/bundles/antigravity-plugin/guard_agy.py +338 -0
- package/bundles/antigravity-plugin/hooks.json +36 -0
- package/bundles/antigravity-plugin/mcp_config.json +8 -0
- package/bundles/antigravity-plugin/mcp_ping_server.py +55 -0
- package/bundles/antigravity-plugin/plugin.json +5 -0
- package/bundles/antigravity-plugin/session_end_agy.py +57 -0
- package/bundles/antigravity-plugin/skills/_registry.md +115 -0
- package/bundles/antigravity-plugin/skills/add-rules/SKILL.md +45 -0
- package/bundles/antigravity-plugin/skills/api-design/SKILL.md +249 -0
- package/bundles/antigravity-plugin/skills/backend-development/SKILL.md +305 -0
- package/bundles/antigravity-plugin/skills/best-practices/SKILL.md +500 -0
- package/bundles/antigravity-plugin/skills/best-practices/agents/best-practices-referencer.md +263 -0
- package/bundles/antigravity-plugin/skills/best-practices/agents/codebase-context-builder.md +326 -0
- package/bundles/antigravity-plugin/skills/best-practices/agents/task-intent-analyzer.md +245 -0
- package/bundles/antigravity-plugin/skills/best-practices/references/anti-patterns.md +571 -0
- package/bundles/antigravity-plugin/skills/best-practices/references/before-after-examples.md +1114 -0
- package/bundles/antigravity-plugin/skills/best-practices/references/best-practices-guide.md +513 -0
- package/bundles/antigravity-plugin/skills/best-practices/references/common-workflows.md +692 -0
- package/bundles/antigravity-plugin/skills/best-practices/references/prompt-patterns.md +547 -0
- package/bundles/antigravity-plugin/skills/brainstorming/SKILL.md +57 -0
- package/bundles/antigravity-plugin/skills/ci-cd-pipeline/SKILL.md +315 -0
- package/bundles/antigravity-plugin/skills/code-documentation/SKILL.md +271 -0
- package/bundles/antigravity-plugin/skills/code-review/SKILL.md +122 -0
- package/bundles/antigravity-plugin/skills/codebase-audit/SKILL.md +204 -0
- package/bundles/antigravity-plugin/skills/context-curator/SKILL.md +157 -0
- package/bundles/antigravity-plugin/skills/cross-review/SKILL.md +40 -0
- package/bundles/antigravity-plugin/skills/css-architecture/SKILL.md +305 -0
- package/bundles/antigravity-plugin/skills/css-architecture/references/RESPONSIVE-DESIGN.md +604 -0
- package/bundles/antigravity-plugin/skills/database-design/SKILL.md +177 -0
- package/bundles/antigravity-plugin/skills/db-diagram/SKILL.md +148 -0
- package/bundles/antigravity-plugin/skills/db-diagram/scripts/sql_to_graph.py +1212 -0
- package/bundles/antigravity-plugin/skills/digress/SKILL.md +61 -0
- package/bundles/antigravity-plugin/skills/draw-io/SKILL.md +162 -0
- package/bundles/antigravity-plugin/skills/draw-io/references/aws-icons.md +677 -0
- package/bundles/antigravity-plugin/skills/draw-io/references/layout-guidelines.md +142 -0
- package/bundles/antigravity-plugin/skills/draw-io/references/troubleshooting.md +118 -0
- package/bundles/antigravity-plugin/skills/draw-io/references/workflows.md +103 -0
- package/bundles/antigravity-plugin/skills/draw-io/scripts/convert-drawio-to-png.sh +25 -0
- package/bundles/antigravity-plugin/skills/draw-io/scripts/find_aws_icon.py +79 -0
- package/bundles/antigravity-plugin/skills/error-handling/SKILL.md +260 -0
- package/bundles/antigravity-plugin/skills/excalidraw-db/SKILL.md +38 -0
- package/bundles/antigravity-plugin/skills/fastapi-dev/SKILL.md +300 -0
- package/bundles/antigravity-plugin/skills/feature-plan/SKILL.md +198 -0
- package/bundles/antigravity-plugin/skills/frontend-design/SKILL.md +193 -0
- package/bundles/antigravity-plugin/skills/frontend-design/references/my-tech-stack.md +127 -0
- package/bundles/antigravity-plugin/skills/gh-cli/SKILL.md +195 -0
- package/bundles/antigravity-plugin/skills/git-commit/SKILL.md +285 -0
- package/bundles/antigravity-plugin/skills/golden-plan/SKILL.md +577 -0
- package/bundles/antigravity-plugin/skills/handoff/SKILL.md +100 -0
- package/bundles/antigravity-plugin/skills/implement/SKILL.md +114 -0
- package/bundles/antigravity-plugin/skills/javascript-typescript/SKILL.md +142 -0
- package/bundles/antigravity-plugin/skills/kb/SKILL.md +60 -0
- package/bundles/antigravity-plugin/skills/mermaid-db/SKILL.md +33 -0
- package/bundles/antigravity-plugin/skills/mermaid-diagrams/SKILL.md +236 -0
- package/bundles/antigravity-plugin/skills/mermaid-diagrams/references/ENHANCEMENTS.md +264 -0
- package/bundles/antigravity-plugin/skills/mermaid-diagrams/references/MERMAID-SUMMARY.md +137 -0
- package/bundles/antigravity-plugin/skills/mermaid-diagrams/references/advanced-features.md +556 -0
- package/bundles/antigravity-plugin/skills/mermaid-diagrams/references/architecture-diagrams.md +192 -0
- package/bundles/antigravity-plugin/skills/mermaid-diagrams/references/c4-diagrams.md +410 -0
- package/bundles/antigravity-plugin/skills/mermaid-diagrams/references/class-diagrams.md +361 -0
- package/bundles/antigravity-plugin/skills/mermaid-diagrams/references/erd-diagrams.md +510 -0
- package/bundles/antigravity-plugin/skills/mermaid-diagrams/references/flowcharts.md +450 -0
- package/bundles/antigravity-plugin/skills/mermaid-diagrams/references/sequence-diagrams.md +394 -0
- package/bundles/antigravity-plugin/skills/mermaid-diagrams/references/troubleshooting.md +335 -0
- package/bundles/antigravity-plugin/skills/mermaid-diagrams/references/workflows.md +418 -0
- package/bundles/antigravity-plugin/skills/migrate-dir/SKILL.md +68 -0
- package/bundles/antigravity-plugin/skills/mockup/SKILL.md +242 -0
- package/bundles/antigravity-plugin/skills/particle-art/SKILL.md +243 -0
- package/bundles/antigravity-plugin/skills/particle-art/references/canvas-utils.ts +171 -0
- package/bundles/antigravity-plugin/skills/particle-art/references/dot-field.template.tsx +203 -0
- package/bundles/antigravity-plugin/skills/particle-art/references/flow-field.template.tsx +263 -0
- package/bundles/antigravity-plugin/skills/particle-art/references/node-shape.template.tsx +261 -0
- package/bundles/antigravity-plugin/skills/particle-art/references/shape-sampler.ts +281 -0
- package/bundles/antigravity-plugin/skills/particle-art/references/stipple-morph.template.tsx +167 -0
- package/bundles/antigravity-plugin/skills/particle-art/references/stipple.template.tsx +175 -0
- package/bundles/antigravity-plugin/skills/particle-art/references/trail-ghost.template.tsx +266 -0
- package/bundles/antigravity-plugin/skills/particle-art/references/usage-examples.md +320 -0
- package/bundles/antigravity-plugin/skills/playwright/API_REFERENCE.md +653 -0
- package/bundles/antigravity-plugin/skills/playwright/SKILL.md +454 -0
- package/bundles/antigravity-plugin/skills/playwright/lib/helpers.js +441 -0
- package/bundles/antigravity-plugin/skills/playwright/package.json +26 -0
- package/bundles/antigravity-plugin/skills/playwright/run.js +228 -0
- package/bundles/antigravity-plugin/skills/prd/SKILL.md +107 -0
- package/bundles/antigravity-plugin/skills/preflight/SKILL.md +435 -0
- package/bundles/antigravity-plugin/skills/python/SKILL.md +388 -0
- package/bundles/antigravity-plugin/skills/react-best-practices/SKILL.md +269 -0
- package/bundles/antigravity-plugin/skills/react-dev/README.md +404 -0
- package/bundles/antigravity-plugin/skills/react-dev/SKILL.md +459 -0
- package/bundles/antigravity-plugin/skills/react-dev/examples/generic-components.md +579 -0
- package/bundles/antigravity-plugin/skills/react-dev/examples/server-components.md +579 -0
- package/bundles/antigravity-plugin/skills/react-dev/references/event-handlers.md +574 -0
- package/bundles/antigravity-plugin/skills/react-dev/references/hooks.md +456 -0
- package/bundles/antigravity-plugin/skills/react-dev/references/react-19-patterns.md +638 -0
- package/bundles/antigravity-plugin/skills/react-dev/references/react-router.md +1002 -0
- package/bundles/antigravity-plugin/skills/react-dev/references/tanstack-router.md +587 -0
- package/bundles/antigravity-plugin/skills/refactoring/SKILL.md +486 -0
- package/bundles/antigravity-plugin/skills/resume/SKILL.md +36 -0
- package/bundles/antigravity-plugin/skills/security-review/SKILL.md +196 -0
- package/bundles/antigravity-plugin/skills/setup-project-ai/SKILL.md +61 -0
- package/bundles/antigravity-plugin/skills/ship/SKILL.md +107 -0
- package/bundles/antigravity-plugin/skills/ship-merge/SKILL.md +103 -0
- package/bundles/antigravity-plugin/skills/ship-pr/SKILL.md +102 -0
- package/bundles/antigravity-plugin/skills/skill-creator/LICENSE.txt +202 -0
- package/bundles/antigravity-plugin/skills/skill-creator/SKILL.md +491 -0
- package/bundles/antigravity-plugin/skills/skill-creator/agents/analyzer.md +274 -0
- package/bundles/antigravity-plugin/skills/skill-creator/agents/comparator.md +202 -0
- package/bundles/antigravity-plugin/skills/skill-creator/agents/grader.md +223 -0
- package/bundles/antigravity-plugin/skills/skill-creator/assets/eval_review.html +146 -0
- package/bundles/antigravity-plugin/skills/skill-creator/eval-viewer/generate_review.py +471 -0
- package/bundles/antigravity-plugin/skills/skill-creator/eval-viewer/viewer.html +1325 -0
- package/bundles/antigravity-plugin/skills/skill-creator/references/schemas.md +430 -0
- package/bundles/antigravity-plugin/skills/skill-creator/scripts/__init__.py +0 -0
- package/bundles/antigravity-plugin/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
- package/bundles/antigravity-plugin/skills/skill-creator/scripts/generate_report.py +326 -0
- package/bundles/antigravity-plugin/skills/skill-creator/scripts/improve_description.py +247 -0
- package/bundles/antigravity-plugin/skills/skill-creator/scripts/package_skill.py +136 -0
- package/bundles/antigravity-plugin/skills/skill-creator/scripts/quick_validate.py +103 -0
- package/bundles/antigravity-plugin/skills/skill-creator/scripts/run_eval.py +310 -0
- package/bundles/antigravity-plugin/skills/skill-creator/scripts/run_loop.py +328 -0
- package/bundles/antigravity-plugin/skills/skill-creator/scripts/utils.py +47 -0
- package/bundles/antigravity-plugin/skills/sql/SKILL.md +321 -0
- package/bundles/antigravity-plugin/skills/tdd/SKILL.md +37 -0
- package/bundles/antigravity-plugin/skills/tdd-workflow/SKILL.md +188 -0
- package/bundles/antigravity-plugin/skills/technical-writing/SKILL.md +286 -0
- package/bundles/antigravity-plugin/skills/test-strategy/SKILL.md +155 -0
- package/bundles/antigravity-plugin/skills/ui-brief/SKILL.md +84 -0
- package/bundles/antigravity-plugin/skills/ui-review/SKILL.md +176 -0
- package/bundles/antigravity-plugin/skills/ui-review/references/framework-fixes.md +471 -0
- package/bundles/antigravity-plugin/skills/ui-review/references/visual-checklist.md +236 -0
- package/bundles/antigravity-plugin/skills/usage-review/SKILL.md +77 -0
- package/bundles/antigravity-plugin/skills/use-model/SKILL.md +64 -0
- package/bundles/antigravity-plugin/skills/using-git-worktrees/SKILL.md +217 -0
- package/bundles/antigravity-plugin/skills/version/SKILL.md +18 -0
- package/bundles/antigravity-plugin/skills/warm-editorial-ui/DESIGN_TOKENS.md +487 -0
- package/bundles/antigravity-plugin/skills/warm-editorial-ui/IMPLEMENTATION_GUIDE.md +177 -0
- package/bundles/antigravity-plugin/skills/warm-editorial-ui/SKILL.md +732 -0
- package/bundles/antigravity-plugin/skills/webapp-testing/LICENSE.txt +202 -0
- package/bundles/antigravity-plugin/skills/webapp-testing/SKILL.md +97 -0
- package/bundles/antigravity-plugin/skills/webapp-testing/examples/console_logging.py +35 -0
- package/bundles/antigravity-plugin/skills/webapp-testing/examples/element_discovery.py +40 -0
- package/bundles/antigravity-plugin/skills/webapp-testing/examples/static_html_automation.py +33 -0
- package/bundles/antigravity-plugin/skills/webapp-testing/scripts/with_server.py +106 -0
- package/bundles/antigravity-plugin/skills/windows-deployment/SKILL.md +880 -0
- package/bundles/antigravity-plugin/skills/writing-plans/SKILL.md +384 -0
- package/bundles/antigravity-plugin/statusline-command-agy.sh +91 -0
- package/bundles/antigravity-plugin/warm_start_agy.py +149 -0
- package/bundles/manifest.json +6 -0
- package/dist/cli.js +5363 -0
- package/package.json +61 -4
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: database-design
|
|
3
|
+
description: Database schema design, optimization, and migration patterns for PostgreSQL, MySQL, and NoSQL databases. Use for designing schemas, writing migrations, or optimizing queries.
|
|
4
|
+
source: wshobson/agents
|
|
5
|
+
license: MIT
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Database Design
|
|
9
|
+
|
|
10
|
+
## Schema Design Principles
|
|
11
|
+
|
|
12
|
+
### Normalization Guidelines
|
|
13
|
+
```sql
|
|
14
|
+
-- 1NF: Atomic values, no repeating groups
|
|
15
|
+
-- 2NF: No partial dependencies on composite keys
|
|
16
|
+
-- 3NF: No transitive dependencies
|
|
17
|
+
|
|
18
|
+
-- Users table (normalized)
|
|
19
|
+
CREATE TABLE users (
|
|
20
|
+
id SERIAL PRIMARY KEY,
|
|
21
|
+
email VARCHAR(255) UNIQUE NOT NULL,
|
|
22
|
+
created_at TIMESTAMPTZ DEFAULT NOW()
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
-- Addresses table (separate entity)
|
|
26
|
+
CREATE TABLE addresses (
|
|
27
|
+
id SERIAL PRIMARY KEY,
|
|
28
|
+
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
|
|
29
|
+
street VARCHAR(255),
|
|
30
|
+
city VARCHAR(100),
|
|
31
|
+
country VARCHAR(100),
|
|
32
|
+
is_primary BOOLEAN DEFAULT false
|
|
33
|
+
);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Denormalization for Performance
|
|
37
|
+
```sql
|
|
38
|
+
-- When read performance matters more than write consistency
|
|
39
|
+
CREATE TABLE order_summaries (
|
|
40
|
+
id SERIAL PRIMARY KEY,
|
|
41
|
+
order_id INTEGER REFERENCES orders(id),
|
|
42
|
+
customer_name VARCHAR(255), -- Denormalized from customers
|
|
43
|
+
total_amount DECIMAL(10,2),
|
|
44
|
+
item_count INTEGER,
|
|
45
|
+
last_updated TIMESTAMPTZ DEFAULT NOW()
|
|
46
|
+
);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Index Design
|
|
50
|
+
|
|
51
|
+
### Common Index Patterns
|
|
52
|
+
```sql
|
|
53
|
+
-- B-tree (default) for equality and range queries
|
|
54
|
+
CREATE INDEX idx_users_email ON users(email);
|
|
55
|
+
|
|
56
|
+
-- Composite index (order matters!)
|
|
57
|
+
CREATE INDEX idx_orders_user_date ON orders(user_id, created_at DESC);
|
|
58
|
+
|
|
59
|
+
-- Partial index for specific conditions
|
|
60
|
+
CREATE INDEX idx_active_users ON users(email) WHERE deleted_at IS NULL;
|
|
61
|
+
|
|
62
|
+
-- GIN index for array/JSONB columns
|
|
63
|
+
CREATE INDEX idx_posts_tags ON posts USING GIN(tags);
|
|
64
|
+
|
|
65
|
+
-- Covering index (includes additional columns)
|
|
66
|
+
CREATE INDEX idx_orders_covering ON orders(user_id) INCLUDE (total, status);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Index Analysis
|
|
70
|
+
```sql
|
|
71
|
+
-- Check index usage
|
|
72
|
+
SELECT
|
|
73
|
+
schemaname, tablename, indexname,
|
|
74
|
+
idx_scan, idx_tup_read, idx_tup_fetch
|
|
75
|
+
FROM pg_stat_user_indexes
|
|
76
|
+
ORDER BY idx_scan DESC;
|
|
77
|
+
|
|
78
|
+
-- Find missing indexes
|
|
79
|
+
SELECT
|
|
80
|
+
relname, seq_scan, seq_tup_read,
|
|
81
|
+
idx_scan, idx_tup_fetch
|
|
82
|
+
FROM pg_stat_user_tables
|
|
83
|
+
WHERE seq_scan > idx_scan
|
|
84
|
+
ORDER BY seq_tup_read DESC;
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Migration Patterns
|
|
88
|
+
|
|
89
|
+
### Safe Migration Template
|
|
90
|
+
```sql
|
|
91
|
+
-- Always use transactions
|
|
92
|
+
BEGIN;
|
|
93
|
+
|
|
94
|
+
-- Add column with default (non-blocking in PG 11+)
|
|
95
|
+
ALTER TABLE users ADD COLUMN status VARCHAR(20) DEFAULT 'active';
|
|
96
|
+
|
|
97
|
+
-- Create index concurrently (doesn't lock table)
|
|
98
|
+
CREATE INDEX CONCURRENTLY idx_users_status ON users(status);
|
|
99
|
+
|
|
100
|
+
-- Backfill data in batches
|
|
101
|
+
UPDATE users SET status = 'active' WHERE status IS NULL AND id BETWEEN 1 AND 10000;
|
|
102
|
+
|
|
103
|
+
COMMIT;
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Zero-Downtime Migrations
|
|
107
|
+
```
|
|
108
|
+
1. Add new column (nullable)
|
|
109
|
+
2. Deploy code that writes to both columns
|
|
110
|
+
3. Backfill old data
|
|
111
|
+
4. Deploy code that reads from new column
|
|
112
|
+
5. Remove old column
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Query Optimization
|
|
116
|
+
|
|
117
|
+
### EXPLAIN Analysis
|
|
118
|
+
```sql
|
|
119
|
+
-- Always use EXPLAIN ANALYZE
|
|
120
|
+
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
|
|
121
|
+
SELECT * FROM orders WHERE user_id = 123 AND status = 'pending';
|
|
122
|
+
|
|
123
|
+
-- Key metrics to watch:
|
|
124
|
+
-- - Seq Scan vs Index Scan
|
|
125
|
+
-- - Actual rows vs Estimated rows
|
|
126
|
+
-- - Buffers: shared hit vs read
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Common Optimizations
|
|
130
|
+
```sql
|
|
131
|
+
-- Use EXISTS instead of IN for large sets
|
|
132
|
+
SELECT * FROM users u
|
|
133
|
+
WHERE EXISTS (SELECT 1 FROM orders o WHERE o.user_id = u.id);
|
|
134
|
+
|
|
135
|
+
-- Pagination with keyset (cursor) instead of OFFSET
|
|
136
|
+
SELECT * FROM posts
|
|
137
|
+
WHERE created_at < '2024-01-01'
|
|
138
|
+
ORDER BY created_at DESC
|
|
139
|
+
LIMIT 20;
|
|
140
|
+
|
|
141
|
+
-- Use CTEs for complex queries
|
|
142
|
+
WITH active_users AS (
|
|
143
|
+
SELECT id FROM users WHERE last_login > NOW() - INTERVAL '30 days'
|
|
144
|
+
)
|
|
145
|
+
SELECT * FROM orders WHERE user_id IN (SELECT id FROM active_users);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Constraints & Data Integrity
|
|
149
|
+
|
|
150
|
+
```sql
|
|
151
|
+
-- Primary key
|
|
152
|
+
ALTER TABLE users ADD PRIMARY KEY (id);
|
|
153
|
+
|
|
154
|
+
-- Foreign key with cascade
|
|
155
|
+
ALTER TABLE orders ADD CONSTRAINT fk_orders_user
|
|
156
|
+
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
|
|
157
|
+
|
|
158
|
+
-- Check constraint
|
|
159
|
+
ALTER TABLE products ADD CONSTRAINT chk_price_positive
|
|
160
|
+
CHECK (price >= 0);
|
|
161
|
+
|
|
162
|
+
-- Unique constraint
|
|
163
|
+
ALTER TABLE users ADD CONSTRAINT uniq_users_email UNIQUE (email);
|
|
164
|
+
|
|
165
|
+
-- Exclusion constraint (no overlapping ranges)
|
|
166
|
+
ALTER TABLE reservations ADD CONSTRAINT excl_no_overlap
|
|
167
|
+
EXCLUDE USING gist (room_id WITH =, tsrange(start_time, end_time) WITH &&);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Best Practices
|
|
171
|
+
|
|
172
|
+
- Use UUIDs for public-facing IDs, SERIAL/BIGSERIAL for internal
|
|
173
|
+
- Always add `created_at` and `updated_at` timestamps
|
|
174
|
+
- Use soft deletes (`deleted_at`) for important data
|
|
175
|
+
- Design for eventual consistency in distributed systems
|
|
176
|
+
- Document schema decisions in migration files
|
|
177
|
+
- Test migrations on production-size data before deploying
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: db-diagram
|
|
3
|
+
context: fork
|
|
4
|
+
description: Turn a SQL artifact — a stored procedure, view, query, .sql file, or table name — into a diagram that explains it to a human. Use when the user says "diagram this query/proc/view/schema", "explain this SQL visually", "draw the ER diagram", "show me the data flow of this stored proc", "/mermaid-db", or "/excalidraw-db". Produces Mermaid (default, git-diffable) or Excalidraw (for design reviews). Read-only — never touches the database.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# db-diagram — explain SQL as a diagram
|
|
8
|
+
|
|
9
|
+
Take a SQL artifact and produce a diagram that explains it to a human. Two output formats, one shared
|
|
10
|
+
extraction: **Mermaid** (default — plain text, diffs cleanly, renders in VS Code/Gitea, regenerable) and
|
|
11
|
+
**Excalidraw** (for a design review / ARB pack / slide — someone drags boxes around).
|
|
12
|
+
|
|
13
|
+
The structure is extracted **deterministically** by `scripts/sql_to_graph.py` (a real sqlglot-based
|
|
14
|
+
parser); you (the model) add the **business narration** on top. Never hand-derive the node graph when the
|
|
15
|
+
script can run — its whole value is reproducibility.
|
|
16
|
+
|
|
17
|
+
## Two non-negotiable safety rules
|
|
18
|
+
|
|
19
|
+
1. **Never write to the database.** Read-only by definition — no DDL, no DML, not even in a rolled-back
|
|
20
|
+
transaction. The extractor only ever parses SQL *text*.
|
|
21
|
+
2. **Never guess schema.** Inspect the actual tables/columns before diagramming. If you can't reach the
|
|
22
|
+
database, diagram only what's provable from the SQL text and **mark inferred elements clearly**.
|
|
23
|
+
|
|
24
|
+
## Step 1 — get the SQL
|
|
25
|
+
|
|
26
|
+
Resolve the argument:
|
|
27
|
+
- **A file path** → read that file.
|
|
28
|
+
- **A database object name** (proc/view/table) → look it up. Prefer a registered DB **MCP tool** if one
|
|
29
|
+
is available in the session; else `sqlcmd`/`psql` **read-only**; else ask the user to paste it. Never
|
|
30
|
+
guess an object's body.
|
|
31
|
+
- **No argument** → operate on the SQL in the current file/context, or ask.
|
|
32
|
+
- **Multiple objects** → diagram the **relationships between them**, in ONE diagram — not one diagram each.
|
|
33
|
+
|
|
34
|
+
## Step 2 — run the deterministic extractor
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
python <skill-dir>/scripts/sql_to_graph.py --file <path> # Mermaid block (default)
|
|
38
|
+
python <skill-dir>/scripts/sql_to_graph.py --file <path> --format excalidraw # native .excalidraw JSON
|
|
39
|
+
python <skill-dir>/scripts/sql_to_graph.py --file <path> --format html --title "..." # self-contained page
|
|
40
|
+
python <skill-dir>/scripts/sql_to_graph.py --file <path> --format svg # self-contained .svg
|
|
41
|
+
python <skill-dir>/scripts/sql_to_graph.py --sql "<SELECT ...>" --json # full graph JSON
|
|
42
|
+
```
|
|
43
|
+
All five formats (`mermaid` | `excalidraw` | `svg` | `html` | `json`) come from **one deterministic layout**
|
|
44
|
+
— same SQL always produces byte-identical output, boxes are grid-aligned, and every label is wrapped to fit
|
|
45
|
+
*inside* its box.
|
|
46
|
+
|
|
47
|
+
**Notation (relational algebra — keep it when narrating):** operations carry the professional symbols
|
|
48
|
+
DB engineers already read — `σ` selection (WHERE), `Σ` aggregation (GROUP BY/HAVING, its own pipeline
|
|
49
|
+
stage), `π` projection (TOP/ORDER BY), `⋈` join (in the joined table's box), `ρ` rename (a CTE),
|
|
50
|
+
`∪`/`∩`/`∖` set operations (annotated on the result). Tables stay symbol-free — the name is the star.
|
|
51
|
+
Palette is the skill's own "jewel on ivory" identity (harbor teal / plum / saffron / madder / ink-blue /
|
|
52
|
+
viridian) — don't restyle it per diagram.
|
|
53
|
+
|
|
54
|
+
`--dialect` defaults to `tsql`; pass `postgres`/`mysql`/etc. for other engines. Requires `sqlglot`
|
|
55
|
+
(`pip install sqlglot` — pure-Python, no DB driver). **If sqlglot is absent** the script exits with an
|
|
56
|
+
actionable message; then hand-parse the SQL yourself and mark every inferred element (per safety rule 2).
|
|
57
|
+
|
|
58
|
+
The extractor classifies the input and picks the diagram type:
|
|
59
|
+
|
|
60
|
+
| Input | Diagram type | Extractor emits |
|
|
61
|
+
|---|---|---|
|
|
62
|
+
| `CREATE TABLE` / schema DDL | `erDiagram` | entities, columns, PK/FK, FK relationships |
|
|
63
|
+
| A query, proc, or CTE chain | `flowchart LR` | a strict pipeline: tables `[(T)]` / CTEs `{{CTE: name}}` → ONE `WHERE` box (all ANDed predicates, one per line) → `result` → projection `[/…/]`; join type+key labels ride on the source edges |
|
|
64
|
+
| An API/service path ending in a DB call | `sequenceDiagram` | *not structural — you build this from the code path; the extractor won't* |
|
|
65
|
+
| A status/lifecycle column | `stateDiagram-v2` | *not structural — you build this from the state values* |
|
|
66
|
+
|
|
67
|
+
The `sequenceDiagram`/`stateDiagram-v2` cases are judgement, not parsing — build those yourself and say so.
|
|
68
|
+
For the two structural cases, **trust the extractor's graph**; your job is narration, not re-deriving nodes.
|
|
69
|
+
|
|
70
|
+
The extractor returns `confidence` (`high` | `partial`) and an `inferred` list. If `partial`, the SQL
|
|
71
|
+
couldn't be fully parsed — surface the `inferred` notes in the output and mark those parts.
|
|
72
|
+
|
|
73
|
+
## Step 3 — wrap it with narration (your job)
|
|
74
|
+
|
|
75
|
+
Around the extractor's Mermaid block, add:
|
|
76
|
+
- **Above the diagram**: one paragraph explaining what the query/proc is *for* in **business terms** (not
|
|
77
|
+
a restatement of the SQL — the *why*).
|
|
78
|
+
- **Below the diagram**: a bulleted list of every source table with a **one-line description** of what it
|
|
79
|
+
holds and why this query touches it. Inspect the real table (MCP/`sqlcmd`) for this — don't invent.
|
|
80
|
+
- **Traceability**: the source file path or object name, and a **generation date**.
|
|
81
|
+
- **This caveat, verbatim:**
|
|
82
|
+
|
|
83
|
+
> This diagram shows the SQL as written, not the execution plan. For performance analysis use the
|
|
84
|
+
> actual execution plan (SSMS Ctrl+M), which reflects what the optimiser actually chose — the two
|
|
85
|
+
> diverge frequently.
|
|
86
|
+
|
|
87
|
+
## Step 4 — validate before saving
|
|
88
|
+
|
|
89
|
+
Malformed Mermaid renders as an error block — worse than no diagram. Before writing:
|
|
90
|
+
- Confirm the diagram **parses** (the extractor already sanitizes labels — no unescaped `"`/`[`/`]` — but
|
|
91
|
+
if you hand-edited or hand-built the diagram, re-check).
|
|
92
|
+
- Common breakages: unescaped parentheses, quotes, and square brackets inside node labels.
|
|
93
|
+
|
|
94
|
+
## Output rules — `/mermaid-db` (the default)
|
|
95
|
+
|
|
96
|
+
- Save as a **`.md`** file. Default path `docs/diagrams/<object-name>.md`, overridable by an argument.
|
|
97
|
+
- **If the file already exists**, diff against it and tell the user *what changed* — don't silently
|
|
98
|
+
overwrite. (Regenerating on a schema change and showing the delta is the point of Mermaid-as-text.)
|
|
99
|
+
|
|
100
|
+
## Output rules — `/excalidraw-db` (for human conversation)
|
|
101
|
+
|
|
102
|
+
Use for a design review / ARB / slide deck. **The extractor emits the `.excalidraw` JSON directly** — run
|
|
103
|
+
`--format excalidraw` and save the output as a `.excalidraw` file. No separate drawing skill, no MCP server.
|
|
104
|
+
The generator already guarantees what a hand-drawn diagram gets wrong.
|
|
105
|
+
|
|
106
|
+
**Flowchart (query / proc):**
|
|
107
|
+
- **Layout**: a strict left-to-right pipeline — sources → `WHERE` → `result` → projection — on a
|
|
108
|
+
deterministic grid (same-column boxes share an x; columns balanced on one mid-line). **Edges connect
|
|
109
|
+
adjacent stages only**, so an arrow can never cross a box; fan-in arrows land on distinct anchor
|
|
110
|
+
points (never one pile-up).
|
|
111
|
+
- **Arrows carry no text**: each join condition is a `⋈ …` sub-line INSIDE the joined table's box —
|
|
112
|
+
in a converging fan a floating label always ends up covering some arrow, so text never floats.
|
|
113
|
+
- **One WHERE box**: all ANDed predicates in a single box, one per line — stacked filter boxes read as
|
|
114
|
+
alternative paths, which is wrong.
|
|
115
|
+
- **Containment**: every label is a container-**bound** text element that auto-wraps and stays vertically
|
|
116
|
+
centred *inside* its box; box heights are computed from the wrapped line count, so text never overflows.
|
|
117
|
+
|
|
118
|
+
**ER diagram (schema DDL):**
|
|
119
|
+
- **Header + bullet columns**: each entity renders its name as a distinct **header** (bold, larger, in the
|
|
120
|
+
role colour, with a divider rule) and every column as a **bullet-list** item (`• col type · PK/FK`) —
|
|
121
|
+
the title never reads as just another column.
|
|
122
|
+
- **Arrows never cross a box**: entities are stacked in one column and every FK is routed as an
|
|
123
|
+
**orthogonal elbow through a left-side channel** (out the child's edge → down/up its own lane → into
|
|
124
|
+
the parent's edge). Every segment lives left of the boxes, so on a hub / chain / self-reference the FK
|
|
125
|
+
arrows can never run through — or hide behind — an intervening box (the old grid+straight-arrow bug).
|
|
126
|
+
Arrows are painted **on top** so every FK is unmistakably visible.
|
|
127
|
+
|
|
128
|
+
- **Canvas**: pure white (`#ffffff`) by default, both outputs.
|
|
129
|
+
- **Theme**: Excalidraw `appState.theme` is `"light"` (it re-tints for dark itself if toggled).
|
|
130
|
+
- **Determinism**: fixed ids/seeds — regenerating on a schema change produces a clean diff, not a reshuffle.
|
|
131
|
+
|
|
132
|
+
Then add the narration around it (business context + per-table descriptions + the execution-plan caveat).
|
|
133
|
+
If someone wants a **shareable, no-app preview**, `--format html` produces a self-contained page (the SVG
|
|
134
|
+
inline + a light/dark toggle) and `--format svg` a standalone SVG. The HTML theme is **fully
|
|
135
|
+
attribute-driven**: an inline head script seeds light/dark from the OS once, both themes are defined under
|
|
136
|
+
`:root[data-theme=…]` with the full variable set, and there is **no `@media` rule** to fight the toggle —
|
|
137
|
+
so the toggle always applies cleanly (no half-applied / black-page state). Zero external requests.
|
|
138
|
+
|
|
139
|
+
- **Do not maintain both formats for the same artifact.** If a Mermaid diagram already exists for an
|
|
140
|
+
object and the user runs `/excalidraw-db` on it, say so and ask: a one-off review copy, or a replacement?
|
|
141
|
+
|
|
142
|
+
## The read-only, never-guess discipline (restated because it matters)
|
|
143
|
+
|
|
144
|
+
- Never run anything that mutates the DB.
|
|
145
|
+
- Never assert a table's columns or relationships you haven't verified against the real schema; mark
|
|
146
|
+
anything inferred-from-SQL-text-only.
|
|
147
|
+
- If the extractor's `confidence` is `partial` or sqlglot is unavailable, the diagram is best-effort —
|
|
148
|
+
say so in the output, don't present it as authoritative.
|