ci(den-db): automated Drizzle migrations for PlanetScale#2152
Open
benjaminshafii wants to merge 2 commits into
Open
ci(den-db): automated Drizzle migrations for PlanetScale#2152benjaminshafii wants to merge 2 commits into
benjaminshafii wants to merge 2 commits into
Conversation
- den-db-check.yml: PR gate that fails when the schema changes without a committed migration (db:generate must be a no-op) - den-db-migrate.yml: applies db:migrate to production PlanetScale when migration files land on dev; manual dispatch supports a one-time baseline (with dry-run) for the push-managed prod database - db:baseline script: records existing migrations as applied in __drizzle_migrations without executing them - drizzle.config.ts: enable TLS for the PlanetScale host/user/password credential path (required for MySQL-protocol connections from CI) - .env.example documents DATABASE_HOST/DATABASE_USERNAME/DATABASE_PASSWORD (same names as the GitHub Actions secrets) - README: CI workflow docs, baseline guide, expand/contract policy
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
2 issues found across 7 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="ee/packages/den-db/scripts/baseline-migrations.ts">
<violation number="1" location="ee/packages/den-db/scripts/baseline-migrations.ts:41">
P2: `--through` is not validated, so missing/empty values silently baseline through the latest migration.</violation>
</file>
<file name=".github/workflows/den-db-migrate.yml">
<violation number="1" location=".github/workflows/den-db-migrate.yml:90">
P2: `workflow_dispatch` input is directly interpolated in a `run` script, creating a shell-injection path for `baseline_through`.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| function parseArgs() { | ||
| const args = process.argv.slice(2) | ||
| const apply = args.includes("--yes") | ||
| const throughIndex = args.indexOf("--through") |
There was a problem hiding this comment.
P2: --through is not validated, so missing/empty values silently baseline through the latest migration.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At ee/packages/den-db/scripts/baseline-migrations.ts, line 41:
<comment>`--through` is not validated, so missing/empty values silently baseline through the latest migration.</comment>
<file context>
@@ -0,0 +1,143 @@
+function parseArgs() {
+ const args = process.argv.slice(2)
+ const apply = args.includes("--yes")
+ const throughIndex = args.indexOf("--through")
+ const through = throughIndex >= 0 ? args[throughIndex + 1] : undefined
+ return { apply, through }
</file context>
| set -euo pipefail | ||
| extra="" | ||
| if [ -n "${{ inputs.baseline_through }}" ]; then | ||
| extra="--through ${{ inputs.baseline_through }}" |
There was a problem hiding this comment.
P2: workflow_dispatch input is directly interpolated in a run script, creating a shell-injection path for baseline_through.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .github/workflows/den-db-migrate.yml, line 90:
<comment>`workflow_dispatch` input is directly interpolated in a `run` script, creating a shell-injection path for `baseline_through`.</comment>
<file context>
@@ -0,0 +1,104 @@
+ set -euo pipefail
+ extra=""
+ if [ -n "${{ inputs.baseline_through }}" ]; then
+ extra="--through ${{ inputs.baseline_through }}"
+ fi
+ if [ "${{ inputs.dry_run }}" = "true" ]; then
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Automated database migrations for the Den stack (PlanetScale prod). No telemetry/analytics changes in this PR — clean off
dev.New workflows
.github/workflows/den-db-check.yml— on every PR touchingee/packages/den-db/**: runsdb:generateand fails if it produces changes (schema edited without a committed migration). No secrets needed..github/workflows/den-db-migrate.yml— appliesdb:migrateto production:devwhenee/packages/den-db/drizzle/**changesworkflow_dispatch, withbaseline/baseline_through/dry_runinputsconcurrencygroup prevents overlapping runs; skipped on forksRequired GitHub Actions secrets (fill these in)
Same names as the local env vars in
ee/packages/den-db/.env.example:DATABASE_HOSTaws.connect.psdb.cloud)DATABASE_USERNAMEDATABASE_PASSWORDSupporting changes
db:baselinescript (ee/packages/den-db/scripts/baseline-migrations.ts): prod was historically managed withdb:push, so it has no__drizzle_migrationstable — the firstdb:migratewould replay all 20 migrations and fail. The baseline records existing migrations as applied without executing them (matches drizzle's exact tracking semantics: sha256 hash + journalwhentimestamp). Dry-run by default,--yesto write,--through <tag>to baseline partially.drizzle.config.ts: theDATABASE_HOST/USERNAME/PASSWORDcredential path now setsssl: { rejectUnauthorized: true }— PlanetScale requires TLS for MySQL-protocol connections, previously this path would fail from CI.Rollout (after merging)
baseline: true, dry_run: true→ check the printed plan (should list 0001–0020).baseline: true, dry_run: false→ records the baseline and runsdb:migrate(no-op).devapply automatically. (PR feat(den): analytics event model + /v1/telemetry/analytics endpoint (Layer 1+2) #2148's0021telemetry migration would be the first real consumer.)Tests
Commands run (all locally, since prod secrets are intentionally not mine to set):
pnpm --filter @openwork-ee/den-db db:generateon a clean tree → "No schema changes",git status --porcelain -- ee/packages/den-db/drizzleempty → check workflow logic verifiedopenwork_den, created viadb:push, no__drizzle_migrationstable — same state as prod):db:baseline(dry run) → printed plan listing all 20 migrationsdb:baseline -- --yes→ recorded 20 rows (count=20,max(created_at)=1780426749385= journalwhenof0020)db:migrate→ "migrations applied successfully" with nothing to replay ✓0001(ALTER TABLE worker ... doesn't exist) — confirms the chain has no0000baseline; documented in the README (fresh DBs usedb:push, existing DBs use baseline + migrate).Not tested (requires the PlanetScale secrets): the TLS connection from CI to PlanetScale itself. The
dry_rundispatch input exists exactly so the first prod run can be validated safely — happy to run it once the secrets are filled.No video: CLI/CI-only change; full command transcripts above reproduce everything.