Skip to content

Commit eb8194b

Browse files
committed
fix(cli): stop telling users to hand-edit .cipherstash/migrations.json
After `decrypt drop`, the skill, the drop's next steps and `encrypt status` told the user to remove the column's entry from .cipherstash/migrations.json by hand. The same skill says the CLI owns .cipherstash/ and hand-edits desync it, and no command performs the removal. The entry now stays: `encrypt status` shows it as `reversed`, which is its final state. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018TacM4u97tr5yPAFynxYXW
1 parent 2ab2b94 commit eb8194b

5 files changed

Lines changed: 12 additions & 26 deletions

File tree

‎languages/typescript/packages/cli/src/commands/decrypt/__tests__/decrypt-drop-plan.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ describe('decrypt drop', () => {
342342
)
343343
})
344344

345-
it('keeps the forward manifest entry until the migration is applied, and says to remove it then', async () => {
345+
it('keeps the forward manifest entry and never says to edit it by hand', async () => {
346346
migrateMocks.readManifest.mockResolvedValue({
347347
version: 1,
348348
tables: {
@@ -357,9 +357,9 @@ describe('decrypt drop', () => {
357357
const next = vi
358358
.mocked(p.note)
359359
.mock.calls.find(([, title]) => title === 'Next')?.[0]
360-
expect(next).toContain(
361-
'Remove the users.email entry from .cipherstash/migrations.json',
362-
)
360+
// The CLI owns .cipherstash/: the entry stays, and `encrypt status`
361+
// shows it as `reversed`. Nothing tells the user to edit the file.
362+
expect(next).not.toContain('migrations.json')
363363
expect(next).toContain(
364364
'Keep writing BOTH email_encrypted and email until it is applied',
365365
)

‎languages/typescript/packages/cli/src/commands/decrypt/drop.ts‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { detectPackageManager, runnerCommand } from '@/commands/init/utils.js'
2020
import { loadStashConfig } from '@/config/index.js'
2121
import { createPgClient } from '@/db/client.js'
2222
import {
23-
manifestPlaintextFor,
2423
recordedPlaintextColumn,
2524
resolveDecryptPair,
2625
} from './lib/resolve-pair.js'
@@ -192,13 +191,8 @@ export async function decryptDropCommand(options: DecryptDropOptions) {
192191
},
193192
})
194193

195-
// The forward manifest entry stays until the migration is APPLIED: this
196-
// file has not run, and its apply-time coverage check can still abort it.
197-
// `stash encrypt status` shows the entry as `reversed` meanwhile.
198-
const manifestColumn = await manifestPlaintextFor(
199-
options.table,
200-
options.column,
201-
)
194+
// The forward manifest entry stays: the CLI owns `.cipherstash/`, and
195+
// `stash encrypt status` shows the entry as `reversed`, its final state.
202196

203197
p.log.success(`Migration written to ${filePath}`)
204198
p.note(
@@ -211,11 +205,6 @@ export async function decryptDropCommand(options: DecryptDropOptions) {
211205
` - Drizzle: delete the ${options.column} column from the table definition. If the next \`drizzle-kit generate\` emits a DROP COLUMN for it, delete that statement — this migration already drops it.`,
212206
` - Prisma Next: remove the cipherstash.* field from the contract and re-emit it.`,
213207
` - Remove the table/column from your encryption client schema if nothing else on it is encrypted.`,
214-
...(manifestColumn !== undefined
215-
? [
216-
` - Remove the ${options.table}.${manifestColumn} entry from .cipherstash/migrations.json: it is no longer an encryption target.`,
217-
]
218-
: []),
219208
' - Then stop writing the encrypted column.',
220209
].join('\n'),
221210
'Next',

‎languages/typescript/packages/cli/src/commands/encrypt/__tests__/status-reversed.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ describe('encrypt status for a reversed column', () => {
109109
)
110110

111111
const row = await emailRow()
112-
expect(row).toContain('reversed (remove from migrations.json)')
112+
expect(row).toContain('reversed')
113+
expect(row).not.toContain('migrations.json')
113114
expect(row).not.toContain('encrypted-col-missing')
114115
})
115116
})

‎languages/typescript/packages/cli/src/commands/encrypt/status.ts‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ export async function statusCommand() {
7575
eqlVersion: column.eqlVersion,
7676
encryptedColumn: column.encryptedColumn,
7777
// `stash decrypt drop` records this against the ENCRYPTED
78-
// column; the manifest entry is the user's to remove once that
79-
// migration is applied.
78+
// column. The manifest entry stays, and `reversed` is its final
79+
// state: the CLI owns `.cipherstash/`.
8080
reversed:
8181
stateMap.get(`${tableName}.${encryptedName}`)?.phase ===
8282
'encrypted-dropped',
@@ -197,11 +197,7 @@ function renderRow(input: {
197197
// rename that creates `<col>_plaintext`.
198198
if (!isV3 && intentIndexes && !eqlColumn) flags.push('not-registered')
199199
if (intentIndexes && !physicalColumns.has(encryptedName)) {
200-
flags.push(
201-
input.reversed
202-
? 'reversed (remove from migrations.json)'
203-
: 'encrypted-col-missing',
204-
)
200+
flags.push(input.reversed ? 'reversed' : 'encrypted-col-missing')
205201
}
206202
if (
207203
!isV3 &&

‎skills/stash-cli/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ stash decrypt drop --table users --column email_encrypted --uninstall-eql
714714

715715
Runs from `decrypted`, against the plaintext twin the backfill **recorded** (a fully-populated but different column would make the coverage check pass vacuously). It verifies live coverage — no row with ciphertext set and plaintext NULL — then writes a migration that re-checks coverage at apply time under `ACCESS EXCLUSIVE`, **drops every index built on the encrypted column** (the EQL-term functional indexes; listed in the output), and drops the column, all in one `DO` block. Not applied for you; Drizzle projects get a journaled `drizzle-kit generate --custom` file.
716716

717-
Generating records `encrypted-dropped`, which stops a second drop being generated for the same column. It does not edit `.cipherstash/migrations.json`, because the migration has not run and its apply-time check can still abort it. After applying it, remove the column's entry from that file (the command's output names it); until then `encrypt status` shows the entry as `reversed` rather than as drift. If the apply-time check aborts, re-run `decrypt backfill`, then `decrypt drop` again. Keep dual-writing until the migration is applied.
717+
Generating records `encrypted-dropped`, which stops a second drop being generated for the same column. It leaves the column's entry in `.cipherstash/migrations.json`: `encrypt status` shows it as `reversed` rather than as drift, which is its final state. Do not edit the file by hand. If the apply-time check aborts, re-run `decrypt backfill`, then `decrypt drop` again. Keep dual-writing until the migration is applied.
718718

719719
`--uninstall-eql` appends the EQL v3 uninstall (`@cipherstash/eql`'s script: `DROP SCHEMA eql_v3, eql_v3_internal … CASCADE`) to the same block, plus the `public.eql_v3_*` column domains that script deliberately leaves behind (they live outside the disposable schemas so upgrades never touch encrypted columns). Only when this is the **last** EQL v3 column in the whole database — checked now and again at apply time, because the cascade would delete any other encrypted column. `cipherstash.cs_migrations` is kept.
720720

0 commit comments

Comments
 (0)