---
template_id: dbdr
template_name: Database Decision Record
version: 1.0
variables:
  - name: number
    type: number
    required: true
    auto: next_dbdr_number
  - name: title
    type: string
    required: true
    prompt: "Title of the database decision:"
  - name: status
    type: choice
    required: true
    choices: [Proposed, Approved, Implemented, Rolled Back]
    default: Proposed
  - name: dbType
    type: choice
    required: true
    choices: [PostgreSQL, MySQL, MongoDB, SQLite, Supabase, Other]
    prompt: "Which database?"
  - name: owner
    type: string
    required: true
    prompt: "Who is the decision owner?"
  - name: context
    type: text
    required: true
    prompt: "What is the context and data problem?"
  - name: decision
    type: text
    required: true
    prompt: "What is the decision being made?"
  - name: migrationStrategy
    type: text
    required: true
    prompt: "What is the migration strategy?"
  - name: rollbackPlan
    type: text
    required: true
    prompt: "What is the rollback plan?"
---

# DBDR {{padNumber number 3}}: {{title}}

**Status:** {{status}}
**Date:** {{formatDate now "YYYY-MM-DD"}}
**Owner:** {{owner}}
**Database:** {{dbType}}

---

## Context

{{#if currentState}}
### Current State
{{currentState}}
{{/if}}

### Problem Statement
{{context}}

{{#if dataVolume}}
### Data Volume Considerations
- **Current Size:** {{dataVolume.current}}
- **Projected Growth:** {{dataVolume.projected}}
- **Retention Policy:** {{dataVolume.retention}}
{{/if}}

---

## Decision

{{decision}}

{{#if rationale}}
### Rationale
{{rationale}}
{{/if}}

---

## Schema Changes

{{#if schemaChanges}}
### Tables Affected

| Table | Change Type | Description |
|-------|-------------|-------------|
{{#each schemaChanges}}
| `{{this.table}}` | {{this.changeType}} | {{this.description}} |
{{/each}}

### SQL Migrations

```sql
{{#each schemaChanges}}
-- {{this.table}}: {{this.changeType}}
{{this.sql}}

{{/each}}
```
{{else}}
_No schema changes required._
{{/if}}

---

## Migration Strategy

### Approach
{{migrationStrategy}}

{{#if migrationPhases}}
### Phases

{{#each migrationPhases}}
1. **{{this.phase}}** ({{this.duration}})
   - {{this.description}}
   - Validation: {{this.validation}}
{{/each}}
{{/if}}

{{#if dataMigrationScripts}}
### Data Migration Scripts

```sql
{{dataMigrationScripts}}
```
{{/if}}

---

## Performance Impact

{{#if performanceMetrics}}
### Expected Impact

| Metric | Before | After | Acceptable? |
|--------|--------|-------|-------------|
{{#each performanceMetrics}}
| {{this.metric}} | {{this.before}} | {{this.after}} | {{this.acceptable}} |
{{/each}}
{{/if}}

{{#if indexes}}
### Indexing Strategy

{{#each indexes}}
- `{{this.name}}` on `{{this.table}}({{this.columns}})` - {{this.reason}}
{{/each}}
{{else}}
_No new indexes required._
{{/if}}

---

## Rollback Plan

### Rollback Strategy
{{rollbackPlan}}

{{#if rollbackScripts}}
### Rollback Scripts

```sql
{{rollbackScripts}}
```
{{/if}}

{{#if rollbackTriggers}}
### Rollback Triggers

{{#each rollbackTriggers}}
- **{{this.condition}}**: {{this.action}}
{{/each}}
{{/if}}

---

## Testing

{{#if preMigrationTests}}
### Pre-Migration Testing
{{#each preMigrationTests}}
- [ ] {{this}}
{{/each}}
{{/if}}

{{#if postMigrationValidation}}
### Post-Migration Validation
{{#each postMigrationValidation}}
- [ ] {{this}}
{{/each}}
{{/if}}

---

## Consequences

{{#if positiveConsequences}}
### Positive
{{#each positiveConsequences}}
- ✅ {{this}}
{{/each}}
{{/if}}

{{#if negativeConsequences}}
### Negative (Trade-offs)
{{#each negativeConsequences}}
- ⚠️ {{this}}
{{/each}}
{{else}}
_No significant trade-offs identified._
{{/if}}

---

## Related Decisions

{{#if relatedDBDRs}}
{{#each relatedDBDRs}}
- [DBDR {{this.number}}](./dbdr-{{padNumber this.number 3}}.md): {{this.title}}
{{/each}}
{{else}}
_No related decisions._
{{/if}}

{{#if relatedADRs}}
### Related ADRs
{{#each relatedADRs}}
- [ADR {{this.number}}](../adr/adr-{{padNumber this.number 3}}.md): {{this.title}}
{{/each}}
{{/if}}

---

**Generated by:** AIOX Template Engine v2.0
**Template Version:** dbdr-1.0
