Skip to content

Commit ca07522

Browse files
committed
Document non-transactional migrations
1 parent 02b551c commit ca07522

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

doc/concepts.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,23 @@ When creating migrations with dependencies:
112112

113113
## Transaction Behavior
114114

115-
- Each migration runs in its **own transaction**
115+
- Each migration runs in its **own transaction** by default
116116
- If a migration fails, the transaction **automatically rolls back**
117117
- The database remains in its **previous state**
118118
- **No partial applications** - migrations are all-or-nothing
119119

120+
### Non-Transactional Migrations
121+
122+
Some operations like `CREATE INDEX CONCURRENTLY` cannot run inside a transaction. Set `no_transaction: true` in `metadata.yaml` to opt out:
123+
124+
```yaml
125+
name: add_index_concurrently
126+
timestamp: 1679012345
127+
no_transaction: true
128+
```
129+
130+
> ⚠️ Non-transactional migrations have no automatic rollback on failure. See [Migration docs](/migration/#non-transactional-migrations) for details.
131+
120132
## Migration Tracking
121133
122134
Kat maintains a tracking table (default: `migrations`) with:

doc/migration.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ DROP TABLE IF EXISTS users;
149149
- **Keep migrations focused**: Each migration should have a single purpose
150150
- **Test migrations**: Verify both up and down migrations work as expected
151151

152+
### Non-Transactional Migrations
153+
154+
Some PostgreSQL operations, such as `CREATE INDEX CONCURRENTLY`, cannot run inside a transaction block. For these cases, you can set `no_transaction: true` in the migration's `metadata.yaml`:
155+
156+
```yaml
157+
name: add_orders_status_index
158+
timestamp: 1679012345
159+
no_transaction: true
160+
parents: [1679012340]
161+
```
162+
163+
When `no_transaction` is set, Kat executes the migration's SQL statements directly against the database without wrapping them in a `BEGIN`/`COMMIT` block.
164+
165+
> ⚠️ **Warning**: Non-transactional migrations cannot be automatically rolled back on failure. If a non-transactional migration fails partway through, the database may be left in a partially-migrated state. Keep these migrations small and focused on a single operation.
166+
152167
## Applying Migrations
153168

154169
To apply pending migrations, use the `up` command:

0 commit comments

Comments
 (0)