[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M70FSG6XAE01506M535DVHDV":3,"skill-same:01M70FSG6XAE01506M535DVHDV":132},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":34,"publishedAt":55,"linkOnly":56,"markdownContent":57,"markdownBody":58,"frontMatter":59,"refName":60,"commitSha":61,"skillDirectory":62,"forksCount":63,"repositoryHtmlUrl":64,"repositoryHomepageUrl":65,"ownerHtmlUrl":66,"ownerBlogUrl":67,"ownerDescription":68,"updatedAt":69,"install":70,"resources":83},"01M70FSG6XAE01506M535DVHDV","postgresql-database",null,"Expert PostgreSQL database development skill covering schema design, normalization, Alembic migrations, SQLAlchemy ORM patterns, query optimization, index strategies, JSONB for flexible data, and full-text search. Use when designing database schemas, creating migrations, optimizing queries, implementing full-text search, or working with PostgreSQL-specific features like JSONB.","shengdabai\u002FTony-Claude-Code-Skills","shengdabai","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F116417419?v=4","01M70F6D2WY5PQV5A92BKYJQEW","Tony Sheng","01M70F6D3GAAAYZ5H4CC1G8VXM",3,"MIT","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fdot_claude\u002Fskills\u002Fpostgresql-database\u002FSKILL.md",[18,23,26,29],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000010","后端与接口","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000015","视觉设计",{"categoryNo":27,"categoryName":28,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":30,"categoryName":31,"taxonomyType":32,"taxonomyTypeDesc":33},"01JBSEEDCAT000000000000032","设计师","PROFESSION","适用职业",[35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54],"database","postgresql database","postgresql","patterns","design","when","features","implementing","sqlalchemy","full","strategies","query","expert","Designing Database Schemas","schema design","query optimization","text","normalization","data","search","2026-11-10 10:12:30",false,"---\nname: postgresql-database\ndescription: Expert PostgreSQL database development skill covering schema design, normalization, Alembic migrations, SQLAlchemy ORM patterns, query optimization, index strategies, JSONB for flexible data, and full-text search. Use when designing database schemas, creating migrations, optimizing queries, implementing full-text search, or working with PostgreSQL-specific features like JSONB.\n---\n\n# PostgreSQL Database Development\n\n## Overview\n\nMaster PostgreSQL database development with comprehensive guidance on schema design, migrations, ORM patterns, and advanced PostgreSQL features. This skill provides best practices, reference documentation, and automation scripts for building high-performance, well-structured PostgreSQL databases.\n\n## When to Use This Skill\n\nUse this skill when working on:\n- Database schema design and normalization\n- Creating or reviewing Alembic migrations\n- Defining SQLAlchemy models and relationships\n- Optimizing slow queries or improving database performance\n- Choosing and implementing index strategies\n- Working with JSONB for semi-structured data\n- Implementing full-text search functionality\n- Analyzing database performance issues\n- Setting up database projects from scratch\n\n## Core Capabilities\n\n### 1. Schema Design and Normalization\n\nConsult `references\u002Fschema_design.md` for:\n- Database normalization (1NF, 2NF, 3NF) with practical examples\n- Common design patterns (one-to-many, many-to-many, self-referential)\n- Polymorphic associations and inheritance patterns\n- Audit trail and temporal data patterns\n- Soft delete implementation\n- Anti-patterns to avoid (EAV, god tables, etc.)\n\n**When to read this reference:**\n- Designing new database schemas\n- Reviewing existing schema for normalization issues\n- Implementing common relationship patterns\n- Adding audit trails or soft deletes\n\n**Example usage:**\n```\nWhen designing a new user management system, reference schema_design.md for:\n- Proper normalization of user attributes\n- Many-to-many relationship patterns for user roles\n- Audit trail implementation to track user changes\n```\n\n### 2. Alembic Migration Workflows\n\nConsult `references\u002Falembic_migrations.md` for:\n- Initial Alembic setup and configuration\n- Auto-generating migrations from SQLAlchemy models\n- Manual migration creation for complex changes\n- Adding\u002Fmodifying columns, indexes, and constraints\n- Data migrations and transformations\n- PostgreSQL-specific features (ENUM, JSONB, extensions)\n- Production-safe migration practices (CONCURRENTLY)\n- Branching and merging strategies\n- Common issues and solutions\n\n**Automation script:** `scripts\u002Finit_alembic.py`\n- Initializes Alembic with best practices\n- Configures environment variable support\n- Creates custom migration templates\n- Generates comprehensive README\n\n**When to use:**\n```bash\n# Initialize new project with Alembic\npython scripts\u002Finit_alembic.py --models-path app\u002Fmodels.py\n```\n\n**When to read this reference:**\n- Creating database migrations\n- Troubleshooting migration issues\n- Migrating production databases safely\n- Understanding Alembic best practices\n\n### 3. SQLAlchemy Model Definitions\n\nConsult `references\u002Fsqlalchemy_models.md` for:\n- Basic and modern (2.0+) model syntax\n- Relationship patterns (one-to-many, many-to-many, self-referential)\n- Column types and constraints\n- Advanced patterns (mixins, hybrid properties, events)\n- Table inheritance strategies\n- Association proxies and composite columns\n- Model validation\n\n**When to read this reference:**\n- Defining new SQLAlchemy models\n- Implementing complex relationships\n- Using advanced SQLAlchemy features\n- Migrating to SQLAlchemy 2.0 syntax\n\n**Example usage:**\n```\nWhen creating models for a blog platform, reference sqlalchemy_models.md for:\n- One-to-many relationship between User and Post\n- Many-to-many relationship between Post and Tag\n- Hybrid properties for computed fields\n- Timestamp mixins for created_at\u002Fupdated_at\n```\n\n### 4. Query Optimization Techniques\n\nConsult `references\u002Fquery_optimization.md` for:\n- Understanding EXPLAIN and EXPLAIN ANALYZE\n- Different scan types (index-only, index, bitmap, sequential)\n- Solving N+1 query problems with eager loading\n- Join optimization strategies\n- Efficient pagination (keyset vs offset)\n- Aggregation and grouping optimization\n- Subquery optimization (EXISTS vs IN)\n- Batch operations for bulk inserts\u002Fupdates\n- Avoiding common anti-patterns\n\n**Analysis script:** `scripts\u002Fanalyze_queries.py`\n- Analyzes slow queries using pg_stat_statements\n- Identifies most time-consuming queries\n- Finds queries with high variability\n- Provides optimization recommendations\n\n**When to use:**\n```bash\n# Analyze query performance\npython scripts\u002Fanalyze_queries.py postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb --limit 20\n```\n\n**When to read this reference:**\n- Diagnosing slow queries\n- Improving application performance\n- Reviewing query patterns\n- Understanding query execution plans\n\n### 5. Index Strategies\n\nConsult `references\u002Findexes.md` for:\n- Index types (B-tree, Hash, GIN, GiST, BRIN, SP-GiST)\n- When to use each index type\n- Composite indexes and column ordering\n- Partial indexes for conditional indexing\n- Expression indexes for computed values\n- Covering indexes with INCLUDE clause\n- Index maintenance and monitoring\n- Best practices and common pitfalls\n\n**Analysis script:** `scripts\u002Fanalyze_indexes.py`\n- Finds unused indexes\n- Detects duplicate indexes\n- Identifies missing indexes on foreign keys\n- Shows most-used indexes\n- Provides actionable recommendations\n\n**When to use:**\n```bash\n# Analyze index usage and health\npython scripts\u002Fanalyze_indexes.py postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb\n```\n\n**When to read this reference:**\n- Adding new indexes to improve query performance\n- Choosing the right index type for your use case\n- Optimizing existing indexes\n- Understanding index trade-offs\n\n### 6. JSONB for Flexible Data\n\nConsult `references\u002Fjsonb_usage.md` for:\n- JSONB vs JSON comparison\n- Basic JSONB operations and operators\n- Querying and filtering JSONB data\n- Modifying JSONB fields\n- JSONB functions and aggregations\n- Indexing strategies for JSONB (GIN, expression indexes)\n- Advanced patterns (validation, combining with structured data)\n- Performance considerations\n- SQLAlchemy JSONB usage\n\n**When to read this reference:**\n- Storing semi-structured or flexible data\n- Working with user-generated attributes\n- Implementing schema-less fields\n- Querying or updating JSON data\n- Optimizing JSONB performance\n\n**Example usage:**\n```\nWhen building a product catalog with varying attributes, reference jsonb_usage.md for:\n- Storing product attributes in JSONB\n- Querying products by specific attributes\n- Indexing JSONB for fast lookups\n- Validating JSONB structure with constraints\n```\n\n### 7. Full-Text Search Implementation\n\nConsult `references\u002Ffulltext_search.md` for:\n- Full-text search basics (tsvector, tsquery)\n- Creating efficient full-text search indexes\n- Query syntax (AND, OR, NOT, phrases, prefix matching)\n- Ranking and sorting search results\n- Highlighting search results\n- Multi-language support\n- Fuzzy search with trigrams\n- Performance optimization\n- Advanced patterns (multi-table search, autocomplete)\n- SQLAlchemy integration\n\n**When to read this reference:**\n- Implementing search functionality\n- Optimizing existing search queries\n- Supporting multiple languages\n- Adding autocomplete or fuzzy matching\n- Combining full-text with other filters\n\n**Example usage:**\n```\nWhen adding search to a blog platform, reference fulltext_search.md for:\n- Creating tsvector column with weighted title and content\n- Building search queries from user input\n- Ranking results by relevance\n- Highlighting matching terms in snippets\n```\n\n## Utility Scripts\n\n### Schema Inspector\n**Script:** `scripts\u002Fschema_inspector.py`\n\nGenerate comprehensive documentation of your database schema.\n\n**Usage:**\n```bash\n# Generate markdown documentation for entire database\npython scripts\u002Fschema_inspector.py postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb\n\n# Inspect specific table\npython scripts\u002Fschema_inspector.py postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb --table users\n\n# Output as JSON\npython scripts\u002Fschema_inspector.py postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb --output json\n```\n\n**When to use:**\n- Documenting existing databases\n- Understanding inherited codebases\n- Reviewing schema structure\n- Generating schema documentation\n\n## Workflow Examples\n\n### Starting a New Database Project\n\n1. **Design the schema**\n   - Read `references\u002Fschema_design.md` for normalization guidance\n   - Sketch out table relationships\n   - Identify common patterns (audit trails, soft deletes)\n\n2. **Set up SQLAlchemy models**\n   - Read `references\u002Fsqlalchemy_models.md` for model patterns\n   - Define Base and create model classes\n   - Implement relationships and constraints\n\n3. **Initialize Alembic**\n   ```bash\n   python scripts\u002Finit_alembic.py --models-path app\u002Fmodels.py\n   export DATABASE_URL=\"postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb\"\n   ```\n\n4. **Create initial migration**\n   - Read `references\u002Falembic_migrations.md` for best practices\n   - Generate migration: `alembic revision --autogenerate -m \"Initial schema\"`\n   - Review and adjust the generated migration\n   - Apply migration: `alembic upgrade head`\n\n5. **Add indexes**\n   - Read `references\u002Findexes.md` for index strategies\n   - Add indexes for foreign keys and frequently queried columns\n   - Create migration for indexes: `alembic revision -m \"Add indexes\"`\n\n### Optimizing Database Performance\n\n1. **Identify slow queries**\n   ```bash\n   python scripts\u002Fanalyze_queries.py postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb --limit 20\n   ```\n\n2. **Analyze query execution**\n   - Use EXPLAIN ANALYZE on identified slow queries\n   - Read `references\u002Fquery_optimization.md` for optimization techniques\n   - Check for N+1 queries, missing indexes, or inefficient joins\n\n3. **Review index usage**\n   ```bash\n   python scripts\u002Fanalyze_indexes.py postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb\n   ```\n\n4. **Implement optimizations**\n   - Add missing indexes on foreign keys\n   - Remove unused indexes\n   - Optimize queries based on recommendations\n   - Use appropriate eager loading strategies\n\n5. **Verify improvements**\n   - Re-run analysis scripts\n   - Compare query execution times\n   - Monitor production metrics\n\n### Adding Full-Text Search\n\n1. **Read the reference**\n   - Consult `references\u002Ffulltext_search.md` for implementation patterns\n\n2. **Choose an approach**\n   - Generated column (PostgreSQL 12+) - recommended\n   - Trigger-based update\n   - Expression index\n\n3. **Implement search vector**\n   ```python\n   # Example using generated column\n   search_vector = Column(\n       TSVECTOR,\n       Computed(\"to_tsvector('english', coalesce(title, '') || ' ' || coalesce(content, ''))\")\n   )\n   ```\n\n4. **Create migration**\n   - Generate Alembic migration\n   - Add GIN index on search_vector\n   - Review migration for correctness\n\n5. **Implement search queries**\n   - Use websearch_to_tsquery for user input\n   - Add ranking and highlighting\n   - Test with various queries\n\n## Best Practices\n\n### Schema Design\n- Normalize to 3NF unless there's a specific reason not to\n- Use appropriate data types (don't store everything as TEXT)\n- Add constraints (NOT NULL, CHECK, UNIQUE) at the database level\n- Use foreign keys with ON DELETE\u002FON UPDATE actions\n- Consider partial indexes for frequently filtered queries\n\n### Migrations\n- Always review auto-generated migrations\n- Test migrations on development data first\n- Write reversible migrations (proper downgrade implementations)\n- Use CONCURRENTLY for index operations in production\n- Add data migrations separately from schema changes\n\n### Query Optimization\n- Index foreign keys and frequently queried columns\n- Use appropriate eager loading to avoid N+1 queries\n- Prefer keyset pagination over OFFSET for large datasets\n- Use EXPLAIN ANALYZE to verify index usage\n- Monitor query performance with pg_stat_statements\n\n### Indexes\n- Don't over-index - each index has overhead on writes\n- Create indexes CONCURRENTLY in production\n- Remove unused indexes\n- Use partial indexes when only subset needs indexing\n- Choose appropriate index type for your query patterns\n\n### JSONB\n- Use JSONB over JSON for better performance\n- Index JSONB columns with GIN for containment queries\n- Use expression indexes for specific JSONB fields\n- Combine structured columns with JSONB for flexibility\n- Validate JSONB structure with CHECK constraints\n\n## Additional Resources\n\nAll reference files contain extensive code examples, best practices, and anti-patterns to avoid. Read the relevant reference file when working on tasks in that domain.\n\nThe automation scripts provide practical tools for common database tasks:\n- `init_alembic.py` - Set up Alembic with best practices\n- `analyze_indexes.py` - Find optimization opportunities\n- `analyze_queries.py` - Identify performance bottlenecks\n- `schema_inspector.py` - Generate schema documentation\n\nFor production deployments, always:\n- Test migrations in staging environment first\n- Use CONCURRENTLY for index operations\n- Monitor query performance\n- Keep statistics up to date with ANALYZE\n- Review execution plans with EXPLAIN\n","# PostgreSQL Database Development\n\n## Overview\n\nMaster PostgreSQL database development with comprehensive guidance on schema design, migrations, ORM patterns, and advanced PostgreSQL features. This skill provides best practices, reference documentation, and automation scripts for building high-performance, well-structured PostgreSQL databases.\n\n## When to Use This Skill\n\nUse this skill when working on:\n- Database schema design and normalization\n- Creating or reviewing Alembic migrations\n- Defining SQLAlchemy models and relationships\n- Optimizing slow queries or improving database performance\n- Choosing and implementing index strategies\n- Working with JSONB for semi-structured data\n- Implementing full-text search functionality\n- Analyzing database performance issues\n- Setting up database projects from scratch\n\n## Core Capabilities\n\n### 1. Schema Design and Normalization\n\nConsult `references\u002Fschema_design.md` for:\n- Database normalization (1NF, 2NF, 3NF) with practical examples\n- Common design patterns (one-to-many, many-to-many, self-referential)\n- Polymorphic associations and inheritance patterns\n- Audit trail and temporal data patterns\n- Soft delete implementation\n- Anti-patterns to avoid (EAV, god tables, etc.)\n\n**When to read this reference:**\n- Designing new database schemas\n- Reviewing existing schema for normalization issues\n- Implementing common relationship patterns\n- Adding audit trails or soft deletes\n\n**Example usage:**\n```\nWhen designing a new user management system, reference schema_design.md for:\n- Proper normalization of user attributes\n- Many-to-many relationship patterns for user roles\n- Audit trail implementation to track user changes\n```\n\n### 2. Alembic Migration Workflows\n\nConsult `references\u002Falembic_migrations.md` for:\n- Initial Alembic setup and configuration\n- Auto-generating migrations from SQLAlchemy models\n- Manual migration creation for complex changes\n- Adding\u002Fmodifying columns, indexes, and constraints\n- Data migrations and transformations\n- PostgreSQL-specific features (ENUM, JSONB, extensions)\n- Production-safe migration practices (CONCURRENTLY)\n- Branching and merging strategies\n- Common issues and solutions\n\n**Automation script:** `scripts\u002Finit_alembic.py`\n- Initializes Alembic with best practices\n- Configures environment variable support\n- Creates custom migration templates\n- Generates comprehensive README\n\n**When to use:**\n```bash\n# Initialize new project with Alembic\npython scripts\u002Finit_alembic.py --models-path app\u002Fmodels.py\n```\n\n**When to read this reference:**\n- Creating database migrations\n- Troubleshooting migration issues\n- Migrating production databases safely\n- Understanding Alembic best practices\n\n### 3. SQLAlchemy Model Definitions\n\nConsult `references\u002Fsqlalchemy_models.md` for:\n- Basic and modern (2.0+) model syntax\n- Relationship patterns (one-to-many, many-to-many, self-referential)\n- Column types and constraints\n- Advanced patterns (mixins, hybrid properties, events)\n- Table inheritance strategies\n- Association proxies and composite columns\n- Model validation\n\n**When to read this reference:**\n- Defining new SQLAlchemy models\n- Implementing complex relationships\n- Using advanced SQLAlchemy features\n- Migrating to SQLAlchemy 2.0 syntax\n\n**Example usage:**\n```\nWhen creating models for a blog platform, reference sqlalchemy_models.md for:\n- One-to-many relationship between User and Post\n- Many-to-many relationship between Post and Tag\n- Hybrid properties for computed fields\n- Timestamp mixins for created_at\u002Fupdated_at\n```\n\n### 4. Query Optimization Techniques\n\nConsult `references\u002Fquery_optimization.md` for:\n- Understanding EXPLAIN and EXPLAIN ANALYZE\n- Different scan types (index-only, index, bitmap, sequential)\n- Solving N+1 query problems with eager loading\n- Join optimization strategies\n- Efficient pagination (keyset vs offset)\n- Aggregation and grouping optimization\n- Subquery optimization (EXISTS vs IN)\n- Batch operations for bulk inserts\u002Fupdates\n- Avoiding common anti-patterns\n\n**Analysis script:** `scripts\u002Fanalyze_queries.py`\n- Analyzes slow queries using pg_stat_statements\n- Identifies most time-consuming queries\n- Finds queries with high variability\n- Provides optimization recommendations\n\n**When to use:**\n```bash\n# Analyze query performance\npython scripts\u002Fanalyze_queries.py postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb --limit 20\n```\n\n**When to read this reference:**\n- Diagnosing slow queries\n- Improving application performance\n- Reviewing query patterns\n- Understanding query execution plans\n\n### 5. Index Strategies\n\nConsult `references\u002Findexes.md` for:\n- Index types (B-tree, Hash, GIN, GiST, BRIN, SP-GiST)\n- When to use each index type\n- Composite indexes and column ordering\n- Partial indexes for conditional indexing\n- Expression indexes for computed values\n- Covering indexes with INCLUDE clause\n- Index maintenance and monitoring\n- Best practices and common pitfalls\n\n**Analysis script:** `scripts\u002Fanalyze_indexes.py`\n- Finds unused indexes\n- Detects duplicate indexes\n- Identifies missing indexes on foreign keys\n- Shows most-used indexes\n- Provides actionable recommendations\n\n**When to use:**\n```bash\n# Analyze index usage and health\npython scripts\u002Fanalyze_indexes.py postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb\n```\n\n**When to read this reference:**\n- Adding new indexes to improve query performance\n- Choosing the right index type for your use case\n- Optimizing existing indexes\n- Understanding index trade-offs\n\n### 6. JSONB for Flexible Data\n\nConsult `references\u002Fjsonb_usage.md` for:\n- JSONB vs JSON comparison\n- Basic JSONB operations and operators\n- Querying and filtering JSONB data\n- Modifying JSONB fields\n- JSONB functions and aggregations\n- Indexing strategies for JSONB (GIN, expression indexes)\n- Advanced patterns (validation, combining with structured data)\n- Performance considerations\n- SQLAlchemy JSONB usage\n\n**When to read this reference:**\n- Storing semi-structured or flexible data\n- Working with user-generated attributes\n- Implementing schema-less fields\n- Querying or updating JSON data\n- Optimizing JSONB performance\n\n**Example usage:**\n```\nWhen building a product catalog with varying attributes, reference jsonb_usage.md for:\n- Storing product attributes in JSONB\n- Querying products by specific attributes\n- Indexing JSONB for fast lookups\n- Validating JSONB structure with constraints\n```\n\n### 7. Full-Text Search Implementation\n\nConsult `references\u002Ffulltext_search.md` for:\n- Full-text search basics (tsvector, tsquery)\n- Creating efficient full-text search indexes\n- Query syntax (AND, OR, NOT, phrases, prefix matching)\n- Ranking and sorting search results\n- Highlighting search results\n- Multi-language support\n- Fuzzy search with trigrams\n- Performance optimization\n- Advanced patterns (multi-table search, autocomplete)\n- SQLAlchemy integration\n\n**When to read this reference:**\n- Implementing search functionality\n- Optimizing existing search queries\n- Supporting multiple languages\n- Adding autocomplete or fuzzy matching\n- Combining full-text with other filters\n\n**Example usage:**\n```\nWhen adding search to a blog platform, reference fulltext_search.md for:\n- Creating tsvector column with weighted title and content\n- Building search queries from user input\n- Ranking results by relevance\n- Highlighting matching terms in snippets\n```\n\n## Utility Scripts\n\n### Schema Inspector\n**Script:** `scripts\u002Fschema_inspector.py`\n\nGenerate comprehensive documentation of your database schema.\n\n**Usage:**\n```bash\n# Generate markdown documentation for entire database\npython scripts\u002Fschema_inspector.py postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb\n\n# Inspect specific table\npython scripts\u002Fschema_inspector.py postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb --table users\n\n# Output as JSON\npython scripts\u002Fschema_inspector.py postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb --output json\n```\n\n**When to use:**\n- Documenting existing databases\n- Understanding inherited codebases\n- Reviewing schema structure\n- Generating schema documentation\n\n## Workflow Examples\n\n### Starting a New Database Project\n\n1. **Design the schema**\n   - Read `references\u002Fschema_design.md` for normalization guidance\n   - Sketch out table relationships\n   - Identify common patterns (audit trails, soft deletes)\n\n2. **Set up SQLAlchemy models**\n   - Read `references\u002Fsqlalchemy_models.md` for model patterns\n   - Define Base and create model classes\n   - Implement relationships and constraints\n\n3. **Initialize Alembic**\n   ```bash\n   python scripts\u002Finit_alembic.py --models-path app\u002Fmodels.py\n   export DATABASE_URL=\"postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb\"\n   ```\n\n4. **Create initial migration**\n   - Read `references\u002Falembic_migrations.md` for best practices\n   - Generate migration: `alembic revision --autogenerate -m \"Initial schema\"`\n   - Review and adjust the generated migration\n   - Apply migration: `alembic upgrade head`\n\n5. **Add indexes**\n   - Read `references\u002Findexes.md` for index strategies\n   - Add indexes for foreign keys and frequently queried columns\n   - Create migration for indexes: `alembic revision -m \"Add indexes\"`\n\n### Optimizing Database Performance\n\n1. **Identify slow queries**\n   ```bash\n   python scripts\u002Fanalyze_queries.py postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb --limit 20\n   ```\n\n2. **Analyze query execution**\n   - Use EXPLAIN ANALYZE on identified slow queries\n   - Read `references\u002Fquery_optimization.md` for optimization techniques\n   - Check for N+1 queries, missing indexes, or inefficient joins\n\n3. **Review index usage**\n   ```bash\n   python scripts\u002Fanalyze_indexes.py postgresql:\u002F\u002Fuser:pass@localhost\u002Fdb\n   ```\n\n4. **Implement optimizations**\n   - Add missing indexes on foreign keys\n   - Remove unused indexes\n   - Optimize queries based on recommendations\n   - Use appropriate eager loading strategies\n\n5. **Verify improvements**\n   - Re-run analysis scripts\n   - Compare query execution times\n   - Monitor production metrics\n\n### Adding Full-Text Search\n\n1. **Read the reference**\n   - Consult `references\u002Ffulltext_search.md` for implementation patterns\n\n2. **Choose an approach**\n   - Generated column (PostgreSQL 12+) - recommended\n   - Trigger-based update\n   - Expression index\n\n3. **Implement search vector**\n   ```python\n   # Example using generated column\n   search_vector = Column(\n       TSVECTOR,\n       Computed(\"to_tsvector('english', coalesce(title, '') || ' ' || coalesce(content, ''))\")\n   )\n   ```\n\n4. **Create migration**\n   - Generate Alembic migration\n   - Add GIN index on search_vector\n   - Review migration for correctness\n\n5. **Implement search queries**\n   - Use websearch_to_tsquery for user input\n   - Add ranking and highlighting\n   - Test with various queries\n\n## Best Practices\n\n### Schema Design\n- Normalize to 3NF unless there's a specific reason not to\n- Use appropriate data types (don't store everything as TEXT)\n- Add constraints (NOT NULL, CHECK, UNIQUE) at the database level\n- Use foreign keys with ON DELETE\u002FON UPDATE actions\n- Consider partial indexes for frequently filtered queries\n\n### Migrations\n- Always review auto-generated migrations\n- Test migrations on development data first\n- Write reversible migrations (proper downgrade implementations)\n- Use CONCURRENTLY for index operations in production\n- Add data migrations separately from schema changes\n\n### Query Optimization\n- Index foreign keys and frequently queried columns\n- Use appropriate eager loading to avoid N+1 queries\n- Prefer keyset pagination over OFFSET for large datasets\n- Use EXPLAIN ANALYZE to verify index usage\n- Monitor query performance with pg_stat_statements\n\n### Indexes\n- Don't over-index - each index has overhead on writes\n- Create indexes CONCURRENTLY in production\n- Remove unused indexes\n- Use partial indexes when only subset needs indexing\n- Choose appropriate index type for your query patterns\n\n### JSONB\n- Use JSONB over JSON for better performance\n- Index JSONB columns with GIN for containment queries\n- Use expression indexes for specific JSONB fields\n- Combine structured columns with JSONB for flexibility\n- Validate JSONB structure with CHECK constraints\n\n## Additional Resources\n\nAll reference files contain extensive code examples, best practices, and anti-patterns to avoid. Read the relevant reference file when working on tasks in that domain.\n\nThe automation scripts provide practical tools for common database tasks:\n- `init_alembic.py` - Set up Alembic with best practices\n- `analyze_indexes.py` - Find optimization opportunities\n- `analyze_queries.py` - Identify performance bottlenecks\n- `schema_inspector.py` - Generate schema documentation\n\nFor production deployments, always:\n- Test migrations in staging environment first\n- Use CONCURRENTLY for index operations\n- Monitor query performance\n- Keep statistics up to date with ANALYZE\n- Review execution plans with EXPLAIN\n",{"name":5,"description":7},"main","7850740bd837adb32f0a109ab2af82482196c6f2","skills\u002F_collections\u002Fdot_claude\u002Fskills\u002Fpostgresql-database",1,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills","https:\u002F\u002Fzturnsgo.com","https:\u002F\u002Fgithub.com\u002Fshengdabai","https:\u002F\u002Fzturnsgo.com\u002F","AI × education creator — producer, not consumer. Taught 6,000+ learners; shipping learning tools & daily essays with Claude Code, practicing @xiaolai's way 🥋","2026-11-01 21:28:23",{"source":8,"skillName":5,"commands":71,"prompt":81,"zipAvailable":82},[72,75,78],{"tool":73,"command":74},"npx","npx skills add shengdabai\u002FTony-Claude-Code-Skills --skill postgresql-database",{"tool":76,"command":77},"bunx","bunx skills add shengdabai\u002FTony-Claude-Code-Skills --skill postgresql-database",{"tool":79,"command":80},"pnpm","pnpm dlx skills add shengdabai\u002FTony-Claude-Code-Skills --skill postgresql-database","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fdot_claude\u002Fskills\u002Fpostgresql-database\u002FSKILL.md",true,[84,90,94,98,102,106,110,114,120,124,128],{"path":85,"resourceType":86,"resourceTypeDesc":87,"sizeBytes":88,"sourceHtmlUrl":89},"references\u002Falembic_migrations.md","REFERENCE","参考文档",13757,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fdot_claude\u002Fskills\u002Fpostgresql-database\u002Freferences\u002Falembic_migrations.md",{"path":91,"resourceType":86,"resourceTypeDesc":87,"sizeBytes":92,"sourceHtmlUrl":93},"references\u002Ffulltext_search.md",16530,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fdot_claude\u002Fskills\u002Fpostgresql-database\u002Freferences\u002Ffulltext_search.md",{"path":95,"resourceType":86,"resourceTypeDesc":87,"sizeBytes":96,"sourceHtmlUrl":97},"references\u002Findexes.md",14850,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fdot_claude\u002Fskills\u002Fpostgresql-database\u002Freferences\u002Findexes.md",{"path":99,"resourceType":86,"resourceTypeDesc":87,"sizeBytes":100,"sourceHtmlUrl":101},"references\u002Fjsonb_usage.md",14352,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fdot_claude\u002Fskills\u002Fpostgresql-database\u002Freferences\u002Fjsonb_usage.md",{"path":103,"resourceType":86,"resourceTypeDesc":87,"sizeBytes":104,"sourceHtmlUrl":105},"references\u002Fquery_optimization.md",12355,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fdot_claude\u002Fskills\u002Fpostgresql-database\u002Freferences\u002Fquery_optimization.md",{"path":107,"resourceType":86,"resourceTypeDesc":87,"sizeBytes":108,"sourceHtmlUrl":109},"references\u002Fschema_design.md",10120,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fdot_claude\u002Fskills\u002Fpostgresql-database\u002Freferences\u002Fschema_design.md",{"path":111,"resourceType":86,"resourceTypeDesc":87,"sizeBytes":112,"sourceHtmlUrl":113},"references\u002Fsqlalchemy_models.md",17381,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fdot_claude\u002Fskills\u002Fpostgresql-database\u002Freferences\u002Fsqlalchemy_models.md",{"path":115,"resourceType":116,"resourceTypeDesc":117,"sizeBytes":118,"sourceHtmlUrl":119},"scripts\u002Fanalyze_indexes.py","SCRIPT","脚本",7052,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fdot_claude\u002Fskills\u002Fpostgresql-database\u002Fscripts\u002Fanalyze_indexes.py",{"path":121,"resourceType":116,"resourceTypeDesc":117,"sizeBytes":122,"sourceHtmlUrl":123},"scripts\u002Fanalyze_queries.py",8163,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fdot_claude\u002Fskills\u002Fpostgresql-database\u002Fscripts\u002Fanalyze_queries.py",{"path":125,"resourceType":116,"resourceTypeDesc":117,"sizeBytes":126,"sourceHtmlUrl":127},"scripts\u002Finit_alembic.py",9533,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fdot_claude\u002Fskills\u002Fpostgresql-database\u002Fscripts\u002Finit_alembic.py",{"path":129,"resourceType":116,"resourceTypeDesc":117,"sizeBytes":130,"sourceHtmlUrl":131},"scripts\u002Fschema_inspector.py",6830,"https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002F_collections\u002Fdot_claude\u002Fskills\u002Fpostgresql-database\u002Fscripts\u002Fschema_inspector.py",[133,150,180,206,228,248],{"skillNo":134,"name":135,"nameZh":6,"description":136,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":137,"categories":138,"keywords":142,"publishedAt":55},"01M70P17DAD4C1C47NPH6A96EM","xiaolai-methodology","以李笑来(Li Xiaolai)的思考方式、方法论与表达风格,为用户做全方位 1-on-1 教练指导,覆盖创业、赚钱、投资、学习、自学、读书写作、用 AI、以及人生心态与自我管理。当用户提到 \"李笑来\"、\"笑来\"、\"笑来老师\"、\"扮演李笑来\"、\"找笑来聊聊\"、\"笑来怎么看\"、\"xiaolai\"、\"把时间当作朋友\"、\"通往财富自由之路\"、\"定投改变命运\"、\"韭菜的自我修养\"、\"自学是门手艺\"、\"让时间陪你慢慢变富\"、\"七年就是一辈子\"、\"元认知\"、\"活在未来\"、\"复利\u002F长期主义\"、\"践行\"、\"痴迷改进\"、\"个人商业模式\u002F出售时间\"、\"睡后收入\"、\"定投\"、\"财富自由\"、\"操作系统升级\"、\"最少必要知识\"、\"北极星提示词\"、\"用 AI 该怎么学\u002F思考\" 等任一触发词,或当用户带着关于创业\u002F赚钱\u002F投资\u002F学习\u002F职业\u002F重大人生决策的困惑、希望被人用笑来式的「逻辑 + 大白话 + 类比 + 重新定义 + 践行导向」来点醒和指导时,自动进入李笑来教练模式。","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fxiaolai-methodology\u002FSKILL.md",[139],{"categoryNo":140,"categoryName":141,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000018","写作与文案",[143,144,145,146,147,148,149],"methodology","xiaolai","xiaolai methodology","朋友","投资","writing","收入",{"skillNo":151,"name":152,"nameZh":6,"description":153,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":154,"categories":155,"keywords":160,"publishedAt":55},"01M70P13NB9YP7ACJR1S861CDS","zread","Produce and consume a wiki-style knowledge base for a code repository via the `zread` CLI and its on-disk output under `.\u002F.zread\u002Fwiki\u002F`. Use this skill whenever the user wants to understand, onboard onto, explore, summarize, map, or get an overview of an unfamiliar codebase; asks for architecture docs, a project wiki, a repo walkthrough, module\u002Fpackage explanations, or \"what does this repo do\"; wants to generate, regenerate, resume, browse, or serve code documentation locally; or mentions zread \u002F zread.ai directly. Also use it proactively before diving into a large unknown repo — if `.\u002F.zread\u002Fwiki\u002Fcurrent` exists, read the generated pages instead of crawling source file-by-file; if it doesn't, consider offering to run `zread generate`. The trigger is the intent (understand a codebase through generated docs), not the literal word \"zread\".","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fzread\u002FSKILL.md",[156,157],{"categoryNo":27,"categoryName":28,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":158,"categoryName":159,"taxonomyType":32,"taxonomyTypeDesc":33},"01JBSEEDCAT000000000000030","开发工程师",[152,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179],"knowledge","wiki","explore","walkthrough","project","get","knowledge base","run","generate","intent","cli","map","documentation","project wiki","disk","architecture","code","unknown","generated",{"skillNo":181,"name":182,"nameZh":6,"description":183,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":184,"categories":185,"keywords":190,"publishedAt":55},"01M70P10S4SWMZQ8BJAFBFDRW3","youtube","Launch the YouTube Creator Agent to auto-generate videos.\nUse when: user types \u002Fyoutube, wants to create YouTube videos,\ngenerate video content, or upload to YouTube.\nKeywords: youtube, video, 视频, 创作视频, 发布视频","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fyoutube\u002FSKILL.md",[186,187],{"categoryNo":27,"categoryName":28,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":188,"categoryName":189,"taxonomyType":32,"taxonomyTypeDesc":33},"01JBSEEDCAT000000000000036","内容创作者",[182,191,192,193,194,195,196,197,169,198,199,200,40,201,202,203,204,205],"user","content","视频","creator","generate video","videos","launch","video content","create","upload","use","auto","types","Video","创作",{"skillNo":207,"name":208,"nameZh":6,"description":209,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":210,"categories":211,"keywords":213,"publishedAt":55},"01M70P0YE95D8BACZCGV8BK90K","youtube-script-sync","Sync, update, or optimize Tony's GetNote knowledge base `Youtube视频逐字稿` by turning each parent recording or first-person idea note into an idempotent child note containing a directly recordable YouTube long-video or Shorts script. Use when the user says “更新\u002F同步\u002F优化 Youtube视频逐字稿知识库”, or says “更新\u002F同步\u002F优化该知识库” while this knowledge base is the active context.","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fyoutube-script-sync\u002FSKILL.md",[212],{"categoryNo":27,"categoryName":28,"taxonomyType":21,"taxonomyTypeDesc":22},[214,215,182,216,217,204,218,219,220,221,222,223,224,225,167,226,40,201,161,227],"sync","script","youtube script sync","recording","shorts","first","base","person","update","active","child","optimize","idempotent","long",{"skillNo":229,"name":230,"nameZh":6,"description":231,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":232,"categories":233,"keywords":238,"publishedAt":55},"01M70P0WMV5XT0EEC0N445PW07","writing-skills","How to write SKILL.md files that trigger reliably and teach effectively. Use when creating, improving, or reviewing Claude Code skills.","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fxiaolai\u002Fnlpm\u002Fskills\u002Fnlpm\u002Fwriting-skills\u002FSKILL.md",[234,235,236,237],{"categoryNo":140,"categoryName":141,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":27,"categoryName":28,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":158,"categoryName":159,"taxonomyType":32,"taxonomyTypeDesc":33},{"categoryNo":188,"categoryName":189,"taxonomyType":32,"taxonomyTypeDesc":33},[239,148,240,241,242,243,177,40,201,244,245,246,247],"writing skills","how","teach","write skill","write","claude code skills","files","how to","trigger",{"skillNo":249,"name":250,"nameZh":6,"description":251,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":252,"categories":253,"keywords":256,"publishedAt":55},"01M70P0SJFR4YVJQBGMHKGSKXT","writing-rules","How to write .claude\u002Frules\u002F files that Claude actually follows. Use when creating, improving, or reviewing project rules.","https:\u002F\u002Fgithub.com\u002Fshengdabai\u002FTony-Claude-Code-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fxiaolai\u002Fnlpm\u002Fskills\u002Fnlpm\u002Fwriting-rules\u002FSKILL.md",[254,255],{"categoryNo":140,"categoryName":141,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":188,"categoryName":189,"taxonomyType":32,"taxonomyTypeDesc":33},[257,148,258,165,259,245,40,240,243,201,246],"Rules","writing rules","project rules"]