pg-smart-search
Guides

CLI & Migrations

Use the interactive CLI to set up database indices, generated columns, and apply migrations for pg-smart-search.

CLI & Migrations

Setting up the required PostgreSQL indices and generated columns can be tedious. pg-smart-search provides an interactive CLI to automate this process.

Interactive Setup

Run the init command in your project directory:

npx pg-smart-init

The CLI is a fully interactive wizard (no flags) that prompts you to:

  1. Enter the table you want to make searchable.
  2. Enter the columns to search (comma-separated).
  3. Confirm whether to enable hybrid search (FTS + Trigrams).
  4. Choose your Search Tier (LITE, STANDARD, ADVANCED, VECTOR).
  5. Enable or disable Turbo Mode (Generated Columns), if hybrid search is on.
  6. Choose a cache provider (None / Memory / Redis) and TTL.

At the end it always prints the generated SQL, then separately asks whether to (a) apply it directly to a database you give it a connection string for, and (b) save it to search-setup.sql / search-config.js.

There is currently no non-interactive or CI/CD mode. The CLI has no command-line flags at all -- every step is an enquirer prompt, so it can't run unattended in a pipeline. For CI/CD, run it once locally and commit the generated search-setup.sql (or the raw SQL it prints) as a normal migration file.

Generated SQL

The CLI creates indices based on your chosen tier:

  • GIN Index: For standard FTS and Trigram searches.
  • RUM Index (ADVANCED tier): The wizard emits CREATE EXTENSION rum and a USING RUM index, but this is unverified in practice -- RUM isn't a standard Postgres contrib module and may fail to install, and AdvancedStrategy's real query sorts word_similarity() in memory rather than via a RUM-ordered scan. The index that actually accelerates its <% pre-filter is a plain GiST/GIN gist_trgm_ops/gin_trgm_ops trigram index.
  • HNSW Index: For vector similarity search (if using pgvector).

The generated SQL is always printed to the console before you're asked whether to apply or save it -- there's no separate "output only" mode, reviewing it is just the default.