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-search init

The CLI will prompt you to:

  1. Select your database connection.
  2. Choose the table you want to make searchable.
  3. Select the columns to search.
  4. Choose your Search Tier (Standard, Advanced, Vector).
  5. Enable or disable Turbo Mode (Generated Columns).

Applying Migrations Directly

For CI/CD pipelines or automated deployment scripts, you can apply the generated migrations directly to the database without user interaction:

npx pg-smart-search init --apply

This will execute the generated SQL migrations against your database immediately.

Generated SQL

The CLI creates optimal indices based on your chosen tier:

  • GIN Index: For standard FTS and Trigram searches.
  • RUM Index: For advanced FTS on large datasets (faster sorting by relevance).
  • HNSW Index: For vector similarity search (if using pgvector).

You can review the generated SQL before applying it by choosing the "Output SQL only" option during the interactive setup.