| name | database-devops |
| description | Database design, migration, and DevOps automation with safety patterns. Use for schema design, migration planning, query optimization, multi-database orchestration, and Infrastructure-as-Code. Includes rollback strategies, performance analysis, and cross-database synchronization. |
| license | MIT |
Database & DevOps
Database lifecycle management with DevOps practices for safe schema evolution, query optimization, and multi-database orchestration.
When to Use
- Schema design - New database schema design and normalization
- Migration planning - Safe schema evolution with data transformations
- Query optimization - Index recommendations, query rewriting, performance tuning
- Multi-database orchestration - Cross-database transactions, data sync
- Infrastructure-as-Code - Terraform/Pulumi database provisioning
- Backup/Recovery - Automated backup strategies and disaster recovery
Core Workflow
Schema Design Phase
- Requirements gathering - Data entities, relationships, access patterns
- Conceptual design - ERD, entity relationships, cardinality
- Logical design - Table structures, column types, constraints
- Physical design - Indexing, partitioning, storage considerations
- Normalization review - 3NF/BCNF compliance vs. denormalization needs
Migration Planning Phase
- Analyze current schema - Existing tables, constraints, indexes
- Define target state - Desired schema changes
- Plan migration steps - Ordered, idempotent operations
- Assess data impact - Data transformations needed
- Design rollback - Reversible operations where possible
Execution Phase
- Test in staging - Run migrations against production-like data
- Backup data - Full backup before destructive changes
- Execute migration - Apply changes with monitoring
- Verify integrity - Check constraints, data consistency
- Update applications - Deploy code changes
Schema Design Patterns
Audit Trail
ALTER TABLE users ADD COLUMN created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
ALTER TABLE users ADD COLUMN updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
CREATE TRIGGER update_users_updated_at
BEFORE UPDATE ON users
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
Soft Delete
ALTER TABLE users ADD COLUMN deleted_at TIMESTAMP;
ALTER TABLE users ADD COLUMN is_deleted BOOLEAN DEFAULT FALSE;
SELECT * FROM users WHERE is_deleted = FALSE;
Multi-Tenancy
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
tenant_id INTEGER NOT NULL REFERENCES tenants(id),
);
CREATE INDEX idx_orders_tenant ON orders(tenant_id);
See references/schema-patterns.md for event sourcing, temporal tables, and more.
Migration Safety
Expand-Contract Pattern
ALTER TABLE users ADD COLUMN email_normalized VARCHAR(255);
UPDATE users SET email_normalized = LOWER(email) WHERE id BETWEEN 1 AND 1000;
ALTER TABLE users ALTER COLUMN email_normalized SET NOT NULL;
Online Schema Change
pt-online-schema-change \
--alter "ADD COLUMN email_normalized VARCHAR(255)" \
--execute \
D=mydb,t=users
See references/migration-patterns.md for gh-ost, batching strategies, and zero-downtime patterns.
Query Optimization
Indexing Strategy
CREATE INDEX idx_orders_user_date ON orders(user_id, created_at);
CREATE INDEX idx_active_users ON users(email) WHERE is_active = TRUE;
CREATE INDEX idx_email_lower ON users(LOWER(email));
Query Rewriting
SELECT orders.*, users.name
FROM orders
JOIN users ON orders.user_id = users.id
WHERE orders.user_id = 1;
See references/query-optimization.md for EXPLAIN analysis, covering indexes, and performance tuning.
Infrastructure-as-Code
Terraform Example
resource "aws_db_instance" "main" {
identifier = "myapp-db"
engine = "postgres"
engine_version = "15.4"
instance_class = "db.t3.micro"
allocated_storage = 20
backup_retention_period = 7
storage_encrypted = true
deletion_protection = true
}
See references/iac-examples.md for Pulumi, CloudFormation, and multi-cloud examples.
Backup and Recovery
Continuous Archiving
wal_level = replica
archive_mode = on
archive_command = 'cp %p /backup/wal/%f'
See references/backup-strategies.md for point-in-time recovery, automated backups, and disaster recovery procedures.
Quality Checklist
References
references/schema-patterns.md - Advanced schema design patterns
references/migration-patterns.md - Migration safety patterns
references/query-optimization.md - Performance tuning guide
references/iac-examples.md - Terraform/Pulumi examples
references/backup-strategies.md - Backup and recovery
Integration with other skills
- turso-db: Use
turso-db for Turso-specific SDKs, bidirectional sync patterns, and experimental features like MVCC, vector search, and encryption. Use database-devops for general schema design, migration safety, and Infrastructure-as-Code.