File: 0001_setup_extensions.py

package info (click to toggle)
python-django 3%3A4.2.24-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 58,604 kB
  • sloc: python: 334,766; javascript: 18,754; xml: 215; makefile: 178; sh: 27
file content (47 lines) | stat: -rw-r--r-- 1,385 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from unittest import mock

from django.db import connection, migrations

try:
    from django.contrib.postgres.operations import (
        BloomExtension,
        BtreeGinExtension,
        BtreeGistExtension,
        CITextExtension,
        CreateExtension,
        CryptoExtension,
        HStoreExtension,
        TrigramExtension,
        UnaccentExtension,
    )
except ImportError:
    BloomExtension = mock.Mock()
    BtreeGinExtension = mock.Mock()
    BtreeGistExtension = mock.Mock()
    CITextExtension = mock.Mock()
    CreateExtension = mock.Mock()
    HStoreExtension = mock.Mock()
    TrigramExtension = mock.Mock()
    UnaccentExtension = mock.Mock()
    needs_crypto_extension = False
else:
    needs_crypto_extension = (
        connection.vendor == "postgresql" and not connection.features.is_postgresql_13
    )


class Migration(migrations.Migration):
    operations = [
        BloomExtension(),
        BtreeGinExtension(),
        BtreeGistExtension(),
        CITextExtension(),
        # Ensure CreateExtension quotes extension names by creating one with a
        # dash in its name.
        CreateExtension("uuid-ossp"),
        # CryptoExtension is required for RandomUUID() on PostgreSQL < 13.
        CryptoExtension() if needs_crypto_extension else mock.Mock(),
        HStoreExtension(),
        TrigramExtension(),
        UnaccentExtension(),
    ]