-
Notifications
You must be signed in to change notification settings - Fork 5
feat(cli): add stash eql migration --drizzle (v3, migration-first EQL install)
#691
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
01d9381
feat(cli): add `stash eql migration --drizzle` (v3, migration-first E…
coderdan 201f7d8
fix(cli): harden `stash eql migration` per review (#691)
coderdan 6381171
fix(cli): bun exec must not surprise-download; drop type-erased test …
coderdan adf5243
docs(cli): correct stale `--prisma` copy now that prisma-next v3 has …
coderdan d1b306f
docs(cli): correct `--prisma` copy to match #690 (planned emitter, no…
coderdan 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| 'stash': minor | ||
| --- | ||
|
|
||
| Add `stash eql migration` — generate an EQL **v3** install migration for your ORM | ||
| instead of running the SQL directly against the database (`stash eql install`). | ||
| Migration-first is the preferred path: the install lands in your migration history | ||
| and ships to every environment through the ORM's own migrate step. | ||
|
|
||
| ```bash | ||
| stash eql migration --drizzle # Drizzle custom migration | ||
| stash eql migration --drizzle --supabase # also grants eql_v3 to anon/authenticated/service_role | ||
| ``` | ||
|
|
||
| The migration carries the CLI's bundled v3 install SQL (one source of truth) plus | ||
| the `cs_migrations` tracking schema, so a single `drizzle-kit migrate` covers | ||
| everything `stash encrypt …` needs. `--supabase` appends the `eql_v3` + | ||
| `eql_v3_internal` role grants for PostgREST/RLS access. | ||
|
|
||
| `--prisma` is registered but not available yet — the Prisma Next migration | ||
| emitter is a follow-up (tracked in cipherstash/stack#690) that will let | ||
| prisma-next drop its baked install baseline. It fails with a pointer for now. |
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
49 changes: 49 additions & 0 deletions
49
packages/cli/src/commands/db/__tests__/find-generated-migration.test.ts
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,49 @@ | ||
| import { mkdtempSync, rmSync, writeFileSync } from 'node:fs' | ||
| import { tmpdir } from 'node:os' | ||
| import { join } from 'node:path' | ||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest' | ||
| import { findGeneratedMigration } from '../install.js' | ||
|
|
||
| /** | ||
| * `findGeneratedMigration` was promoted to public API by the `eql migration` | ||
| * command and now has two consumers (`db install --drizzle` and | ||
| * `eql migration --drizzle`), so its branches are pinned directly — a change for | ||
| * one consumer must not silently break the other. | ||
| */ | ||
| describe('findGeneratedMigration', () => { | ||
| let dir: string | ||
| beforeEach(() => { | ||
| dir = mkdtempSync(join(tmpdir(), 'stash-find-migration-')) | ||
| }) | ||
| afterEach(() => { | ||
| rmSync(dir, { recursive: true, force: true }) | ||
| }) | ||
|
|
||
| it('throws when the out directory does not exist', async () => { | ||
| await expect( | ||
| findGeneratedMigration(join(dir, 'nope'), 'install-eql'), | ||
| ).rejects.toThrow(/output directory not found/) | ||
| }) | ||
|
|
||
| it('throws when no .sql file matches the migration name', async () => { | ||
| writeFileSync(join(dir, '0000_other.sql'), '') | ||
| await expect(findGeneratedMigration(dir, 'install-eql')).rejects.toThrow( | ||
| /Could not find a migration matching "install-eql"/, | ||
| ) | ||
| }) | ||
|
|
||
| it('returns the highest-numbered match, ignoring non-.sql and non-matching entries', async () => { | ||
| for (const f of [ | ||
| '0000_install-eql.sql', | ||
| '0010_install-eql.sql', | ||
| '0011_install-eql.txt', // not .sql | ||
| '0001_users.sql', // doesn't match the name | ||
| ]) { | ||
| writeFileSync(join(dir, f), '') | ||
| } | ||
| // Relies on drizzle-kit's zero-padded 4-digit prefix for lexical == numeric. | ||
| expect(await findGeneratedMigration(dir, 'install-eql')).toBe( | ||
| join(dir, '0010_install-eql.sql'), | ||
| ) | ||
| }) | ||
| }) |
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
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.