Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/cli-database-url-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"stash": patch
---

`stash eql install --help` and `stash eql repair --help` now say that
`--database-url` wins over a literal `databaseUrl` in `stash.config.ts`. That is
what both commands already do: `eql install --database-url` never loads the
config, and `eql repair` never reads it.

Before, both showed the help text the other database commands share. That text
says the config literal wins. The commands still behave as before. Only the
help changed.

`stash eql verify --help` no longer prints "Also settable via DATABASE_URL"
twice. The `eql install` and `eql verify` help now also says that
`DATABASE_URL` on its own does not skip the config the way the flag does.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Every command that takes `--database-url` must say, in its help, which value
* wins when stash.config.ts sets a literal `databaseUrl`: the flag or the
* config (#1980). The registry is plain data, so nothing else ties the help to
* what each command does.
*
* `flag` commands never load the config when the flag is given. `config`
* commands load stash.config.ts through `loadStashConfig`, and a literal
* `databaseUrl` there replaces the resolver that reads the flag.
*/

import { describe, expect, it } from 'vitest'
import { registry } from '@/cli/registry.js'

type Winner = 'flag' | 'config'

const WINNER: Record<string, Winner> = {
// main.ts passes `scaffoldConfig: 'skip'` with the flag, and
// `resolveInstallContext` then never looks for a config.
'eql install': 'flag',
// `resolveRepairDatabaseUrl` reads only the flag and DATABASE_URL.
'eql repair': 'flag',
// `resolveDiagnosticDatabaseUrl` with `flagWins: true`.
'eql verify': 'flag',
// `resolveDiagnosticDatabaseUrl` with `flagWins: false`.
Comment thread
auxesis marked this conversation as resolved.
Resolved
'eql preflight': 'config',
// These five call `loadStashConfig` directly.
'eql upgrade': 'config',
'eql status': 'config',
'eql validate': 'config',
'db test-connection': 'config',
'schema build': 'config',
}

const CONFIG_WINS =
'a hand-set literal databaseUrl in the config bypasses the resolver and wins over all of these'

const FLAG_WINS =
'The flag wins even when stash.config.ts sets a literal databaseUrl.'

const withFlag = registry
.flatMap((group) => group.commands)
.flatMap((command) => {
const flag = command.flags?.find((f) => f.name === '--database-url')
return flag ? [{ name: command.name, description: flag.description }] : []
})

describe('--database-url help', () => {
it('classifies every command that takes the flag', () => {
expect(withFlag.map((c) => c.name).sort()).toEqual(
Object.keys(WINNER).sort(),
)
})

it.each(withFlag)(
'$name states which value wins',
({ name, description }) => {
if (WINNER[name] === 'config') {
expect(description).toContain(CONFIG_WINS)
} else {
expect(description).not.toContain(CONFIG_WINS)
expect(description).toContain(FLAG_WINS)
}
},
)
})
26 changes: 18 additions & 8 deletions languages/typescript/packages/cli/src/cli/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ export interface CommandGroup {
}

/**
* Shared `--database-url` flag — every db/eql/schema command accepts it, so it's
* declared once and referenced, not copy-pasted.
* Shared `--database-url` flag, for the commands that load stash.config.ts
* through `loadStashConfig`, where a literal `databaseUrl` in the config wins
* over the flag. Commands where the flag wins (`eql install`, `eql repair`,
* `eql verify`) spread it and replace only the description.
* `cli/__tests__/database-url-help.test.ts` holds each command to the text that
* matches what it does.
*/
const DATABASE_URL_FLAG: Flag = {
name: '--database-url',
Expand Down Expand Up @@ -354,7 +358,11 @@ export const registry: CommandGroup[] = [
description:
'Use Supabase-compatible mode (auto-detected from DATABASE_URL).',
},
DATABASE_URL_FLAG,
{
...DATABASE_URL_FLAG,
description:
'One-shot: bypasses config loading entirely, so EQL is installed into the database you name and no stash.config.ts is scaffolded. The flag wins even when stash.config.ts sets a literal databaseUrl. Never written to disk. DATABASE_URL alone is not a one-shot: with no flag, install uses the databaseUrl of a stash.config.ts if it finds one, else DATABASE_URL env → supabase status → interactive prompt.',
},
],
},
{
Expand Down Expand Up @@ -396,11 +404,9 @@ export const registry: CommandGroup[] = [
'Emit the machine-readable verification report instead of the table.',
},
{
name: '--database-url',
value: '<url>',
...DATABASE_URL_FLAG,
description:
"One-shot, like `eql install`'s: bypasses config loading entirely, so the database you name is the database that gets judged. Also settable via DATABASE_URL.",
env: 'DATABASE_URL',
'One-shot: bypasses config loading entirely, so the database you name is the database that gets judged. The flag wins even when stash.config.ts sets a literal databaseUrl. DATABASE_URL alone is not a one-shot: with no flag, verify uses the databaseUrl of a stash.config.ts if it finds one, else the DATABASE_URL chain.',
},
],
},
Expand Down Expand Up @@ -507,7 +513,11 @@ export const registry: CommandGroup[] = [
"Drizzle's migration ledger, when drizzle.config.ts overrides `migrations.table` / `migrations.schema`. Defaults to `drizzle.__drizzle_migrations`. Only read with --database-url.",
},
DRY_RUN_FLAG,
DATABASE_URL_FLAG,
{
...DATABASE_URL_FLAG,
description:
'Database to check applied migrations against, for this run only — never written to disk. Repair never reads stash.config.ts. The flag wins even when stash.config.ts sets a literal databaseUrl. With no flag, repair uses DATABASE_URL, and the config cannot override that either. With neither, it skips the check and warns. It never runs supabase status or prompts.',
},
],
},
{
Expand Down
4 changes: 2 additions & 2 deletions skills/stash-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ First hit wins:
4. Interactive prompt — skipped under CI / non-TTY
5. Hard fail, naming the sources it tried

`stash.config.ts` is **not** a separate tier: the scaffolded config calls this same resolver, and the `--database-url` flag still wins. The one exception is a hand-edited config assigning a literal `databaseUrl` string — that bypasses the resolver entirely and beats both flag and env.
`stash.config.ts` is **not** a separate tier: the scaffolded config calls this same resolver, and the `--database-url` flag still wins. The one exception is a hand-edited config assigning a literal `databaseUrl` string — that bypasses the resolver entirely and beats both flag and env. Three commands work differently. `eql install` and `eql verify` skip the config when you pass `--database-url`, so the flag wins there. `eql repair` never reads the config, so the flag wins, and with no flag `DATABASE_URL` wins.

The resolved URL is returned in memory only. It is never written to disk or into `process.env`.

Expand Down Expand Up @@ -484,7 +484,7 @@ stash eql repair --drizzle --out db/migrations \
| `--drizzle` | Required. Repair a Drizzle migration directory. |
| `--out <path>` | Directory to sweep. Default `drizzle`; set it to match your `drizzle.config.ts`. |
| `--dry-run` | Report what would be rewritten without writing anything. |
| `--database-url <url>` | Check which migrations the database has already applied, and leave those alone. Also read from `DATABASE_URL`. |
| `--database-url <url>` | Check which migrations the database has already applied, and leave those alone. Also read from `DATABASE_URL`. Repair never reads `stash.config.ts`, so the flag wins even when the config sets a literal `databaseUrl`. |
| `--migrations-table <[schema.]table>` | Drizzle's migration ledger, when `drizzle.config.ts` overrides `migrations.table` / `migrations.schema`. Defaults to `drizzle.__drizzle_migrations`. Only read alongside `--database-url`. |

What it rewrites, what it refuses, and the schema reconciliation afterwards are identical to the `eql migration --drizzle` sweep above — both call the same rewriter and print the same report. It exits non-zero if any statement is left unrepaired.
Expand Down
Loading