-
Notifications
You must be signed in to change notification settings - Fork 30
feat(migrations): Unify schema and data journals #896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
dcramer
wants to merge
8
commits into
main
Choose a base branch
from
codex/unified-migration-journals
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e63720b
feat(migrations): Unify schema and data journals
dcramer a85b6d4
fix(migrations): Embed durable migration implementations
dcramer 04f568c
ref(migrations): Inject the database adapter
dcramer f568497
ref(migrations): Add a versioned helper boundary
dcramer e763a82
ref(migrations): Reduce mixed journal bloat
dcramer c676c05
fix(migrations): Address adversarial review findings
dcramer 360518a
ref(migrations): Make bootstrap and plugin state explicit
dcramer 4ca01d1
fix(migrations): Preserve host state adapter identity
dcramer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # `@sentry/junior-migrations` | ||
|
|
||
| Junior's migration format extends a Drizzle Kit journal with TypeScript data | ||
| migrations. Every journal entry resolves to exactly one `<tag>.sql` or | ||
| `<tag>.ts` file. Drizzle Kit continues to own numbering and schema snapshots; | ||
| the Junior migration runner owns execution and exact per-entry tracking. | ||
|
|
||
| TypeScript migrations target a versioned capability API and must not import | ||
| Junior runtime internals. Migration-specific parsers and transforms belong | ||
| permanently in the migration file so application refactors or deletions cannot | ||
| break pending upgrades. | ||
|
|
||
| ## Authoring | ||
|
|
||
| Generate schema migrations with the owning package's normal Drizzle command. | ||
| Generate data migrations through this package's wrapper: | ||
|
|
||
| ```bash | ||
| junior-migrations generate \ | ||
| --config drizzle.config.ts \ | ||
| --out migrations \ | ||
| --name backfill_actor | ||
| ``` | ||
|
|
||
| The wrapper asks Drizzle Kit to create a custom journal entry, replaces the | ||
| empty SQL file with a `MigrationV1` TypeScript scaffold, and removes the | ||
| unchanged custom snapshot. Schema generation continues from the latest real | ||
| schema snapshot while preserving the mixed journal order. | ||
|
|
||
| ## Compatibility | ||
|
|
||
| Drizzle Kit remains the supported authoring tool. Drizzle ORM's stock | ||
| `migrate()` function is not a supported executor for mixed journals because it | ||
| requires every entry to have a SQL file. Call `runMigrationJournal` instead and | ||
| provide the host database adapter, state adapter, and TypeScript loader. The | ||
| same database adapter drives the journal ledger and is exposed as | ||
| `context.database`, so migration files never own connection or driver setup. | ||
|
|
||
| Normal upgrades run with `mode: "all"` and execute every SQL and TypeScript | ||
| entry in journal order. `mode: "schema-bootstrap"` is reserved for constructing | ||
| an empty database at the latest schema in tests or bootstrap tooling. It skips | ||
| TypeScript data migrations while executing SQL entries across the full journal, | ||
| so it must not be used to upgrade an existing installation. | ||
|
|
||
| The runner rejects runtime imports of application source, relative modules, | ||
| and unversioned `@sentry/junior` modules. Migrations may import the append-only | ||
| `@sentry/junior/migration-helpers/v1` surface for parsing primitives, adapters, | ||
| stores, and key resolution. One-off migration decisions and data transforms | ||
| must still remain in the journal entry. Add a new helper or capability version | ||
| rather than changing an existing contract. | ||
|
|
||
| This source validation is an authoring guard for trusted packaged migration | ||
| code, not a security sandbox for untrusted scripts. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| { | ||
| "name": "@sentry/junior-migrations", | ||
| "version": "0.104.2", | ||
| "private": false, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "type": "module", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/getsentry/junior.git", | ||
| "directory": "packages/junior-migrations" | ||
| }, | ||
| "bin": { | ||
| "junior-migrations": "dist/cli.js" | ||
| }, | ||
| "exports": { | ||
| ".": { | ||
| "types": "./src/index.ts", | ||
| "default": "./dist/index.js" | ||
| } | ||
| }, | ||
| "files": [ | ||
| "dist", | ||
| "src" | ||
| ], | ||
| "scripts": { | ||
| "build": "tsup && tsc -p tsconfig.build.json --emitDeclarationOnly", | ||
| "prepare": "pnpm run build", | ||
| "prepack": "pnpm run build", | ||
| "lint": "oxlint --config ../junior/.oxlintrc.json --deny-warnings src tests tsup.config.ts", | ||
| "test": "vitest run", | ||
| "typecheck": "tsc --noEmit" | ||
| }, | ||
| "peerDependencies": { | ||
| "drizzle-kit": "catalog:" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^25.9.1", | ||
| "drizzle-kit": "catalog:", | ||
| "drizzle-orm": "catalog:", | ||
| "oxlint": "^1.66.0", | ||
| "tsup": "^8.5.1", | ||
| "typescript": "^6.0.3", | ||
| "vitest": "^4.1.7" | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { parseArgs } from "node:util"; | ||
| import { generateTypeScriptMigration } from "./generate"; | ||
|
|
||
| const { positionals, values } = parseArgs({ | ||
| allowPositionals: true, | ||
| options: { | ||
| config: { type: "string" }, | ||
| name: { type: "string" }, | ||
| out: { type: "string", default: "./migrations" }, | ||
| }, | ||
| }); | ||
|
|
||
| if (positionals[0] !== "generate" || !values.config || !values.name) { | ||
| throw new Error( | ||
| "Usage: junior-migrations generate --config <path> --name <name> [--out <dir>]", | ||
| ); | ||
| } | ||
|
|
||
| const path = await generateTypeScriptMigration({ | ||
| configPath: values.config, | ||
| migrationsFolder: values.out, | ||
| name: values.name, | ||
| }); | ||
| console.log(`Created TypeScript migration ${path}`); |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.