diff --git a/.changeset/cli-preflight-ore-wording.md b/.changeset/cli-preflight-ore-wording.md new file mode 100644 index 0000000000..1e64080131 --- /dev/null +++ b/.changeset/cli-preflight-ore-wording.md @@ -0,0 +1,15 @@ +--- +"stash": patch +--- + +`stash eql preflight` now describes the ORE operator class check in words that +apply to every SDK and every EQL version. When the role cannot create the +class, the output names types by suffix: OPE-ordered types (`*Ord`) and +ORE types (`*OrdOre`, `*SearchOre`). The output no longer names the +TypeScript `types.*` factories or the EQL v3 domains. `stash eql install`, +`stash eql status`, and `stash eql verify` print the same remedy sentence, so +it changes there too. + +Where EQL is already installed, preflight no longer predicts a fallback that +`stash eql install` would not install, and points at `stash eql status` +instead. The row values, exit codes, and `--json` output are unchanged. diff --git a/languages/typescript/packages/cli/src/commands/db/__tests__/preflight.test.ts b/languages/typescript/packages/cli/src/commands/db/__tests__/preflight.test.ts index dbdf788557..c77a17e23e 100644 --- a/languages/typescript/packages/cli/src/commands/db/__tests__/preflight.test.ts +++ b/languages/typescript/packages/cli/src/commands/db/__tests__/preflight.test.ts @@ -1,6 +1,10 @@ import { describe, expect, it } from 'vitest' import type { PreflightResult } from '@/installer/index.js' -import { renderPreflightReport } from '../preflight.js' +import { ORE_FALLBACK_REMEDY } from '@/installer/ore.js' +import { + renderOreOperatorClassNote, + renderPreflightReport, +} from '../preflight.js' const CAPABLE: PreflightResult = { currentUser: 'postgres', @@ -90,15 +94,25 @@ describe('renderPreflightReport', () => { canCreateOperatorClass: false, }) expect(report).toMatch(/ORE operator class\s+not creatable/) - expect(report).toContain('<- skips: ORE opclass') - expect(report).toContain('`types.*Ord`, not `types.*OrdOre`') + expect(report).toContain('<- skips: ORE operator class') + expect(report).toContain( + 'use OPE-ordered types (`*Ord`), not ORE types (`*OrdOre`, `*SearchOre`)', + ) + // The row is read by users of every SDK and every EQL version, so it + // names no TypeScript API and no EQL version (#1904). + const oreRow = report + .split('\n') + .find((line) => line.startsWith('ORE operator class')) + expect(oreRow).toBeDefined() + expect(oreRow).not.toContain('types.') + expect(oreRow).not.toMatch(/eql_v\d/) expect(report).not.toContain('<- blocks') }) it('leaves the ORE row unannotated for a role that can create one', () => { const report = renderPreflightReport(CAPABLE) expect(report).toMatch(/ORE operator class\s+creatable/) - expect(report).not.toContain('<- skips: ORE opclass') + expect(report).not.toContain('<- skips: ORE operator class') }) // A probe that could not ask the question must not be rendered as either @@ -147,3 +161,39 @@ describe('renderPreflightReport', () => { expect(report).not.toContain('<- blocks: CREATE') }) }) + +describe('renderOreOperatorClassNote', () => { + const NO_OPCLASS: PreflightResult = { + ...CAPABLE, + isSuperuser: false, + canCreateOperatorClass: false, + } + + it('says nothing when the role can create the class or the probe could not ask', () => { + expect(renderOreOperatorClassNote(CAPABLE)).toBeNull() + expect( + renderOreOperatorClassNote({ ...CAPABLE, canCreateOperatorClass: null }), + ).toBeNull() + }) + + it('predicts the fallback on a fresh install, and states its consequence once', () => { + const note = renderOreOperatorClassNote(NO_OPCLASS) + expect(note).toContain('install a fallback in its place') + expect(note).toContain(ORE_FALLBACK_REMEDY) + expect(note?.match(/every write/g)).toHaveLength(1) + }) + + // On an installed database, `eql install` without `--force` keeps the + // existing ORE state, so the note must not predict a fallback there. + it('does not predict the fallback where EQL is already installed', () => { + const note = renderOreOperatorClassNote({ + ...NO_OPCLASS, + eqlV3SchemaPresent: true, + eqlV3InternalSchemaPresent: true, + }) + expect(note).toContain('already installed') + expect(note).toContain('stash eql status') + expect(note).not.toContain(ORE_FALLBACK_REMEDY) + expect(note).not.toContain('will skip') + }) +}) diff --git a/languages/typescript/packages/cli/src/commands/db/preflight.ts b/languages/typescript/packages/cli/src/commands/db/preflight.ts index b60c533973..0e3e4e6851 100644 --- a/languages/typescript/packages/cli/src/commands/db/preflight.ts +++ b/languages/typescript/packages/cli/src/commands/db/preflight.ts @@ -92,16 +92,36 @@ export async function preflightCommand( ) } // Said here so the ordering trade is known before a schema is written. The - // same sentence is printed by `eql install` and `eql status` against the + // same remedy is printed by `eql install` and `eql status` against the // installed state, so the answer survives past this command's output (#891). - if (result.canCreateOperatorClass === false) { - p.log.info( - `This role cannot create an operator class, so \`eql install\` will skip the ORE one and install its loud-failure fallback instead. That is a complete install. ${ORE_FALLBACK_REMEDY}`, - ) - } + const oreNote = renderOreOperatorClassNote(result) + if (oreNote) p.log.info(oreNote) p.outro('This role can install EQL.') } +/** + * The note printed after the report when this role cannot create the ORE + * operator class, or `null` when there is nothing to say. Exported for unit + * tests. + * + * Only a fresh install takes the fallback. Where EQL is already installed, + * `stash eql install` without `--force` stops at "already installed" and + * leaves the existing ORE state alone, which may include an operator class + * a more privileged role created. So the note predicts the fallback only + * for a fresh install, and otherwise points at `stash eql status`. + */ +export function renderOreOperatorClassNote( + result: PreflightResult, +): string | null { + if (result.canCreateOperatorClass !== false) return null + const installed = + result.eqlV3SchemaPresent && result.eqlV3InternalSchemaPresent + if (installed) { + return 'This role cannot create the operator class that ORE ordering needs. EQL is already installed here, so `stash eql install` keeps the existing ORE state. Run `stash eql status` to see it. A reinstall by this role (`stash eql install --force`) would skip the operator class and install a fallback in its place.' + } + return `This role cannot create the operator class that ORE ordering needs. \`stash eql install\` will skip it and install a fallback in its place. That is a complete install. ${ORE_FALLBACK_REMEDY}` +} + /** The human-readable rows, aligned. Exported for unit tests. */ export function renderPreflightReport(result: PreflightResult): string { const yesNo = (value: boolean) => (value ? 'yes' : 'no') diff --git a/languages/typescript/packages/cli/src/installer/__tests__/ore.test.ts b/languages/typescript/packages/cli/src/installer/__tests__/ore.test.ts index 74112bc7fb..a7574b5625 100644 --- a/languages/typescript/packages/cli/src/installer/__tests__/ore.test.ts +++ b/languages/typescript/packages/cli/src/installer/__tests__/ore.test.ts @@ -71,8 +71,8 @@ describe('describeOreState', () => { const { message } = describeOreState('fallback') // The consequence: not a failed install. expect(message).toContain('not a failed install') - // The remedy, in the words a schema author types. - expect(message).toContain('types.*Ord') + // The remedy, named by type suffix so it reads for every SDK. + expect(message).toContain('OPE-ordered types (`*Ord`)') expect(message).toContain(ORE_FALLBACK_REMEDY) }) @@ -102,6 +102,20 @@ describe('describeOreState', () => { }) }) +describe('ORE_FALLBACK_REMEDY', () => { + /** + * The remedy is printed to users of every SDK and every EQL version, so it + * names types by suffix, not by a TypeScript API or an EQL version (#1904). + */ + it('names no TypeScript API and no EQL version', () => { + expect(ORE_FALLBACK_REMEDY).toContain('OPE-ordered types (`*Ord`)') + // The fallback also poisons the `_text_search_ore` domain (#1944 review). + expect(ORE_FALLBACK_REMEDY).toContain('ORE types (`*OrdOre`, `*SearchOre`)') + expect(ORE_FALLBACK_REMEDY).not.toContain('types.') + expect(ORE_FALLBACK_REMEDY).not.toMatch(/eql_v\d/) + }) +}) + describe('describeOreCreatable', () => { it('annotates only the "no" answer, and never as a blocker', () => { expect(describeOreCreatable(true)).toEqual({ value: 'creatable' }) @@ -109,6 +123,7 @@ describe('describeOreCreatable', () => { expect(no.value).toBe('not creatable') expect(no.annotation).toContain('<- skips:') expect(no.annotation).not.toContain('<- blocks') + expect(no.annotation).toContain('`*SearchOre`') }) it('renders an unanswerable probe as its own third state', () => { diff --git a/languages/typescript/packages/cli/src/installer/ore.ts b/languages/typescript/packages/cli/src/installer/ore.ts index 8728245c66..06674588de 100644 --- a/languages/typescript/packages/cli/src/installer/ore.ts +++ b/languages/typescript/packages/cli/src/installer/ore.ts @@ -69,14 +69,21 @@ export function classifyOreState(observed: { /** * The remedy, named once. * - * It deliberately names `types.*Ord` and not the `_ord_ope` domains: the - * bundle creates `public.eql_v3__ord_ope`, but `@cipherstash/stack` ships - * no `types.*OrdOpe` factory, so pointing a schema author there names a column - * type they cannot declare. `types.*Ord` (`public.eql_v3__ord`) is the same - * CLLW-OPE ordering and is the one with an SDK factory behind it. + * It names the types by their suffix (`*Ord`, `*OrdOre`, `*SearchOre`), not by an SDK API + * or an EQL version, because the same sentence is read by users of every SDK + * and of every EQL version. The Go SDK, for example, has `eql.IntegerOrd` and + * `eql.IntegerOrdOre` and `eql.TextSearchOre`, and EQL v4 has `public.eql_v4__ord` and + * `public.eql_v4__ord_ore`, just as EQL v3 has `public.eql_v3__ord`. + * The fallback poisons `public._text_search_ore` as well as every + * `_ord_ore` domain (`ore_fallback.sql`), so both ORE suffixes are named. + * + * It deliberately names `*Ord` and not `*OrdOpe`: `@cipherstash/stack` ships + * no `types.*OrdOpe` factory, so pointing a TypeScript schema author there + * names a column type they cannot declare. `*Ord` is the same CLLW-OPE + * ordering and has a type behind it in every SDK. */ export const ORE_FALLBACK_REMEDY = - 'Ordered columns must use OPE ordering: declare them `types.*Ord` (`public.eql_v3_*_ord`), which orders and indexes on any role. `types.*OrdOre` is unusable here — every write to one fails its `eql_ore_unavailable` CHECK.' + 'Use OPE-ordered types (`*Ord`) for ordered columns: they order and index on any role. Do not use ORE types (`*OrdOre`, `*SearchOre`) on this database, because every write to one fails its `eql_ore_unavailable` CHECK.' /** * One line naming what an ORE state means for the operator. `severity` is what @@ -139,6 +146,7 @@ export function describeOreCreatable(creatable: boolean | null): { if (creatable) return { value: 'creatable' } return { value: 'not creatable', - annotation: '<- skips: ORE opclass; use `types.*Ord`, not `types.*OrdOre`', + annotation: + '<- skips: ORE operator class; use OPE-ordered types (`*Ord`), not ORE types (`*OrdOre`, `*SearchOre`)', } } diff --git a/skills/stash-cli/SKILL.md b/skills/stash-cli/SKILL.md index 4ea65c39ca..34b90da94a 100644 --- a/skills/stash-cli/SKILL.md +++ b/skills/stash-cli/SKILL.md @@ -372,7 +372,7 @@ Read-only report of whether the connected role can install EQL, run before anyth Membership of `postgres` is reported but never blocks: `eql install` handles a non-member role by skipping the owner-scoped `ALTER DEFAULT PRIVILEGES FOR ROLE postgres` statements, which are **optional** — the install is complete without them (see `eql install` below). This matters on managed platforms whose database role is not `postgres` and not a member of it (e.g. Lovable's `sandbox_exec`). -**The `ORE operator class` row never blocks either** (`canCreateOperatorClass` in `--json`; `creatable` / `not creatable` / `unknown`). It answers the one schema-design question you want settled *before* writing types: `not creatable` means `eql install` will skip the ORE operator class and install the bundle's loud-failure fallback in its place, so **declare ordered columns `types.*Ord`, not `types.*OrdOre`** — every write to an `_ord_ore` domain on such a database fails its `eql_ore_unavailable` CHECK. This is probed, not inferred from `superuser`: `CREATE OPERATOR CLASS` is superuser-gated in stock PostgreSQL, but AWS RDS and Aurora let their admin role create one while cloud-hosted Supabase does not — so a role with `rolsuper = f` is not evidence either way. The probe attempts the DDL inside a transaction it always rolls back, so preflight stays read-only; `unknown` means it could not ask (a read-only replica, say) and must not be read as either answer. +**The `ORE operator class` row never blocks either** (`canCreateOperatorClass` in `--json`; `creatable` / `not creatable` / `unknown`). It answers the one schema-design question you want settled *before* writing types. `not creatable` means `eql install` will skip the ORE operator class and install the bundle's loud-failure fallback in its place. So **declare ordered columns with OPE-ordered types (`*Ord`), not ORE types (`*OrdOre`, `*SearchOre`)**. On such a database, every write to an ORE column fails its `eql_ore_unavailable` CHECK. Where EQL is already installed, `eql install` without `--force` keeps the existing ORE state, so preflight points at `eql status` instead. The output names types by suffix, so it reads the same for every SDK and EQL version. In TypeScript, use `types.*Ord`. This is probed, not inferred from `superuser`: `CREATE OPERATOR CLASS` is superuser-gated in stock PostgreSQL, but AWS RDS and Aurora let their admin role create one while cloud-hosted Supabase does not — so a role with `rolsuper = f` is not evidence either way. The probe attempts the DDL inside a transaction it always rolls back, so preflight stays read-only; `unknown` means it could not ask (a read-only replica, say) and must not be read as either answer. | Flag | Description | |---|---|