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 initThe CLI will prompt you to:
- Select your database connection.
- Choose the table you want to make searchable.
- Select the columns to search.
- Choose your Search Tier (Standard, Advanced, Vector).
- 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 --applyThis 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.