Skip to content

Commit

Permalink
Merge pull request #1068 from MTES-MCT/pgsql-extensions-doc
Browse files Browse the repository at this point in the history
doc: add PostgreSQL extensions setup and usage details
  • Loading branch information
loicguillois authored Jan 6, 2025
2 parents 0a6bbef + 4708962 commit 356c730
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,28 @@ yarn workspace @zerologementvacant/server knex seed:make \

Knex will create a seed file in `src/infra/database/seeds` with the name
`<timestamp>_<name>.ts`.

## Required PostgreSQL Extensions

This project relies on the following PostgreSQL extensions to enhance database functionality:

- **uuid-ossp**: Enables the generation of universally unique identifiers (UUIDs), useful for creating unique keys across distributed systems.
- **postgis**: Adds spatial database capabilities for managing and querying geographic data, enabling advanced geospatial queries (owners and housings).
- **unaccent**: Provides functionality to remove accents from strings, improving search flexibility. To ensure efficient usage with indexed text searches, define an immutable wrapper function:

```sql
CREATE OR REPLACE FUNCTION immutable_unaccent(text)
RETURNS text AS $$
SELECT unaccent($1)
$$ LANGUAGE sql IMMUTABLE STRICT;
```

- **pg_trgm**: Supports similarity and trigram-based text searches. It is particularly effective for fuzzy string matching and partial text search. To optimize full-text searches, create an index using:

```sql
CREATE INDEX IF NOT EXISTS owners_full_name_trgm_idx
ON owners
USING GIN (immutable_unaccent(full_name) gin_trgm_ops);
```

Ensure these extensions are installed and activated in your PostgreSQL database using CREATE EXTENSION IF NOT EXISTS extension_name;.

0 comments on commit 356c730

Please sign in to comment.