Files
gochat/backend/migrations/000013_add_pg_trgm_search.up.sql
T
rogee aeddedf2a3 Reorganize repo: backend/, deploy/, docs/ layout + AGENTS.md
Restructure the monorepo into clear top-level directories:
- backend/: Go module root (cmd, internal, pkg, configs, migrations,
  docs/swagger, scripts, tests, go.mod, Makefile, .air.toml)
- deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd
- docs/: project documentation + reports/ (moved from repo root)
- AGENTS.md: new AI coding-agent guide at repo root

Update all references to the new layout:
- Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root)
- docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile,
  env_file ../../.env, volume mounts ../../backend:/app
- deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile
- CI: working-directory: backend for go commands, file deploy/docker/Dockerfile,
  coverage path backend/coverage.out, health_check backend/scripts/
- backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../
- README: architecture tree, quickstart, config paths updated

Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh,
gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to
preserve history. Build, vet, SQLite tests, and docker compose config verified.
2026-07-07 14:44:12 +08:00

24 lines
1.6 KiB
SQL

-- M15: pg_trgm extension + GIN trigram indexes for fuzzy/full-text search
-- Enables PostgreSQL trigram similarity search (pg_trgm) across conversations,
-- messages, contacts, and articles — supports fuzzy matching with relevance ranking.
-- Reference: Chatwoot GlobalSearchService — pg_trgm for fuzzy search on text columns.
-- Create pg_trgm extension (requires superuser; may need: CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public;)
CREATE EXTENSION IF NOT EXISTS pg_trgm;
-- Conversations: trigram indexes on labels (for label search)
CREATE INDEX IF NOT EXISTS idx_conversations_labels_trgm ON conversations USING gin (labels gin_trgm_ops);
-- Messages: trigram indexes on content (primary search field)
CREATE INDEX IF NOT EXISTS idx_messages_content_trgm ON messages USING gin (content gin_trgm_ops);
-- Contacts: trigram indexes on name, email, phone_number, identifier
CREATE INDEX IF NOT EXISTS idx_contacts_name_trgm ON contacts USING gin (name gin_trgm_ops);
CREATE INDEX IF NOT EXISTS idx_contacts_email_trgm ON contacts USING gin (email gin_trgm_ops);
CREATE INDEX IF NOT EXISTS idx_contacts_phone_trgm ON contacts USING gin (phone_number gin_trgm_ops);
CREATE INDEX IF NOT EXISTS idx_contacts_identifier_trgm ON contacts USING gin (identifier gin_trgm_ops);
-- Articles: trigram indexes on title, description, content
CREATE INDEX IF NOT EXISTS idx_articles_title_trgm ON articles USING gin (title gin_trgm_ops);
CREATE INDEX IF NOT EXISTS idx_articles_description_trgm ON articles USING gin (description gin_trgm_ops);
CREATE INDEX IF NOT EXISTS idx_articles_content_trgm ON articles USING gin (content gin_trgm_ops);