start-vibing-stacks 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +16 -2
- package/dist/migrate.d.ts +27 -0
- package/dist/migrate.js +217 -0
- package/dist/setup.js +10 -0
- package/package.json +1 -1
- package/stacks/_shared/agents/claude-md-compactor.md +1 -0
- package/stacks/_shared/agents/commit-manager.md +1 -0
- package/stacks/_shared/agents/documenter.md +1 -0
- package/stacks/_shared/agents/domain-updater.md +1 -0
- package/stacks/_shared/agents/research-web.md +1 -0
- package/stacks/_shared/agents/security-auditor.md +168 -0
- package/stacks/_shared/agents/tester.md +1 -0
- package/stacks/_shared/hooks/final-check.ts +205 -0
- package/stacks/_shared/hooks/stop-validator.ts +77 -1
- package/stacks/_shared/skills/accessibility-wcag22/SKILL.md +284 -0
- package/stacks/_shared/skills/ci-pipelines/SKILL.md +166 -0
- package/stacks/_shared/skills/codebase-knowledge/SKILL.md +5 -0
- package/stacks/_shared/skills/database-migrations/SKILL.md +256 -0
- package/stacks/_shared/skills/debugging-patterns/SKILL.md +5 -0
- package/stacks/_shared/skills/docker-patterns/SKILL.md +5 -0
- package/stacks/_shared/skills/docs-tracker/SKILL.md +5 -0
- package/stacks/_shared/skills/error-handling/SKILL.md +335 -0
- package/stacks/_shared/skills/final-check/SKILL.md +74 -37
- package/stacks/_shared/skills/git-workflow/SKILL.md +5 -0
- package/stacks/_shared/skills/hook-development/SKILL.md +5 -0
- package/stacks/_shared/skills/observability/SKILL.md +351 -0
- package/stacks/_shared/skills/performance-patterns/SKILL.md +5 -0
- package/stacks/_shared/skills/playwright-automation/SKILL.md +5 -0
- package/stacks/_shared/skills/quality-gate/SKILL.md +5 -0
- package/stacks/_shared/skills/research-cache/SKILL.md +5 -0
- package/stacks/_shared/skills/secrets-management/SKILL.md +245 -0
- package/stacks/_shared/skills/security-baseline/SKILL.md +202 -0
- package/stacks/_shared/skills/test-coverage/SKILL.md +5 -0
- package/stacks/_shared/skills/ui-ux-audit/SKILL.md +5 -0
- package/stacks/frontend/react/skills/preline-ui/SKILL.md +5 -0
- package/stacks/frontend/react/skills/react-patterns/SKILL.md +5 -0
- package/stacks/frontend/react/skills/react-standards/SKILL.md +5 -0
- package/stacks/frontend/react/skills/react-ui-patterns/SKILL.md +5 -0
- package/stacks/frontend/react/skills/shadcn-ui/SKILL.md +5 -0
- package/stacks/frontend/react/skills/tailwind-patterns/SKILL.md +5 -0
- package/stacks/frontend/react/skills/zod-validation/SKILL.md +5 -0
- package/stacks/frontend/react-inertia/skills/inertia-react/SKILL.md +5 -0
- package/stacks/frontend/react-inertia/skills/react-standards/SKILL.md +5 -0
- package/stacks/nodejs/skills/api-security-node/SKILL.md +275 -0
- package/stacks/nodejs/skills/bun-runtime/SKILL.md +5 -0
- package/stacks/nodejs/skills/mongoose-patterns/SKILL.md +5 -0
- package/stacks/nodejs/skills/nextjs-app-router/SKILL.md +5 -0
- package/stacks/nodejs/skills/trpc-api/SKILL.md +5 -0
- package/stacks/nodejs/skills/typescript-strict/SKILL.md +5 -0
- package/stacks/nodejs/stack.json +2 -1
- package/stacks/nodejs/workflows/ci.yml +90 -0
- package/stacks/nodejs/workflows/security.yml +45 -0
- package/stacks/php/skills/api-design/SKILL.md +5 -0
- package/stacks/php/skills/api-security/SKILL.md +5 -0
- package/stacks/php/skills/composer-workflow/SKILL.md +5 -0
- package/stacks/php/skills/external-api-patterns/SKILL.md +5 -0
- package/stacks/php/skills/inertia-react/SKILL.md +5 -0
- package/stacks/php/skills/laravel-inertia-i18n/SKILL.md +5 -0
- package/stacks/php/skills/laravel-octane/SKILL.md +5 -0
- package/stacks/php/skills/laravel-patterns/SKILL.md +5 -0
- package/stacks/php/skills/mariadb-octane/SKILL.md +5 -0
- package/stacks/php/skills/php-patterns/SKILL.md +5 -0
- package/stacks/php/skills/phpstan-analysis/SKILL.md +5 -0
- package/stacks/php/skills/phpunit-testing/SKILL.md +5 -0
- package/stacks/php/skills/security-scan-php/SKILL.md +5 -0
- package/stacks/php/workflows/ci.yml +106 -0
- package/stacks/php/workflows/security.yml +36 -0
- package/stacks/python/skills/api-security-python/SKILL.md +312 -0
- package/stacks/python/skills/async-patterns/SKILL.md +5 -0
- package/stacks/python/skills/django-patterns/SKILL.md +5 -0
- package/stacks/python/skills/fastapi-patterns/SKILL.md +5 -0
- package/stacks/python/skills/pydantic-validation/SKILL.md +5 -0
- package/stacks/python/skills/pytest-testing/SKILL.md +5 -0
- package/stacks/python/skills/python-patterns/SKILL.md +5 -0
- package/stacks/python/skills/python-performance/SKILL.md +5 -0
- package/stacks/python/skills/scripting-automation/SKILL.md +5 -0
- package/stacks/python/stack.json +2 -1
- package/stacks/python/workflows/ci.yml +76 -0
- package/stacks/python/workflows/security.yml +56 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ci-pipelines
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
description: GitHub Actions pipelines for typecheck, lint, test, security scan, build, and release. Stack-aware templates live in stacks/<stack>/workflows/.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# CI Pipelines
|
|
8
|
+
|
|
9
|
+
**ALWAYS invoke when setting up CI, modifying `.github/workflows/`, or wiring quality gates.**
|
|
10
|
+
|
|
11
|
+
> CI is the only enforcement that survives human pressure. Anything not in CI will eventually be skipped.
|
|
12
|
+
|
|
13
|
+
## Pipeline Stages (Required Order)
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
1. checkout + setup
|
|
17
|
+
2. install deps (cache locked)
|
|
18
|
+
3. typecheck / static analysis — fail fast, cheapest
|
|
19
|
+
4. lint
|
|
20
|
+
5. unit tests
|
|
21
|
+
6. integration tests (with services)
|
|
22
|
+
7. security audit (npm/pip/composer audit + gitleaks)
|
|
23
|
+
8. build
|
|
24
|
+
9. e2e (only on main / PRs to main)
|
|
25
|
+
10. publish artifacts (only on tag)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Order matters**: cheaper gates first. A typo found by typecheck in 30s saves 10 minutes of e2e runtime.
|
|
29
|
+
|
|
30
|
+
## Required Workflows per Repo
|
|
31
|
+
|
|
32
|
+
| File | Triggers | Purpose |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| `ci.yml` | `pull_request`, `push` to main | Main pipeline |
|
|
35
|
+
| `security.yml` | weekly cron + push | Audits, gitleaks, CodeQL |
|
|
36
|
+
| `release.yml` | `release: published` | Publish to npm / PyPI / Docker / etc. |
|
|
37
|
+
|
|
38
|
+
## Universal Best Practices
|
|
39
|
+
|
|
40
|
+
### Concurrency (cancel stale runs)
|
|
41
|
+
```yaml
|
|
42
|
+
concurrency:
|
|
43
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
44
|
+
cancel-in-progress: true
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Permissions (least privilege)
|
|
48
|
+
```yaml
|
|
49
|
+
permissions:
|
|
50
|
+
contents: read # default; bump only what each job needs
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Bump per job:
|
|
54
|
+
```yaml
|
|
55
|
+
jobs:
|
|
56
|
+
release:
|
|
57
|
+
permissions:
|
|
58
|
+
contents: write # to create tags
|
|
59
|
+
id-token: write # to use OIDC for npm provenance
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Pin actions by SHA in production
|
|
63
|
+
```yaml
|
|
64
|
+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`Dependabot` will keep them updated. Tags can be re-pointed; SHAs cannot.
|
|
68
|
+
|
|
69
|
+
### Secrets
|
|
70
|
+
|
|
71
|
+
- Never `echo "$SECRET"` — masking is best-effort.
|
|
72
|
+
- Pass to runtime via env, not CLI args (CLI shows in logs on some setups).
|
|
73
|
+
- Use **OIDC** for cloud deploys (AWS / GCP / Vercel) — no long-lived keys in repo secrets.
|
|
74
|
+
|
|
75
|
+
### Caching
|
|
76
|
+
|
|
77
|
+
| Stack | Cache key |
|
|
78
|
+
|---|---|
|
|
79
|
+
| Node.js | `package-lock.json` / `bun.lock` / `pnpm-lock.yaml` |
|
|
80
|
+
| Python | `requirements*.txt` / `uv.lock` / `poetry.lock` |
|
|
81
|
+
| PHP | `composer.lock` |
|
|
82
|
+
|
|
83
|
+
`actions/setup-node` / `setup-python` provide `cache:` parameter — use it.
|
|
84
|
+
|
|
85
|
+
### Matrix builds for multi-version coverage
|
|
86
|
+
```yaml
|
|
87
|
+
strategy:
|
|
88
|
+
matrix:
|
|
89
|
+
node: [20, 22]
|
|
90
|
+
fail-fast: false # see all failures, don't bail on first
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Branch Protection (mandatory)
|
|
94
|
+
|
|
95
|
+
Configure on GitHub: Settings → Branches → main:
|
|
96
|
+
- Require PRs (no direct push to main)
|
|
97
|
+
- Require status checks: `ci / typecheck`, `ci / test`, `ci / security`
|
|
98
|
+
- Require linear history (no merge commits, only squash/rebase)
|
|
99
|
+
- Require signed commits (optional but recommended)
|
|
100
|
+
- Require up-to-date branch before merge
|
|
101
|
+
|
|
102
|
+
## Templates Per Stack
|
|
103
|
+
|
|
104
|
+
Templates ship in `stacks/<stack>/workflows/`. Run `npx start-vibing` (or copy manually) to install them into the project's `.github/workflows/`.
|
|
105
|
+
|
|
106
|
+
| Stack | Template files |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `nodejs` | `ci.yml`, `security.yml` |
|
|
109
|
+
| `python` | `ci.yml`, `security.yml` |
|
|
110
|
+
| `php` | `ci.yml`, `security.yml` |
|
|
111
|
+
|
|
112
|
+
## Release / Publish
|
|
113
|
+
|
|
114
|
+
For npm packages:
|
|
115
|
+
```yaml
|
|
116
|
+
# .github/workflows/release.yml
|
|
117
|
+
on:
|
|
118
|
+
release:
|
|
119
|
+
types: [published]
|
|
120
|
+
permissions:
|
|
121
|
+
contents: read
|
|
122
|
+
id-token: write # OIDC for provenance
|
|
123
|
+
jobs:
|
|
124
|
+
publish:
|
|
125
|
+
runs-on: ubuntu-latest
|
|
126
|
+
steps:
|
|
127
|
+
- uses: actions/checkout@v4
|
|
128
|
+
- uses: actions/setup-node@v4
|
|
129
|
+
with:
|
|
130
|
+
node-version: 20
|
|
131
|
+
registry-url: https://registry.npmjs.org
|
|
132
|
+
- run: npm ci
|
|
133
|
+
- run: npm run build
|
|
134
|
+
- run: npm publish --access public --provenance
|
|
135
|
+
env:
|
|
136
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`--provenance` is the 2024+ default — gives users SLSA-attested supply chain.
|
|
140
|
+
|
|
141
|
+
## Pre-Commit Checklist for CI Changes
|
|
142
|
+
|
|
143
|
+
- [ ] `concurrency` group set
|
|
144
|
+
- [ ] `permissions: contents: read` at top, bump per job
|
|
145
|
+
- [ ] Secrets via `${{ secrets.X }}`, never inline
|
|
146
|
+
- [ ] Actions pinned by SHA (or at least major+minor for non-critical)
|
|
147
|
+
- [ ] Quality gates ordered cheapest → most expensive
|
|
148
|
+
- [ ] Caching configured for the package manager
|
|
149
|
+
- [ ] Branch protection rules applied to main on GitHub
|
|
150
|
+
|
|
151
|
+
## FORBIDDEN
|
|
152
|
+
|
|
153
|
+
| Pattern | Reason |
|
|
154
|
+
|---|---|
|
|
155
|
+
| `if: always()` on the final reporter that swallows failures | CI green when tests fail |
|
|
156
|
+
| `continue-on-error: true` outside of allowed-fail matrix | Hides regressions |
|
|
157
|
+
| `--no-verify` in CI git operations | Bypasses other guardrails |
|
|
158
|
+
| Plain text secrets in env files committed to repo | See `secrets-management` |
|
|
159
|
+
| Workflow with `permissions: write-all` | Overly broad, supply chain risk |
|
|
160
|
+
| Long-lived cloud creds in repo secrets | Use OIDC instead |
|
|
161
|
+
|
|
162
|
+
## See Also
|
|
163
|
+
|
|
164
|
+
- `secrets-management` — repo secrets & OIDC patterns
|
|
165
|
+
- `quality-gate` — local quality gates that mirror CI
|
|
166
|
+
- `git-workflow` — branch + commit conventions CI relies on
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: database-migrations
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
description: Safe database migrations under load — backfills, concurrent indexes, lock timeouts, parallel-change pattern, rollback strategy. Invoke before writing or running any schema migration.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Database Migrations — Safety Patterns
|
|
8
|
+
|
|
9
|
+
**ALWAYS invoke before writing or executing a schema migration on any environment with data.**
|
|
10
|
+
|
|
11
|
+
> A migration that locks the table for 90 seconds at 1k writes/sec creates a 90,000-request outage. The only safe migration is one that ships in pieces.
|
|
12
|
+
|
|
13
|
+
## The Cardinal Rule: Parallel Change
|
|
14
|
+
|
|
15
|
+
For any non-trivial schema change, deploy in **at least two releases**:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
Release N → expand: add new column/table, dual-write, leave old
|
|
19
|
+
Release N+1 → migrate: backfill data
|
|
20
|
+
Release N+2 → contract: drop old, switch reads
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Never combine expand + contract in one deploy. You will regret it the moment you need to roll back.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 1. Adding a Column
|
|
28
|
+
|
|
29
|
+
### NOT NULL with default
|
|
30
|
+
|
|
31
|
+
PostgreSQL ≥ 11 / MySQL 8 / MariaDB 10.5+: `ADD COLUMN ... NOT NULL DEFAULT ...` is fast (metadata-only). On older versions or other engines, it rewrites the whole table.
|
|
32
|
+
|
|
33
|
+
**Safe pattern (works on any version):**
|
|
34
|
+
```sql
|
|
35
|
+
-- Step 1 (release N): nullable, no default → instant
|
|
36
|
+
ALTER TABLE users ADD COLUMN plan VARCHAR(20);
|
|
37
|
+
|
|
38
|
+
-- Step 2 (release N): app dual-writes — sets plan on every INSERT/UPDATE
|
|
39
|
+
-- Step 3 (release N+1): backfill in chunks (see §3)
|
|
40
|
+
-- Step 4 (release N+2): set NOT NULL + default
|
|
41
|
+
ALTER TABLE users ALTER COLUMN plan SET NOT NULL;
|
|
42
|
+
ALTER TABLE users ALTER COLUMN plan SET DEFAULT 'free';
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Generated columns
|
|
46
|
+
Prefer over backfilling derived data when possible — DB keeps it consistent.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 2. Adding an Index
|
|
51
|
+
|
|
52
|
+
Indexes lock the table during build on most engines.
|
|
53
|
+
|
|
54
|
+
### PostgreSQL
|
|
55
|
+
```sql
|
|
56
|
+
-- WRONG — exclusive lock for the duration
|
|
57
|
+
CREATE INDEX idx_users_email ON users(email);
|
|
58
|
+
|
|
59
|
+
-- CORRECT — non-blocking
|
|
60
|
+
CREATE INDEX CONCURRENTLY idx_users_email ON users(email);
|
|
61
|
+
-- Caveats: cannot run inside a transaction; on failure leaves invalid index — drop with `DROP INDEX CONCURRENTLY`
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### MySQL / MariaDB
|
|
65
|
+
InnoDB ≥ 5.6 supports `ALGORITHM=INPLACE, LOCK=NONE` for most index types:
|
|
66
|
+
```sql
|
|
67
|
+
ALTER TABLE users ADD INDEX idx_email (email), ALGORITHM=INPLACE, LOCK=NONE;
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
If `LOCK=NONE` fails, the engine tells you why (e.g. fulltext, spatial). Don't override — the lock is real.
|
|
71
|
+
|
|
72
|
+
### MongoDB
|
|
73
|
+
```js
|
|
74
|
+
db.users.createIndex({ email: 1 }, { background: true }) // 4.2 default; deprecated in 6+ where it's always non-blocking
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Tooling
|
|
78
|
+
- **Postgres**: `pg_repack` for table-rewrite migrations without long locks
|
|
79
|
+
- **MySQL**: `pt-online-schema-change` (Percona) or `gh-ost` (GitHub) — both work via shadow tables + triggers
|
|
80
|
+
- **Mongo**: rolling builds across replica set members
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 3. Backfilling — Chunked
|
|
85
|
+
|
|
86
|
+
Single `UPDATE` over millions of rows = long transaction = long lock = replication lag = page.
|
|
87
|
+
|
|
88
|
+
### SQL (chunked, app-driven)
|
|
89
|
+
```sql
|
|
90
|
+
-- pseudo: loop in app code
|
|
91
|
+
UPDATE users
|
|
92
|
+
SET plan = COALESCE(plan, 'free')
|
|
93
|
+
WHERE id BETWEEN :start AND :end
|
|
94
|
+
AND plan IS NULL;
|
|
95
|
+
-- Sleep 50ms between batches; chunk size 1k–10k rows
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Laravel
|
|
99
|
+
```php
|
|
100
|
+
User::whereNull('plan')->chunkById(1000, function ($users) {
|
|
101
|
+
foreach ($users as $user) {
|
|
102
|
+
$user->update(['plan' => 'free']);
|
|
103
|
+
}
|
|
104
|
+
usleep(50_000); // 50ms breathing room
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Mongoose
|
|
109
|
+
```ts
|
|
110
|
+
const cursor = User.find({ plan: { $exists: false } }).cursor();
|
|
111
|
+
for await (const user of cursor) {
|
|
112
|
+
await User.updateOne({ _id: user._id }, { $set: { plan: 'free' } });
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Django
|
|
117
|
+
Use `RunPython` migration with `atomic=False` and chunk:
|
|
118
|
+
```python
|
|
119
|
+
class Migration(migrations.Migration):
|
|
120
|
+
atomic = False
|
|
121
|
+
operations = [migrations.RunPython(backfill, reverse_code=migrations.RunPython.noop)]
|
|
122
|
+
|
|
123
|
+
def backfill(apps, schema_editor):
|
|
124
|
+
User = apps.get_model("app", "User")
|
|
125
|
+
qs = User.objects.filter(plan__isnull=True).only("id")
|
|
126
|
+
for batch in chunked(qs.iterator(), 1000):
|
|
127
|
+
User.objects.filter(id__in=[u.id for u in batch]).update(plan="free")
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## 4. Lock Timeouts (Critical)
|
|
133
|
+
|
|
134
|
+
Set a short timeout so a stuck migration fails fast instead of blocking the app:
|
|
135
|
+
|
|
136
|
+
```sql
|
|
137
|
+
-- Postgres
|
|
138
|
+
SET LOCAL lock_timeout = '5s';
|
|
139
|
+
SET LOCAL statement_timeout = '15s';
|
|
140
|
+
ALTER TABLE users ADD COLUMN x INT;
|
|
141
|
+
|
|
142
|
+
-- MySQL / MariaDB
|
|
143
|
+
SET SESSION lock_wait_timeout = 5;
|
|
144
|
+
SET SESSION innodb_lock_wait_timeout = 5;
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Without this, an `ALTER` waiting for a long-running `SELECT` will block every subsequent write behind it (Postgres queue).
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## 5. Renaming — Never Direct in Prod
|
|
152
|
+
|
|
153
|
+
Never `ALTER TABLE users RENAME COLUMN email TO email_address` in a single deploy. The old code on the previous release will break.
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
Release N: add new column, dual-write
|
|
157
|
+
Release N+1: backfill, switch reads to new column
|
|
158
|
+
Release N+2: drop old column
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Same for table renames, type changes (often disguised renames + casts), enum value removal.
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## 6. Foreign Keys
|
|
166
|
+
|
|
167
|
+
Adding a FK validates every existing row. On large tables this locks.
|
|
168
|
+
|
|
169
|
+
### Postgres
|
|
170
|
+
```sql
|
|
171
|
+
-- Two-step
|
|
172
|
+
ALTER TABLE orders ADD CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) NOT VALID; -- fast
|
|
173
|
+
-- Validate when load is low; takes only SHARE UPDATE EXCLUSIVE lock
|
|
174
|
+
ALTER TABLE orders VALIDATE CONSTRAINT fk_user;
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### MySQL — no equivalent; use offline tooling (`gh-ost`).
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## 7. Dropping — Always Soft First
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
Release N: stop writing to column (deploy)
|
|
185
|
+
Release N+1: stop reading from column (deploy) ← observe metrics
|
|
186
|
+
Release N+2: drop column
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Add a feature flag for the new code path so you can roll back without a schema change.
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## 8. Migration Tooling Per Stack
|
|
194
|
+
|
|
195
|
+
| Stack | Tool | Notes |
|
|
196
|
+
|---|---|---|
|
|
197
|
+
| Node + SQL | Drizzle / Kysely / Knex / TypeORM | Drizzle is the modern choice; uses `meta` snapshots |
|
|
198
|
+
| Node + Mongo | Mongoose schema versioning | No DDL — but evolve with backfills |
|
|
199
|
+
| Python + SQL | Alembic (SQLAlchemy), Django migrations | |
|
|
200
|
+
| PHP | Laravel migrations + `doctrine/dbal` for DDL | |
|
|
201
|
+
|
|
202
|
+
Rules regardless of tool:
|
|
203
|
+
- Migration files are **append-only** once merged. Edit = rewrite history = production drift.
|
|
204
|
+
- Each migration has both `up` and `down` (or a documented "no rollback" reason).
|
|
205
|
+
- Migrations run idempotently (safe to re-run).
|
|
206
|
+
- Never include data migrations in schema migrations on huge tables — separate scripts.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## 9. Rollback Strategy
|
|
211
|
+
|
|
212
|
+
For every migration ask: **"How do I undo this in 5 minutes if prod breaks?"**
|
|
213
|
+
|
|
214
|
+
| Operation | Rollback |
|
|
215
|
+
|---|---|
|
|
216
|
+
| Add nullable column | `DROP COLUMN` (instant) |
|
|
217
|
+
| Add NOT NULL column with default | `DROP COLUMN` |
|
|
218
|
+
| Add index | `DROP INDEX [CONCURRENTLY]` |
|
|
219
|
+
| Rename column | None — that's why parallel change |
|
|
220
|
+
| Drop column | Restore from backup. **Don't.** |
|
|
221
|
+
| Backfill | Run inverse update OR accept the data is now correct |
|
|
222
|
+
|
|
223
|
+
If you can't write a 5-minute rollback, the migration is too risky for one release. Split it.
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## 10. Pre-Deploy Checklist
|
|
228
|
+
|
|
229
|
+
- [ ] Migration runs in < 5s OR is concurrent / non-blocking
|
|
230
|
+
- [ ] Lock + statement timeouts set
|
|
231
|
+
- [ ] Tested on a copy of prod-sized data (or a representative subset)
|
|
232
|
+
- [ ] Backfills are chunked with breathing room
|
|
233
|
+
- [ ] No combined expand + contract in same deploy
|
|
234
|
+
- [ ] App code on previous release survives if migration runs first
|
|
235
|
+
- [ ] App code on next release survives if migration is delayed
|
|
236
|
+
- [ ] Rollback plan written (or "no rollback" justified)
|
|
237
|
+
- [ ] DBA / on-call notified for high-risk migrations
|
|
238
|
+
|
|
239
|
+
## FORBIDDEN
|
|
240
|
+
|
|
241
|
+
| Pattern | Reason |
|
|
242
|
+
|---|---|
|
|
243
|
+
| `ALTER TABLE` without lock timeout in prod | Single bad query = full outage |
|
|
244
|
+
| `CREATE INDEX` without `CONCURRENTLY` (Postgres) | Locks writes |
|
|
245
|
+
| Renaming a column in one deploy | Breaks rolling deploys |
|
|
246
|
+
| Single huge `UPDATE` | Replication lag, locks, redo bloat |
|
|
247
|
+
| Editing a merged migration file | Prod drift, dev/prod mismatch |
|
|
248
|
+
| Dropping a column without two prior soft-delete deploys | No rollback |
|
|
249
|
+
| Migrations running automatically on every deploy without gates | Surprise outage |
|
|
250
|
+
| Mixing schema and data migrations on hot tables | Single-tx behavior unpredictable |
|
|
251
|
+
|
|
252
|
+
## See Also
|
|
253
|
+
|
|
254
|
+
- `observability` — track migration duration and lag during runs
|
|
255
|
+
- `error-handling` — service-side feature flags for parallel change
|
|
256
|
+
- `ci-pipelines` — gate migrations behind manual approval for production
|