til: django_migration-postgresql-fuzzystrmatch.md
This data as json
| path | topic | title | url | body | html | shot | created | created_utc | updated | updated_utc | shot_hash | slug |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| django_migration-postgresql-fuzzystrmatch.md | django | Enabling the fuzzystrmatch extension in PostgreSQL with a Django migration | https://github.com/simonw/til/blob/main/django/migration-postgresql-fuzzystrmatch.md | The PostgreSQL [fuzzystrmatch extension](https://www.postgresql.org/docs/13/fuzzystrmatch.html) enables several functions for fuzzy string matching: `soundex()`, `difference()`, `levenshtein()`, `levenshtein_less_equal()`, `metaphone()`, `dmetaphone()` and `dmetaphone_alt()`. Enabling them for use with Django turns out to be really easy - it just takes a migration that looks something like this: ```python from django.contrib.postgres.operations import CreateExtension from django.db import migrations class Migration(migrations.Migration): dependencies = [ ("core", "0089_importrun_sourcelocation"), ] operations = [ CreateExtension(name="fuzzystrmatch"), ] ``` | <p>The PostgreSQL <a href="https://www.postgresql.org/docs/13/fuzzystrmatch.html" rel="nofollow">fuzzystrmatch extension</a> enables several functions for fuzzy string matching: <code>soundex()</code>, <code>difference()</code>, <code>levenshtein()</code>, <code>levenshtein_less_equal()</code>, <code>metaphone()</code>, <code>dmetaphone()</code> and <code>dmetaphone_alt()</code>.</p> <p>Enabling them for use with Django turns out to be really easy - it just takes a migration that looks something like this:</p> <div class="highlight highlight-source-python"><pre><span class="pl-k">from</span> <span class="pl-s1">django</span>.<span class="pl-s1">contrib</span>.<span class="pl-s1">postgres</span>.<span class="pl-s1">operations</span> <span class="pl-k">import</span> <span class="pl-v">CreateExtension</span> <span class="pl-k">from</span> <span class="pl-s1">django</span>.<span class="pl-s1">db</span> <span class="pl-k">import</span> <span class="pl-s1">migrations</span> <span class="pl-k">class</span> <span class="pl-v">Migration</span>(<span class="pl-s1">migrations</span>.<span class="pl-v">Migration</span>): <span class="pl-s1">dependencies</span> <span class="pl-c1">=</span> [ (<span class="pl-s">"core"</span>, <span class="pl-s">"0089_importrun_sourcelocation"</span>), ] <span class="pl-s1">operations</span> <span class="pl-c1">=</span> [ <span class="pl-v">CreateExtension</span>(<span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-s">"fuzzystrmatch"</span>), ]</pre></div> | <Binary: 58,747 bytes> | 2021-04-18T12:32:58-07:00 | 2021-04-18T19:32:58+00:00 | 2021-04-18T12:32:58-07:00 | 2021-04-18T19:32:58+00:00 | a95d79750b014c729ca6aca5db4665ee | migration-postgresql-fuzzystrmatch |