jorgex-stack 1.0.1 → 1.0.3
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/PRD.md +310 -297
- package/README.md +68 -56
- package/dist/cli.js +37 -3
- package/package.json +1 -1
- package/stack/agents/code-simplifier.md +21 -10
- package/stack/agents/implementer.md +1 -0
- package/stack/agents/orchestrator.md +194 -192
- package/stack/agents/security-auditor.md +7 -0
- package/stack/agents/silent-failure-hunter.md +7 -0
- package/stack/agents/test-analyzer.md +7 -0
- package/stack/agents/tester.md +71 -71
- package/stack/agents/type-design-analyzer.md +1 -1
- package/stack/commands/lean-audit.md +59 -0
- package/stack/commands/xreview.md +82 -80
- package/stack/hooks/hooks.json +18 -18
- package/stack/scripts/post-pr-review.cjs +159 -156
- package/stack/skills/diagnose/SKILL.md +117 -117
- package/stack/skills/diagnose/scripts/hitl-loop.template.sh +41 -41
- package/stack/skills/find-skills/SKILL.md +133 -133
- package/stack/skills/lean-code/SKILL.md +69 -0
- package/stack/skills/mcp-builder/LICENSE.txt +201 -201
- package/stack/skills/mcp-builder/SKILL.md +236 -236
- package/stack/skills/mcp-builder/reference/evaluation.md +601 -601
- package/stack/skills/mcp-builder/reference/mcp_best_practices.md +249 -249
- package/stack/skills/mcp-builder/reference/node_mcp_server.md +969 -969
- package/stack/skills/mcp-builder/reference/python_mcp_server.md +718 -718
- package/stack/skills/mcp-builder/scripts/connections.py +151 -151
- package/stack/skills/mcp-builder/scripts/evaluation.py +373 -373
- package/stack/skills/mcp-builder/scripts/example_evaluation.xml +22 -22
- package/stack/skills/mcp-builder/scripts/requirements.txt +2 -2
- package/stack/skills/obsidian-cli/SKILL.md +106 -106
- package/stack/skills/obsidian-markdown/SKILL.md +196 -196
- package/stack/skills/obsidian-markdown/references/CALLOUTS.md +58 -58
- package/stack/skills/obsidian-markdown/references/EMBEDS.md +63 -63
- package/stack/skills/obsidian-markdown/references/PROPERTIES.md +61 -61
- package/stack/skills/react-doctor/SKILL.md +19 -19
- package/stack/skills/skill-creator/LICENSE.txt +201 -201
- package/stack/skills/skill-creator/agents/analyzer.md +274 -274
- package/stack/skills/skill-creator/agents/comparator.md +202 -202
- package/stack/skills/skill-creator/agents/grader.md +223 -223
- package/stack/skills/skill-creator/assets/eval_review.html +146 -146
- package/stack/skills/skill-creator/eval-viewer/generate_review.py +471 -471
- package/stack/skills/skill-creator/eval-viewer/viewer.html +1325 -1325
- package/stack/skills/skill-creator/references/schemas.md +430 -430
- package/stack/skills/skill-creator/scripts/aggregate_benchmark.py +401 -401
- package/stack/skills/skill-creator/scripts/generate_report.py +326 -326
- package/stack/skills/skill-creator/scripts/improve_description.py +248 -248
- package/stack/skills/skill-creator/scripts/package_skill.py +136 -136
- package/stack/skills/skill-creator/scripts/quick_validate.py +102 -102
- package/stack/skills/skill-creator/scripts/run_eval.py +310 -310
- package/stack/skills/skill-creator/scripts/run_loop.py +332 -332
- package/stack/skills/skill-creator/scripts/utils.py +47 -47
- package/stack/skills/supabase/SKILL.md +135 -135
- package/stack/skills/supabase/assets/feedback-issue-template.md +17 -17
- package/stack/skills/supabase/references/skill-feedback.md +17 -17
- package/stack/skills/supabase-postgres-best-practices/SKILL.md +64 -64
- package/stack/skills/supabase-postgres-best-practices/references/_contributing.md +170 -170
- package/stack/skills/supabase-postgres-best-practices/references/_sections.md +39 -39
- package/stack/skills/supabase-postgres-best-practices/references/_template.md +34 -34
- package/stack/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +55 -55
- package/stack/skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +49 -49
- package/stack/skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +46 -46
- package/stack/skills/supabase-postgres-best-practices/references/conn-limits.md +44 -44
- package/stack/skills/supabase-postgres-best-practices/references/conn-pooling.md +41 -41
- package/stack/skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +46 -46
- package/stack/skills/supabase-postgres-best-practices/references/data-batch-inserts.md +54 -54
- package/stack/skills/supabase-postgres-best-practices/references/data-n-plus-one.md +53 -53
- package/stack/skills/supabase-postgres-best-practices/references/data-pagination.md +50 -50
- package/stack/skills/supabase-postgres-best-practices/references/data-upsert.md +50 -50
- package/stack/skills/supabase-postgres-best-practices/references/lock-advisory.md +56 -56
- package/stack/skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +68 -68
- package/stack/skills/supabase-postgres-best-practices/references/lock-short-transactions.md +50 -50
- package/stack/skills/supabase-postgres-best-practices/references/lock-skip-locked.md +54 -54
- package/stack/skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +45 -45
- package/stack/skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +55 -55
- package/stack/skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +55 -55
- package/stack/skills/supabase-postgres-best-practices/references/query-composite-indexes.md +44 -44
- package/stack/skills/supabase-postgres-best-practices/references/query-covering-indexes.md +40 -40
- package/stack/skills/supabase-postgres-best-practices/references/query-index-types.md +48 -48
- package/stack/skills/supabase-postgres-best-practices/references/query-missing-indexes.md +43 -43
- package/stack/skills/supabase-postgres-best-practices/references/query-partial-indexes.md +45 -45
- package/stack/skills/supabase-postgres-best-practices/references/schema-constraints.md +80 -80
- package/stack/skills/supabase-postgres-best-practices/references/schema-data-types.md +46 -46
- package/stack/skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +59 -59
- package/stack/skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +55 -55
- package/stack/skills/supabase-postgres-best-practices/references/schema-partitioning.md +55 -55
- package/stack/skills/supabase-postgres-best-practices/references/schema-primary-keys.md +61 -61
- package/stack/skills/supabase-postgres-best-practices/references/security-privileges.md +54 -54
- package/stack/skills/supabase-postgres-best-practices/references/security-rls-basics.md +50 -50
- package/stack/skills/supabase-postgres-best-practices/references/security-rls-performance.md +63 -63
- package/stack/skills/tdd/SKILL.md +109 -109
- package/stack/skills/tdd/deep-modules.md +33 -33
- package/stack/skills/tdd/interface-design.md +31 -31
- package/stack/skills/tdd/mocking.md +59 -59
- package/stack/skills/tdd/refactoring.md +10 -10
- package/stack/skills/tdd/tests.md +61 -61
- package/stack/skills/to-issues/SKILL.md +83 -83
- package/stack/skills/to-prd/SKILL.md +72 -72
- package/upstreams.json +96 -96
|
@@ -1,170 +1,170 @@
|
|
|
1
|
-
# Writing Guidelines for Postgres References
|
|
2
|
-
|
|
3
|
-
This document provides guidelines for creating effective Postgres best
|
|
4
|
-
practice references that work well with AI agents and LLMs.
|
|
5
|
-
|
|
6
|
-
## Key Principles
|
|
7
|
-
|
|
8
|
-
### 1. Concrete Transformation Patterns
|
|
9
|
-
|
|
10
|
-
Show exact SQL rewrites. Avoid philosophical advice.
|
|
11
|
-
|
|
12
|
-
**Good:** "Use `WHERE id = ANY(ARRAY[...])` instead of
|
|
13
|
-
`WHERE id IN (SELECT ...)`" **Bad:** "Design good schemas"
|
|
14
|
-
|
|
15
|
-
### 2. Error-First Structure
|
|
16
|
-
|
|
17
|
-
Always show the problematic pattern first, then the solution. This trains agents
|
|
18
|
-
to recognize anti-patterns.
|
|
19
|
-
|
|
20
|
-
```markdown
|
|
21
|
-
**Incorrect (sequential queries):** [bad example]
|
|
22
|
-
|
|
23
|
-
**Correct (batched query):** [good example]
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
### 3. Quantified Impact
|
|
27
|
-
|
|
28
|
-
Include specific metrics. Helps agents prioritize fixes.
|
|
29
|
-
|
|
30
|
-
**Good:** "10x faster queries", "50% smaller index", "Eliminates N+1"
|
|
31
|
-
**Bad:** "Faster", "Better", "More efficient"
|
|
32
|
-
|
|
33
|
-
### 4. Self-Contained Examples
|
|
34
|
-
|
|
35
|
-
Examples should be complete and runnable (or close to it). Include `CREATE TABLE`
|
|
36
|
-
if context is needed.
|
|
37
|
-
|
|
38
|
-
```sql
|
|
39
|
-
-- Include table definition when needed for clarity
|
|
40
|
-
CREATE TABLE users (
|
|
41
|
-
id bigint PRIMARY KEY,
|
|
42
|
-
email text NOT NULL,
|
|
43
|
-
deleted_at timestamptz
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
-- Now show the index
|
|
47
|
-
CREATE INDEX users_active_email_idx ON users(email) WHERE deleted_at IS NULL;
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### 5. Semantic Naming
|
|
51
|
-
|
|
52
|
-
Use meaningful table/column names. Names carry intent for LLMs.
|
|
53
|
-
|
|
54
|
-
**Good:** `users`, `email`, `created_at`, `is_active`
|
|
55
|
-
**Bad:** `table1`, `col1`, `field`, `flag`
|
|
56
|
-
|
|
57
|
-
---
|
|
58
|
-
|
|
59
|
-
## Code Example Standards
|
|
60
|
-
|
|
61
|
-
### SQL Formatting
|
|
62
|
-
|
|
63
|
-
```sql
|
|
64
|
-
-- Use lowercase keywords, clear formatting
|
|
65
|
-
CREATE INDEX CONCURRENTLY users_email_idx
|
|
66
|
-
ON users(email)
|
|
67
|
-
WHERE deleted_at IS NULL;
|
|
68
|
-
|
|
69
|
-
-- Not cramped or ALL CAPS
|
|
70
|
-
CREATE INDEX CONCURRENTLY USERS_EMAIL_IDX ON USERS(EMAIL) WHERE DELETED_AT IS NULL;
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### Comments
|
|
74
|
-
|
|
75
|
-
- Explain _why_, not _what_
|
|
76
|
-
- Highlight performance implications
|
|
77
|
-
- Point out common pitfalls
|
|
78
|
-
|
|
79
|
-
### Language Tags
|
|
80
|
-
|
|
81
|
-
- `sql` - Standard SQL queries
|
|
82
|
-
- `plpgsql` - Stored procedures/functions
|
|
83
|
-
- `typescript` - Application code (when needed)
|
|
84
|
-
- `python` - Application code (when needed)
|
|
85
|
-
|
|
86
|
-
---
|
|
87
|
-
|
|
88
|
-
## When to Include Application Code
|
|
89
|
-
|
|
90
|
-
**Default: SQL Only**
|
|
91
|
-
|
|
92
|
-
Most references should focus on pure SQL patterns. This keeps examples portable.
|
|
93
|
-
|
|
94
|
-
**Include Application Code When:**
|
|
95
|
-
|
|
96
|
-
- Connection pooling configuration
|
|
97
|
-
- Transaction management in application context
|
|
98
|
-
- ORM anti-patterns (N+1 in Prisma/TypeORM)
|
|
99
|
-
- Prepared statement usage
|
|
100
|
-
|
|
101
|
-
**Format for Mixed Examples:**
|
|
102
|
-
|
|
103
|
-
````markdown
|
|
104
|
-
**Incorrect (N+1 in application):**
|
|
105
|
-
|
|
106
|
-
```typescript
|
|
107
|
-
for (const user of users) {
|
|
108
|
-
const posts = await db.query("SELECT * FROM posts WHERE user_id = $1", [
|
|
109
|
-
user.id,
|
|
110
|
-
]);
|
|
111
|
-
}
|
|
112
|
-
```
|
|
113
|
-
````
|
|
114
|
-
|
|
115
|
-
**Correct (batch query):**
|
|
116
|
-
|
|
117
|
-
```typescript
|
|
118
|
-
const posts = await db.query("SELECT * FROM posts WHERE user_id = ANY($1)", [
|
|
119
|
-
userIds,
|
|
120
|
-
]);
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
---
|
|
124
|
-
|
|
125
|
-
## Impact Level Guidelines
|
|
126
|
-
|
|
127
|
-
| Level | Improvement | Use When |
|
|
128
|
-
|-------|-------------|----------|
|
|
129
|
-
| **CRITICAL** | 10-100x | Missing indexes, connection exhaustion, sequential scans on large tables |
|
|
130
|
-
| **HIGH** | 5-20x | Wrong index types, poor partitioning, missing covering indexes |
|
|
131
|
-
| **MEDIUM-HIGH** | 2-5x | N+1 queries, inefficient pagination, RLS optimization |
|
|
132
|
-
| **MEDIUM** | 1.5-3x | Redundant indexes, query plan instability |
|
|
133
|
-
| **LOW-MEDIUM** | 1.2-2x | VACUUM tuning, configuration tweaks |
|
|
134
|
-
| **LOW** | Incremental | Advanced patterns, edge cases |
|
|
135
|
-
|
|
136
|
-
---
|
|
137
|
-
|
|
138
|
-
## Reference Standards
|
|
139
|
-
|
|
140
|
-
**Primary Sources:**
|
|
141
|
-
|
|
142
|
-
- Official Postgres documentation
|
|
143
|
-
- Supabase documentation
|
|
144
|
-
- Postgres wiki
|
|
145
|
-
- Established blogs (2ndQuadrant, Crunchy Data)
|
|
146
|
-
|
|
147
|
-
**Format:**
|
|
148
|
-
|
|
149
|
-
```markdown
|
|
150
|
-
Reference:
|
|
151
|
-
[Postgres Indexes](https://www.postgresql.org/docs/current/indexes.html)
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
---
|
|
155
|
-
|
|
156
|
-
## Review Checklist
|
|
157
|
-
|
|
158
|
-
Before submitting a reference:
|
|
159
|
-
|
|
160
|
-
- [ ] Title is clear and action-oriented
|
|
161
|
-
- [ ] Impact level matches the performance gain
|
|
162
|
-
- [ ] impactDescription includes quantification
|
|
163
|
-
- [ ] Explanation is concise (1-2 sentences)
|
|
164
|
-
- [ ] Has at least 1 **Incorrect** SQL example
|
|
165
|
-
- [ ] Has at least 1 **Correct** SQL example
|
|
166
|
-
- [ ] SQL uses semantic naming
|
|
167
|
-
- [ ] Comments explain _why_, not _what_
|
|
168
|
-
- [ ] Trade-offs mentioned if applicable
|
|
169
|
-
- [ ] Reference links included
|
|
170
|
-
- [ ] `pnpm test` passes
|
|
1
|
+
# Writing Guidelines for Postgres References
|
|
2
|
+
|
|
3
|
+
This document provides guidelines for creating effective Postgres best
|
|
4
|
+
practice references that work well with AI agents and LLMs.
|
|
5
|
+
|
|
6
|
+
## Key Principles
|
|
7
|
+
|
|
8
|
+
### 1. Concrete Transformation Patterns
|
|
9
|
+
|
|
10
|
+
Show exact SQL rewrites. Avoid philosophical advice.
|
|
11
|
+
|
|
12
|
+
**Good:** "Use `WHERE id = ANY(ARRAY[...])` instead of
|
|
13
|
+
`WHERE id IN (SELECT ...)`" **Bad:** "Design good schemas"
|
|
14
|
+
|
|
15
|
+
### 2. Error-First Structure
|
|
16
|
+
|
|
17
|
+
Always show the problematic pattern first, then the solution. This trains agents
|
|
18
|
+
to recognize anti-patterns.
|
|
19
|
+
|
|
20
|
+
```markdown
|
|
21
|
+
**Incorrect (sequential queries):** [bad example]
|
|
22
|
+
|
|
23
|
+
**Correct (batched query):** [good example]
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 3. Quantified Impact
|
|
27
|
+
|
|
28
|
+
Include specific metrics. Helps agents prioritize fixes.
|
|
29
|
+
|
|
30
|
+
**Good:** "10x faster queries", "50% smaller index", "Eliminates N+1"
|
|
31
|
+
**Bad:** "Faster", "Better", "More efficient"
|
|
32
|
+
|
|
33
|
+
### 4. Self-Contained Examples
|
|
34
|
+
|
|
35
|
+
Examples should be complete and runnable (or close to it). Include `CREATE TABLE`
|
|
36
|
+
if context is needed.
|
|
37
|
+
|
|
38
|
+
```sql
|
|
39
|
+
-- Include table definition when needed for clarity
|
|
40
|
+
CREATE TABLE users (
|
|
41
|
+
id bigint PRIMARY KEY,
|
|
42
|
+
email text NOT NULL,
|
|
43
|
+
deleted_at timestamptz
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
-- Now show the index
|
|
47
|
+
CREATE INDEX users_active_email_idx ON users(email) WHERE deleted_at IS NULL;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 5. Semantic Naming
|
|
51
|
+
|
|
52
|
+
Use meaningful table/column names. Names carry intent for LLMs.
|
|
53
|
+
|
|
54
|
+
**Good:** `users`, `email`, `created_at`, `is_active`
|
|
55
|
+
**Bad:** `table1`, `col1`, `field`, `flag`
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Code Example Standards
|
|
60
|
+
|
|
61
|
+
### SQL Formatting
|
|
62
|
+
|
|
63
|
+
```sql
|
|
64
|
+
-- Use lowercase keywords, clear formatting
|
|
65
|
+
CREATE INDEX CONCURRENTLY users_email_idx
|
|
66
|
+
ON users(email)
|
|
67
|
+
WHERE deleted_at IS NULL;
|
|
68
|
+
|
|
69
|
+
-- Not cramped or ALL CAPS
|
|
70
|
+
CREATE INDEX CONCURRENTLY USERS_EMAIL_IDX ON USERS(EMAIL) WHERE DELETED_AT IS NULL;
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Comments
|
|
74
|
+
|
|
75
|
+
- Explain _why_, not _what_
|
|
76
|
+
- Highlight performance implications
|
|
77
|
+
- Point out common pitfalls
|
|
78
|
+
|
|
79
|
+
### Language Tags
|
|
80
|
+
|
|
81
|
+
- `sql` - Standard SQL queries
|
|
82
|
+
- `plpgsql` - Stored procedures/functions
|
|
83
|
+
- `typescript` - Application code (when needed)
|
|
84
|
+
- `python` - Application code (when needed)
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## When to Include Application Code
|
|
89
|
+
|
|
90
|
+
**Default: SQL Only**
|
|
91
|
+
|
|
92
|
+
Most references should focus on pure SQL patterns. This keeps examples portable.
|
|
93
|
+
|
|
94
|
+
**Include Application Code When:**
|
|
95
|
+
|
|
96
|
+
- Connection pooling configuration
|
|
97
|
+
- Transaction management in application context
|
|
98
|
+
- ORM anti-patterns (N+1 in Prisma/TypeORM)
|
|
99
|
+
- Prepared statement usage
|
|
100
|
+
|
|
101
|
+
**Format for Mixed Examples:**
|
|
102
|
+
|
|
103
|
+
````markdown
|
|
104
|
+
**Incorrect (N+1 in application):**
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
for (const user of users) {
|
|
108
|
+
const posts = await db.query("SELECT * FROM posts WHERE user_id = $1", [
|
|
109
|
+
user.id,
|
|
110
|
+
]);
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
````
|
|
114
|
+
|
|
115
|
+
**Correct (batch query):**
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
const posts = await db.query("SELECT * FROM posts WHERE user_id = ANY($1)", [
|
|
119
|
+
userIds,
|
|
120
|
+
]);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Impact Level Guidelines
|
|
126
|
+
|
|
127
|
+
| Level | Improvement | Use When |
|
|
128
|
+
|-------|-------------|----------|
|
|
129
|
+
| **CRITICAL** | 10-100x | Missing indexes, connection exhaustion, sequential scans on large tables |
|
|
130
|
+
| **HIGH** | 5-20x | Wrong index types, poor partitioning, missing covering indexes |
|
|
131
|
+
| **MEDIUM-HIGH** | 2-5x | N+1 queries, inefficient pagination, RLS optimization |
|
|
132
|
+
| **MEDIUM** | 1.5-3x | Redundant indexes, query plan instability |
|
|
133
|
+
| **LOW-MEDIUM** | 1.2-2x | VACUUM tuning, configuration tweaks |
|
|
134
|
+
| **LOW** | Incremental | Advanced patterns, edge cases |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Reference Standards
|
|
139
|
+
|
|
140
|
+
**Primary Sources:**
|
|
141
|
+
|
|
142
|
+
- Official Postgres documentation
|
|
143
|
+
- Supabase documentation
|
|
144
|
+
- Postgres wiki
|
|
145
|
+
- Established blogs (2ndQuadrant, Crunchy Data)
|
|
146
|
+
|
|
147
|
+
**Format:**
|
|
148
|
+
|
|
149
|
+
```markdown
|
|
150
|
+
Reference:
|
|
151
|
+
[Postgres Indexes](https://www.postgresql.org/docs/current/indexes.html)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Review Checklist
|
|
157
|
+
|
|
158
|
+
Before submitting a reference:
|
|
159
|
+
|
|
160
|
+
- [ ] Title is clear and action-oriented
|
|
161
|
+
- [ ] Impact level matches the performance gain
|
|
162
|
+
- [ ] impactDescription includes quantification
|
|
163
|
+
- [ ] Explanation is concise (1-2 sentences)
|
|
164
|
+
- [ ] Has at least 1 **Incorrect** SQL example
|
|
165
|
+
- [ ] Has at least 1 **Correct** SQL example
|
|
166
|
+
- [ ] SQL uses semantic naming
|
|
167
|
+
- [ ] Comments explain _why_, not _what_
|
|
168
|
+
- [ ] Trade-offs mentioned if applicable
|
|
169
|
+
- [ ] Reference links included
|
|
170
|
+
- [ ] `pnpm test` passes
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
# Section Definitions
|
|
2
|
-
|
|
3
|
-
This file defines the rule categories for Postgres best practices. Rules are automatically assigned to sections based on their filename prefix.
|
|
4
|
-
|
|
5
|
-
Take the examples below as pure demonstrative. Replace each section with the actual rule categories for Postgres best practices.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## 1. Query Performance (query)
|
|
10
|
-
**Impact:** CRITICAL
|
|
11
|
-
**Description:** Slow queries, missing indexes, inefficient query plans. The most common source of Postgres performance issues.
|
|
12
|
-
|
|
13
|
-
## 2. Connection Management (conn)
|
|
14
|
-
**Impact:** CRITICAL
|
|
15
|
-
**Description:** Connection pooling, limits, and serverless strategies. Critical for applications with high concurrency or serverless deployments.
|
|
16
|
-
|
|
17
|
-
## 3. Security & RLS (security)
|
|
18
|
-
**Impact:** CRITICAL
|
|
19
|
-
**Description:** Row-Level Security policies, privilege management, and authentication patterns.
|
|
20
|
-
|
|
21
|
-
## 4. Schema Design (schema)
|
|
22
|
-
**Impact:** HIGH
|
|
23
|
-
**Description:** Table design, index strategies, partitioning, and data type selection. Foundation for long-term performance.
|
|
24
|
-
|
|
25
|
-
## 5. Concurrency & Locking (lock)
|
|
26
|
-
**Impact:** MEDIUM-HIGH
|
|
27
|
-
**Description:** Transaction management, isolation levels, deadlock prevention, and lock contention patterns.
|
|
28
|
-
|
|
29
|
-
## 6. Data Access Patterns (data)
|
|
30
|
-
**Impact:** MEDIUM
|
|
31
|
-
**Description:** N+1 query elimination, batch operations, cursor-based pagination, and efficient data fetching.
|
|
32
|
-
|
|
33
|
-
## 7. Monitoring & Diagnostics (monitor)
|
|
34
|
-
**Impact:** LOW-MEDIUM
|
|
35
|
-
**Description:** Using pg_stat_statements, EXPLAIN ANALYZE, metrics collection, and performance diagnostics.
|
|
36
|
-
|
|
37
|
-
## 8. Advanced Features (advanced)
|
|
38
|
-
**Impact:** LOW
|
|
39
|
-
**Description:** Full-text search, JSONB optimization, PostGIS, extensions, and advanced Postgres features.
|
|
1
|
+
# Section Definitions
|
|
2
|
+
|
|
3
|
+
This file defines the rule categories for Postgres best practices. Rules are automatically assigned to sections based on their filename prefix.
|
|
4
|
+
|
|
5
|
+
Take the examples below as pure demonstrative. Replace each section with the actual rule categories for Postgres best practices.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Query Performance (query)
|
|
10
|
+
**Impact:** CRITICAL
|
|
11
|
+
**Description:** Slow queries, missing indexes, inefficient query plans. The most common source of Postgres performance issues.
|
|
12
|
+
|
|
13
|
+
## 2. Connection Management (conn)
|
|
14
|
+
**Impact:** CRITICAL
|
|
15
|
+
**Description:** Connection pooling, limits, and serverless strategies. Critical for applications with high concurrency or serverless deployments.
|
|
16
|
+
|
|
17
|
+
## 3. Security & RLS (security)
|
|
18
|
+
**Impact:** CRITICAL
|
|
19
|
+
**Description:** Row-Level Security policies, privilege management, and authentication patterns.
|
|
20
|
+
|
|
21
|
+
## 4. Schema Design (schema)
|
|
22
|
+
**Impact:** HIGH
|
|
23
|
+
**Description:** Table design, index strategies, partitioning, and data type selection. Foundation for long-term performance.
|
|
24
|
+
|
|
25
|
+
## 5. Concurrency & Locking (lock)
|
|
26
|
+
**Impact:** MEDIUM-HIGH
|
|
27
|
+
**Description:** Transaction management, isolation levels, deadlock prevention, and lock contention patterns.
|
|
28
|
+
|
|
29
|
+
## 6. Data Access Patterns (data)
|
|
30
|
+
**Impact:** MEDIUM
|
|
31
|
+
**Description:** N+1 query elimination, batch operations, cursor-based pagination, and efficient data fetching.
|
|
32
|
+
|
|
33
|
+
## 7. Monitoring & Diagnostics (monitor)
|
|
34
|
+
**Impact:** LOW-MEDIUM
|
|
35
|
+
**Description:** Using pg_stat_statements, EXPLAIN ANALYZE, metrics collection, and performance diagnostics.
|
|
36
|
+
|
|
37
|
+
## 8. Advanced Features (advanced)
|
|
38
|
+
**Impact:** LOW
|
|
39
|
+
**Description:** Full-text search, JSONB optimization, PostGIS, extensions, and advanced Postgres features.
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Clear, Action-Oriented Title (e.g., "Use Partial Indexes for Filtered Queries")
|
|
3
|
-
impact: MEDIUM
|
|
4
|
-
impactDescription: 5-20x query speedup for filtered queries
|
|
5
|
-
tags: indexes, query-optimization, performance
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## [Rule Title]
|
|
9
|
-
|
|
10
|
-
[1-2 sentence explanation of the problem and why it matters. Focus on performance impact.]
|
|
11
|
-
|
|
12
|
-
**Incorrect (describe the problem):**
|
|
13
|
-
|
|
14
|
-
```sql
|
|
15
|
-
-- Comment explaining what makes this slow/problematic
|
|
16
|
-
CREATE INDEX users_email_idx ON users(email);
|
|
17
|
-
|
|
18
|
-
SELECT * FROM users WHERE email = 'user@example.com' AND deleted_at IS NULL;
|
|
19
|
-
-- This scans deleted records unnecessarily
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
**Correct (describe the solution):**
|
|
23
|
-
|
|
24
|
-
```sql
|
|
25
|
-
-- Comment explaining why this is better
|
|
26
|
-
CREATE INDEX users_active_email_idx ON users(email) WHERE deleted_at IS NULL;
|
|
27
|
-
|
|
28
|
-
SELECT * FROM users WHERE email = 'user@example.com' AND deleted_at IS NULL;
|
|
29
|
-
-- Only indexes active users, 10x smaller index, faster queries
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
[Optional: Additional context, edge cases, or trade-offs]
|
|
33
|
-
|
|
34
|
-
Reference: [Postgres Docs](https://www.postgresql.org/docs/current/)
|
|
1
|
+
---
|
|
2
|
+
title: Clear, Action-Oriented Title (e.g., "Use Partial Indexes for Filtered Queries")
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: 5-20x query speedup for filtered queries
|
|
5
|
+
tags: indexes, query-optimization, performance
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## [Rule Title]
|
|
9
|
+
|
|
10
|
+
[1-2 sentence explanation of the problem and why it matters. Focus on performance impact.]
|
|
11
|
+
|
|
12
|
+
**Incorrect (describe the problem):**
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
-- Comment explaining what makes this slow/problematic
|
|
16
|
+
CREATE INDEX users_email_idx ON users(email);
|
|
17
|
+
|
|
18
|
+
SELECT * FROM users WHERE email = 'user@example.com' AND deleted_at IS NULL;
|
|
19
|
+
-- This scans deleted records unnecessarily
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Correct (describe the solution):**
|
|
23
|
+
|
|
24
|
+
```sql
|
|
25
|
+
-- Comment explaining why this is better
|
|
26
|
+
CREATE INDEX users_active_email_idx ON users(email) WHERE deleted_at IS NULL;
|
|
27
|
+
|
|
28
|
+
SELECT * FROM users WHERE email = 'user@example.com' AND deleted_at IS NULL;
|
|
29
|
+
-- Only indexes active users, 10x smaller index, faster queries
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
[Optional: Additional context, edge cases, or trade-offs]
|
|
33
|
+
|
|
34
|
+
Reference: [Postgres Docs](https://www.postgresql.org/docs/current/)
|
package/stack/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Use tsvector for Full-Text Search
|
|
3
|
-
impact: MEDIUM
|
|
4
|
-
impactDescription: 100x faster than LIKE, with ranking support
|
|
5
|
-
tags: full-text-search, tsvector, gin, search
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## Use tsvector for Full-Text Search
|
|
9
|
-
|
|
10
|
-
LIKE with wildcards can't use indexes. Full-text search with tsvector is orders of magnitude faster.
|
|
11
|
-
|
|
12
|
-
**Incorrect (LIKE pattern matching):**
|
|
13
|
-
|
|
14
|
-
```sql
|
|
15
|
-
-- Cannot use index, scans all rows
|
|
16
|
-
select * from articles where content like '%postgresql%';
|
|
17
|
-
|
|
18
|
-
-- Case-insensitive makes it worse
|
|
19
|
-
select * from articles where lower(content) like '%postgresql%';
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
**Correct (full-text search with tsvector):**
|
|
23
|
-
|
|
24
|
-
```sql
|
|
25
|
-
-- Add tsvector column and index
|
|
26
|
-
alter table articles add column search_vector tsvector
|
|
27
|
-
generated always as (to_tsvector('english', coalesce(title,'') || ' ' || coalesce(content,''))) stored;
|
|
28
|
-
|
|
29
|
-
create index articles_search_idx on articles using gin (search_vector);
|
|
30
|
-
|
|
31
|
-
-- Fast full-text search
|
|
32
|
-
select * from articles
|
|
33
|
-
where search_vector @@ to_tsquery('english', 'postgresql & performance');
|
|
34
|
-
|
|
35
|
-
-- With ranking
|
|
36
|
-
select *, ts_rank(search_vector, query) as rank
|
|
37
|
-
from articles, to_tsquery('english', 'postgresql') query
|
|
38
|
-
where search_vector @@ query
|
|
39
|
-
order by rank desc;
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Search multiple terms:
|
|
43
|
-
|
|
44
|
-
```sql
|
|
45
|
-
-- AND: both terms required
|
|
46
|
-
to_tsquery('postgresql & performance')
|
|
47
|
-
|
|
48
|
-
-- OR: either term
|
|
49
|
-
to_tsquery('postgresql | mysql')
|
|
50
|
-
|
|
51
|
-
-- Prefix matching
|
|
52
|
-
to_tsquery('post:*')
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Reference: [Full Text Search](https://supabase.com/docs/guides/database/full-text-search)
|
|
1
|
+
---
|
|
2
|
+
title: Use tsvector for Full-Text Search
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: 100x faster than LIKE, with ranking support
|
|
5
|
+
tags: full-text-search, tsvector, gin, search
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use tsvector for Full-Text Search
|
|
9
|
+
|
|
10
|
+
LIKE with wildcards can't use indexes. Full-text search with tsvector is orders of magnitude faster.
|
|
11
|
+
|
|
12
|
+
**Incorrect (LIKE pattern matching):**
|
|
13
|
+
|
|
14
|
+
```sql
|
|
15
|
+
-- Cannot use index, scans all rows
|
|
16
|
+
select * from articles where content like '%postgresql%';
|
|
17
|
+
|
|
18
|
+
-- Case-insensitive makes it worse
|
|
19
|
+
select * from articles where lower(content) like '%postgresql%';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Correct (full-text search with tsvector):**
|
|
23
|
+
|
|
24
|
+
```sql
|
|
25
|
+
-- Add tsvector column and index
|
|
26
|
+
alter table articles add column search_vector tsvector
|
|
27
|
+
generated always as (to_tsvector('english', coalesce(title,'') || ' ' || coalesce(content,''))) stored;
|
|
28
|
+
|
|
29
|
+
create index articles_search_idx on articles using gin (search_vector);
|
|
30
|
+
|
|
31
|
+
-- Fast full-text search
|
|
32
|
+
select * from articles
|
|
33
|
+
where search_vector @@ to_tsquery('english', 'postgresql & performance');
|
|
34
|
+
|
|
35
|
+
-- With ranking
|
|
36
|
+
select *, ts_rank(search_vector, query) as rank
|
|
37
|
+
from articles, to_tsquery('english', 'postgresql') query
|
|
38
|
+
where search_vector @@ query
|
|
39
|
+
order by rank desc;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Search multiple terms:
|
|
43
|
+
|
|
44
|
+
```sql
|
|
45
|
+
-- AND: both terms required
|
|
46
|
+
to_tsquery('postgresql & performance')
|
|
47
|
+
|
|
48
|
+
-- OR: either term
|
|
49
|
+
to_tsquery('postgresql | mysql')
|
|
50
|
+
|
|
51
|
+
-- Prefix matching
|
|
52
|
+
to_tsquery('post:*')
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Reference: [Full Text Search](https://supabase.com/docs/guides/database/full-text-search)
|