跳到正文
cccskills
免费在 GitHub 公开

db-migrations

Generate Drizzle database migrations on a fresh Neon branch and review their production safety. Check table sizes, locking order, execution time, and data transfer needs, with load testing for changes affecting busy or large tables.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

Create a database migration with Drizzle on a fresh Neon branch, and check it is safe to run against production under load. Use when changing the packages/db schema, generating migrations, or reviewing one.

查看安装方法

适用场景

  • Generate migrations after changing a database schema
  • Review locking risks before production deployment
  • Rehearse large table changes under load
  • Check data backfills when switching read sources

包含的文件(1)

  • SKILL.md8.0 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

DB migrations

A migration that is correct on a quiet database can still take production down. On 17 September 2026 migration 0119 rewrote ingest.webhook_events (about 540 GB with indexes) while holding ACCESS EXCLUSIVE on the auth tables, and took the API down. Generate the migration with the steps below, then clear the safety checklist before opening the PR.

Generate

  1. Spin up a new Neon branch and point the root .env files at it. NEON_ORG_ID and NEON_PROJECT_ID are in .env; the Neon list_projects tool needs org_id passed in.
  2. Change the schema in packages/db/src/schema/.
  3. Run bunx drizzle-kit generate --name="<sample_name_snake_case>" from packages/db.
  4. Apply it to your dev branch only. Never apply against a shared or production database; those go through the deploy flow described under "What the production deploy does".

Never hand-edit packages/db/drizzle/ (.sql files, meta/_journal.json, snapshots) without explicit user confirmation. Change the schema and let drizzle-kit generate write the files. The one legitimate reason to ask for that confirmation is statement order (rule 3).

