Skip to content

Commit 25f5d2c

Browse files
docs: add comprehensive deployment failure analysis
- Document launchql_migrate schema/table state differences between transaction and non-transaction modes - Explain rollback behavior with snapshot evidence - Highlight key discovery: failure events are not logged to migration tables - Provide recommendations for production use Co-Authored-By: Dan Lynch <[email protected]>
1 parent 8237d90 commit 25f5d2c

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

DEPLOYMENT_FAILURE_ANALYSIS.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Deployment Failure Analysis
2+
3+
## Overview
4+
5+
This document analyzes the behavior of LaunchQL's migration system when SQL changes fail during deployment, specifically examining the state of the `launchql_migrate` schema and tables.
6+
7+
## Key Findings
8+
9+
### Transaction Mode (Default: `useTransaction: true`)
10+
11+
When a deployment fails in transaction mode:
12+
13+
- **Complete Rollback**: All changes are automatically rolled back
14+
- **Database State**: Clean (as if deployment never happened)
15+
- **Migration Tracking**:
16+
- `launchql_migrate.changes`: 0 rows
17+
- `launchql_migrate.events`: 0 rows
18+
- **Behavior**: Entire deployment is wrapped in a single transaction
19+
20+
**Snapshot Evidence:**
21+
```json
22+
{
23+
"changeCount": 0,
24+
"changes": [],
25+
"eventCount": 0,
26+
"events": []
27+
}
28+
```
29+
30+
### Non-Transaction Mode (`useTransaction: false`)
31+
32+
When a deployment fails in non-transaction mode:
33+
34+
- **Partial Deployment**: Successful changes remain deployed
35+
- **Database State**: Mixed (successful changes persist)
36+
- **Migration Tracking**:
37+
- `launchql_migrate.changes`: Contains successful deployments
38+
- `launchql_migrate.events`: Contains `deploy` events for successful changes
39+
- **Behavior**: Each change deployed individually
40+
41+
**Snapshot Evidence:**
42+
```json
43+
{
44+
"changeCount": 2,
45+
"changes": [
46+
{
47+
"change_name": "create_table",
48+
"deployed_at": "2025-07-20T09:15:13.265Z",
49+
"project": "test-constraint-partial",
50+
"script_hash": "0624b3e2276299c8c3b8bfa514fe0d128906193769b3aeaea6732e71c0e352e6"
51+
},
52+
{
53+
"change_name": "add_record",
54+
"deployed_at": "2025-07-20T09:15:13.269Z",
55+
"project": "test-constraint-partial",
56+
"script_hash": "833d7d349e3c4f07e1a24ed40ac9814329efc87c180180342a09874f8124a037"
57+
}
58+
],
59+
"eventCount": 2,
60+
"events": [
61+
{
62+
"change_name": "create_table",
63+
"event_type": "deploy",
64+
"occurred_at": "2025-07-20T09:15:13.266Z",
65+
"project": "test-constraint-partial"
66+
},
67+
{
68+
"change_name": "add_record",
69+
"event_type": "deploy",
70+
"occurred_at": "2025-07-20T09:15:13.269Z",
71+
"project": "test-constraint-partial"
72+
}
73+
]
74+
}
75+
```
76+
77+
## Important Observations
78+
79+
### Failure Event Logging
80+
81+
**Critical Discovery**: Failure events are NOT logged to the `launchql_migrate.events` table. Only successful deployments create entries with `event_type: 'deploy'`.
82+
83+
- Failed deployments are logged to application logs but not persisted in the migration tracking tables
84+
- The `launchql_migrate.events` table only contains successful deployment records
85+
- This means you cannot query the migration tables to see deployment failure history
86+
87+
### Schema Structure
88+
89+
The `launchql_migrate.events` table supports failure tracking with:
90+
```sql
91+
event_type TEXT NOT NULL CHECK (event_type IN ('deploy', 'revert', 'fail'))
92+
```
93+
94+
However, in practice, only `'deploy'` events are currently being logged.
95+
96+
## Recommendations
97+
98+
### For Production Use
99+
100+
1. **Use Transaction Mode (Default)**: Provides automatic rollback and clean state on failure
101+
2. **Monitor Application Logs**: Failure details are logged but not persisted in migration tables
102+
3. **Manual Cleanup**: In non-transaction mode, failed deployments require manual cleanup of successful changes
103+
104+
### For Development/Testing
105+
106+
- Non-transaction mode can be useful for incremental rollout scenarios where partial success is acceptable
107+
- Always verify the state of `launchql_migrate.changes` after deployment failures
108+
109+
## Test Coverage
110+
111+
The deployment failure scenarios are tested in:
112+
- `packages/core/__tests__/projects/deploy-failure-scenarios.test.ts`
113+
- Snapshots: `packages/core/__tests__/projects/__snapshots__/deploy-failure-scenarios.test.ts.snap`
114+
115+
These tests demonstrate the exact database state differences between transaction and non-transaction failure modes using constraint violations as the failure mechanism.

0 commit comments

Comments
 (0)