database-workflow

Provide database best practices for migrations, schema design, and query optimization.

Updated Apr 11, 2023
One-click install
npx skills add https://github.com/salverius-tech/dotfiles --skill database-workflow-salverius-tech
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: database-workflow
Source: https://github.com/salverius-tech/dotfiles/tree/main/home/dot_claude/skills/database-workflow
Command: npx skills add https://github.com/salverius-tech/dotfiles --skill database-workflow-salverius-tech

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides comprehensive guidance on database design, management, and optimization, helping you build robust, efficient, and maintainable database systems.

Core Features & Use Cases

  • Schema Design: Learn principles like normalization (1NF, 2NF, 3NF) and when to denormalize.
  • Migration Strategies: Understand version control, up/down migrations, and rollback plans.
  • Query Optimization: Techniques for indexing, using EXPLAIN, and avoiding common pitfalls like N+1 queries.
  • ORM Patterns: Compare Active Record vs. Data Mapper and best practices for query builders.
  • SQL vs. NoSQL: Guidance on choosing the right database type for your needs.
  • Testing: Strategies for test databases, fixtures, and transaction rollbacks.
  • Common Patterns: Implement soft deletes, audit logs, and handle hierarchical data.

Quick Start

Use the database-workflow skill to learn about best practices for designing a relational database schema.

Frequently Asked Questions about database-workflow

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design a relational database schema using normalization?

Database schema design uses normalization principles like 1NF, 2NF, and 3NF to organize data efficiently and reduce redundancy. You should apply these forms sequentially to structure tables, establish relationships, and identify when denormalization is appropriate for performance.

What is the best way to manage database migrations and rollbacks?

Database migrations should be managed through version control with up and down scripts for every change. This approach ensures you can apply schema modifications predictably and execute rollback plans safely if errors occur during deployment.

How do I fix N+1 query problems in my ORM code?

Fixing N+1 query problems requires query optimization techniques like eager loading relationships and using EXPLAIN to analyze execution plans. You must identify inefficient ORM patterns and replace them with batched queries or proper joins.

When should I choose NoSQL over SQL for my database?

Choose NoSQL over SQL when your data structure is highly variable, requires horizontal scaling, or does not fit relational models. SQL is preferred for structured data requiring strict ACID compliance and complex relational queries.

What are the best practices for testing database logic and migrations?

Testing database logic involves using dedicated test databases, setting up fixtures, and leveraging transaction rollbacks to isolate tests. This ensures each test runs in a clean state without persisting mock data to your actual database.

Should I use Active Record or Data Mapper patterns in my ORM?

Active Record simplifies CRUD operations by embedding database logic in entities, while Data Mapper separates persistence from business logic. Choose Active Record for rapid development and Data Mapper for complex domain logic requiring loose coupling.