Safety checklist

  • Production sizes checked for every table the migration touches (query below)
  • No column type change on a large or busy table (rule 2)
  • Locks are taken child table first, then the tables it references (rule 3)
  • No long ACCESS EXCLUSIVE on a hot table (rule 4)
  • Every statement finishes well inside 60 seconds at production size
  • Rehearsed on a Neon branch of production under load, when the migration locks a hot table (rule 4) or rewrites or scans a large one. Otherwise the size and lock checks are enough
  • If reads move to a new table or column, the data moves in the same release (rule 5)
  • No tRPC input or output change in the same PR, so a bad API change can still be reverted (#7726; see .agents/skills/trpc-compat/SKILL.md)
  • After changing an already-pushed migration, the PR's preview Neon branch was deleted

Check production sizes first

Run this read-only against production, with the tables your migration touches:

begin transaction read only;
select c.oid::regclass as table_name,
       pg_size_pretty(pg_total_relation_size(c.oid)) as total_size,
       c.reltuples::bigint as approx_rows
from pg_class c
where c.oid in ('ingest.webhook_events'::regclass, 'automation_events'::regclass);
rollback;

Sizes on 2026-09-19, indexes included:

TableSizeRows
ingest.webhook_eventsabout 540 GB~199M
automation_eventsabout 245 GB~54M

Rules

1. All pending migrations run in ONE transaction

PgDialect.migrate in drizzle-orm 0.45.2 (pg-core/dialect.js) wraps the loop over every pending migration in a single session.transaction.

  • Splitting a change across several migration files gives no lock isolation.
  • Every lock an early statement takes is held until the last statement of the last file finishes.

2. Never change a column's type on a large, busy table in a normal migration

ALTER COLUMN ... SET DATA TYPE between types that are not binary-coercible rewrites the whole table and its indexes under ACCESS EXCLUSIVE. Enum to text on ingest.webhook_events was the outage.

Safe shapes:

  • For an enum, ALTER TYPE ... ADD VALUE.
  • Otherwise add a new column, backfill it in batches, and swap in a later release.

3. Take locks in the order the application does: child first, then its parents

An insert locks its own table, then takes RowShare on each foreign-key parent. DROP TABLE ... CASCADE, DROP CONSTRAINT and ADD CONSTRAINT ... FOREIGN KEY lock the referenced tables too. A migration that locks a parent before the child deadlocks against in-flight inserts.

  • The generated order of 0119 locked auth.organizations before automation_events and deadlocked 3 attempts out of 3 under load.
  • Hand-ordering the automation_events statement first fixed it (4 of 4).

drizzle-kit picks statement order, so this is the one legitimate reason to hand-order a generated file. Get explicit user confirmation first, and say why in a SQL comment above the moved statement, because regenerating restores the bad order. See packages/db/drizzle/0119_plugin_oauth_clients_and_connectors.sql for the pattern.

4. Know what is hot

TableWhy it is hot
auth.users, auth.organizationsRead by every authenticated request. ACCESS EXCLUSIVE for more than a moment is an outage.
automation_events, ingest.webhook_eventsHeld in a transaction almost continuously by the dispatch sweep (redispatchUndispatched) and the retention job (enforce-retention). A 5 second lock wait succeeded from about 44% of start times. A migration that needs their table lock should first wait on the job's own advisory lock (the singleFlight key), which lets the running batch finish without queueing inserts; 0122_webhook_events_swap_to_short_retention.sql is the pattern.

Because of rule 1, a statement queued behind a lock on automation_events keeps every lock the transaction already holds, including any on the auth tables.

5. Moving where data is READ from means moving the data in the same release

#7317 pointed every integration lookup at a new, empty connections table with no backfill. 2,393 live integrations read as disconnected until packages/trpc/scripts/backfill-connections.ts ran.

CI cannot catch this: unit tests mock the lookup layer (mock.module("@superset/trpc/connectors", ...)). Ship the backfill with the schema change.

Rehearse on a Neon branch of production, under load

A workspace's own Neon branch is a copy-on-write child of production at the same 0.25 to 2 CU size. A quiet rehearsal is not enough: the first one for 0119 passed in 2.3s and missed the deadlock entirely. pgbench found it immediately.

Rehearse when the migration locks a table in rule 4 or rewrites or scans a large table. A migration that only touches small tables that no job holds open does not need it: check the sizes, the lock order and the statement types, and say in the PR that you did not rehearse and why.

  1. Point at a production-child branch that does not have your migration yet. The workspace .env has two DATABASE_URL entries and the last one is the workspace branch.
  2. Write two pgbench scripts: reads on the parent tables your migration locks, and inserts into the child table.
  3. Start pgbench with both scripts (pgbench -n -f reads.sql -f inserts.sql -c <clients> -T <seconds>).
  4. While it runs, apply the migration with the production settings: PGOPTIONS="-c lock_timeout=5s -c statement_timeout=60s" bun drizzle-kit migrate.
  5. Repeat a few times. One pass proves little; 0119 was judged on 3 of 3 failures and 4 of 4 passes.

What the production deploy does

Job deploy-database in .github/workflows/deploy-production.yml:

  • A concurrency group, so two migration runs never overlap.
  • PGOPTIONS: -c lock_timeout=5s -c statement_timeout=60s.
  • Up to 8 attempts, retried only when the log contains "deadlock detected" or "lock timeout". Any other failure stops the deploy.
  • Then packages/db/src/verify-migrations-applied.ts, which fails unless the newest migration recorded in the database equals the newest journal entry.

A migration that needs longer than 60 seconds for one statement fails by design. Do that work online instead (rule 2).

A reused preview branch proves nothing

deploy-preview.yml names the Neon branch after the PR head ref and reuses it across pushes. Once the branch has applied a migration, later pushes that change that migration make the PR's database check a no-op. Delete the Neon branch to force a real run.

Workflow pitfalls from the same incident (pipefail, production secrets) are in docs/deploy-workflows.md.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

10x

免费

Review how you use Superset and identify unused features that fit your workflow. Get a short list of suggestions, learn about each option, and set up selected features such as scheduled agents, parallel workspaces, or shared tasks.

中文简介正在准备中。当前显示英语简介。

  • Find unused Superset features worth exploring
  • Set up scheduled agent tasks
  • Start parallel work in separate workspaces
superset-sh/superset1.5万2026年10月22日 更新

automate

免费

Set up recurring tasks in Superset with an agent prompt, a schedule or event trigger, and a chosen execution workspace. After explicit confirmation, create the automation, check its saved settings, and review a real first run.

中文简介正在准备中。当前显示英语简介。

  • Scheduling a daily or weekly agent task
  • Starting agent work when a GitHub pull request opens
  • Triggering tasks from selected Slack reactions
superset-sh/superset1.5万2026年10月22日 更新

browser

免费

Browse pages, click controls, fill fields, and inspect screenshots or console messages through Superset's browser pane. Use it to preview a running web app, check interface behavior, and work through browser tasks in a visible session.

中文简介正在准备中。当前显示英语简介。

  • Preview a locally running web app
  • Capture screenshots of a page
  • Inspect console errors
superset-sh/superset1.5万2026年10月22日 更新

Build Stripe payments, subscriptions, and invoicing using verified documentation and API parameter definitions. The skill guides product selection, sandbox testing, and webhook handling, where server notifications determine payment and subscription state.

中文简介正在准备中。当前显示英语简介。

  • Choose Stripe products for payments or recurring billing
  • Implement Checkout or invoice flows
  • Investigate Stripe code that compiles but behaves incorrectly
superset-sh/superset1.5万2026年10月22日 更新

Verify desktop UI changes through the Chrome DevTools Protocol, a connection for controlling the running app. Reproduce the user’s actual steps and compare screenshots, measured state, and console errors to establish evidence before and after a fix.

中文简介正在准备中。当前显示英语简介。

  • Reproducing reported bugs in the running app
  • Comparing UI behavior before and after a fix
  • Checking state across navigation and reopening
superset-sh/superset1.5万2026年10月22日 更新

ci-triage

免费

Diagnose failed GitHub Actions runs by finding the first meaningful error, separating code problems from infrastructure issues and intermittent failures, and comparing the base branch. Get a focused report explaining the PR’s involvement and recommended next steps.

中文简介正在准备中。当前显示英语简介。

  • Investigating failed PR checks
  • Separating intermittent test failures from code defects
  • Checking whether the base branch already fails
superset-sh/superset1.5万2026年10月22日 更新

查看 superset-sh 的全部技能

报告此技能的问题