Declarative .mdcQuy tắc Cursor/Claude/Windsurf & quy trình làm việc n8nQuy tắc IDEĐã kiểm tra rò rỉ bí mật

PostgreSQL 18 Di chuyển an toàn theo khóa & Quy tắc lập chỉ mục JSONB GIN

Bộ quy tắc Windsurf, Cursor và Claude khai báo thực thi các biện pháp bảo vệ lock_timeout, tạo chỉ mục ĐỒNG thời và tối ưu hóa ngăn chặn GIN jsonb_path_ops.

Tệp quy tắc IDE & Tác nhân khai báo

---
description: Lock-safe PostgreSQL 18 DDL migrations, JSONB GIN indexing, and query latency guardrails
globs: **/*.{sql,prisma,go}
alwaysApply: false
---

# PostgreSQL 18 Zero-Downtime DDL & Indexing Rules

- Prefix every production migration with `SET lock_timeout = '2s'; SET statement_timeout = '30s';` so blocked DDL aborts cleanly instead of queueing reads.
- Build new indexes on populated tables using `CREATE INDEX CONCURRENTLY IF NOT EXISTS` outside explicit transaction blocks.
- Use `USING GIN (column jsonb_path_ops)` for JSONB containment (`@>`) workloads to reduce index footprint by up to 60%.
- Add `NOT NULL` constraints on existing large tables via `CHECK (...) NOT VALID` followed by `VALIDATE CONSTRAINT` before setting `NOT NULL`.
- Verify every new list/filter query with `EXPLAIN (ANALYZE, BUFFERS)` to prevent sequential scans on tables exceeding 10,000 rows.

## Verification Check
```bash
grep -rn 'CREATE INDEX ' migrations/ | grep -v 'CONCURRENTLY' && exit 1 || echo 'All indexes concurrent-safe'
```

Ghi chú Thiết lập Cộng đồng & Đánh giá Sản xuất (0)

Chưa có ghi chú cộng đồng nào. Chia sẻ mẹo cấu hình sản xuất của bạn bên dưới.

Đăng ghi chú thiết lập hoặc mẹo xác minh

Trình kiểm tra lược đồ tài nguyên và công cụ MCP

Mã định danh công cụ/tài nguyênThông số đầu vàoHành vi thực thi
lock_safe_ddl_guardmigrations/**/*.sqlRequires lock_timeout = '2s' and CREATE INDEX CONCURRENTLY on live tables.
jsonb_gin_operator_classschema.sqlSelects jsonb_path_ops GIN indexes for fast @> containment lookups.