ワンクリックで
sql-workflow
SQL workflow guidelines. Activate when working with SQL files (.sql), database queries, migrations, or SQLFluff.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
SQL workflow guidelines. Activate when working with SQL files (.sql), database queries, migrations, or SQLFluff.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Language-agnostic API design patterns covering REST and GraphQL, including resource naming, HTTP methods, status codes, versioning, pagination, filtering, authentication, error handling, and schema design. Activate when working with APIs, REST endpoints, GraphQL schemas, API documentation, OpenAPI/Swagger, JWT, OAuth2, endpoint design, API versioning, rate limiting, or GraphQL resolvers.
Git workflow and commit guidelines. Trigger keywords: git, commit, push, .git, version control. MUST be activated before ANY git commit, push, or version control operation. Includes security scanning for secrets (API keys, tokens, .env files), commit message formatting with HEREDOC, logical commit grouping (docs, test, feat, fix, refactor, chore, build, deps), push behavior rules, safety rules for hooks and force pushes, and CRITICAL safeguards for destructive operations (filter-branch, gc --prune, reset --hard). Activate when user requests committing changes, pushing code, creating commits, rewriting history, or performing any git operations including analyzing uncommitted changes.
Testing workflow patterns and quality standards. Activate when working with tests, test files, test directories, code quality tools, coverage reports, or testing tasks. Includes zero-warnings policy, targeted testing during development, mocking patterns, and best practices across languages.
Ansible automation workflow guidelines. Activate when working with Ansible playbooks, ansible-playbook, inventory files (.yml, .ini), or Ansible-specific patterns.
Claude Code AI-assisted development workflow. Activate when discussing Claude Code usage, AI-assisted coding, prompting strategies, or Claude Code-specific patterns.
Guidelines for containerized projects using Docker, Dockerfile, docker-compose, container, and containerization. Covers multi-stage builds, security, signal handling, entrypoint scripts, and deployment workflows.
| name | sql-workflow |
| description | SQL workflow guidelines. Activate when working with SQL files (.sql), database queries, migrations, or SQLFluff. |
| location | user |
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
| Task | Tool | Command |
|---|---|---|
| Lint | SQLFluff | sqlfluff lint |
| Format | SQLFluff | sqlfluff fix |
| Analyze | Database | EXPLAIN ANALYZE |
snake_caseusers, order_items)id or {table_singular}_id{referenced_table_singular}_id patternis_, has_, or can_ prefix-- Good
CREATE TABLE orders (
id BIGINT PRIMARY KEY,
user_id BIGINT NOT NULL,
is_completed BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP WITH TIME ZONE
);
-- Bad
CREATE TABLE Order (
OrderID INT,
userId INT,
completed BOOLEAN
);
TEXT over VARCHAR unless length constraint is business requirementTIMESTAMP WITH TIME ZONE for all temporal dataBIGINT for IDs to prevent overflowNUMERIC(precision, scale) for money/financial dataUUID type when availableJSONB over JSON for PostgreSQLCHAR(n) - wastes space with paddingFLOAT/DOUBLE for financial calculationsTIMESTAMP without time zoneMigrations MUST follow: YYYYMMDD_HHMMSS_description.sql
20241215_143022_create_users_table.sql
20241215_150000_add_email_index_to_users.sql
20241216_090000_create_orders_table.sql
-- Migration: 20241215_143022_create_users_table.sql
-- Description: Creates the users table with core fields
BEGIN;
CREATE TABLE users (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
email TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
COMMIT;
SELECT, FROM, WHERE, JOINusers, created_atSELECT
u.id,
u.email,
COUNT(o.id) AS order_count
FROM users AS u
LEFT JOIN orders AS o
ON u.id = o.user_id
WHERE u.is_active = TRUE
AND u.created_at >= '2024-01-01'
GROUP BY u.id, u.email
HAVING COUNT(o.id) > 0
ORDER BY order_count DESC
LIMIT 100;
AS keyword explicitlyidx_{table}_{column(s)}
idx_{table}_{column1}_{column2}
-- Single column index
CREATE INDEX idx_users_email ON users (email);
-- Composite index
CREATE INDEX idx_orders_user_id_created_at ON orders (user_id, created_at);
-- Partial index
CREATE INDEX idx_orders_pending ON orders (id)
WHERE status = 'pending';
-- Unique index
CREATE UNIQUE INDEX idx_users_email_unique ON users (email);
ALTER TABLE orders
ADD CONSTRAINT fk_orders_user_id
FOREIGN KEY (user_id) REFERENCES users (id)
ON DELETE CASCADE
ON UPDATE CASCADE;
ALTER TABLE products
ADD CONSTRAINT chk_products_price_positive
CHECK (price > 0);
ALTER TABLE users
ADD CONSTRAINT chk_users_email_format
CHECK (email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$');
fk_{table}_{column}chk_{table}_{description}uq_{table}_{column(s)}IS NULL / IS NOT NULL for NULL comparisons= NULL or != NULLCOALESCE() for default valuesNULLIF() to convert values to NULL-- Correct NULL handling
SELECT * FROM users WHERE deleted_at IS NULL;
-- Using COALESCE for defaults
SELECT COALESCE(nickname, email) AS display_name FROM users;
-- Using NULLIF to handle empty strings
SELECT NULLIF(phone, '') AS phone FROM users;
EXPLAIN ANALYZE before optimizingEXPLAIN ANALYZE
SELECT * FROM orders WHERE user_id = 123;
SELECT * in production codeEXISTS instead of COUNT(*) for existence checksLIMIT with ORDER BY for pagination-- Bad: SELECT *
SELECT * FROM users WHERE id = 1;
-- Good: Explicit columns
SELECT id, email, created_at FROM users WHERE id = 1;
-- Bad: COUNT for existence
SELECT COUNT(*) > 0 FROM orders WHERE user_id = 1;
-- Good: EXISTS
SELECT EXISTS (SELECT 1 FROM orders WHERE user_id = 1);
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;
-- For critical financial operations
BEGIN ISOLATION LEVEL SERIALIZABLE;
-- ... operations ...
COMMIT;
[sqlfluff]
dialect = postgres
templater = raw
max_line_length = 120
[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = upper
[sqlfluff:rules:capitalisation.identifiers]
capitalisation_policy = lower
[sqlfluff:rules:layout.long_lines]
ignore_comment_lines = True
| Pitfall | Solution |
|---|---|
= NULL comparison | Use IS NULL |
SELECT * in production | Explicit column list |
| Missing indexes on FKs | Always index foreign keys |
| VARCHAR for text | Use TEXT |
| TIMESTAMP without TZ | Use TIMESTAMP WITH TIME ZONE |
| No transaction for writes | Wrap in BEGIN/COMMIT |
| Guessing query performance | Use EXPLAIN ANALYZE |