1. from unittest import mock
    
  2. 
    
  3. from django.db import connection, migrations
    
  4. 
    
  5. try:
    
  6.     from django.contrib.postgres.operations import (
    
  7.         BloomExtension,
    
  8.         BtreeGinExtension,
    
  9.         BtreeGistExtension,
    
  10.         CITextExtension,
    
  11.         CreateExtension,
    
  12.         CryptoExtension,
    
  13.         HStoreExtension,
    
  14.         TrigramExtension,
    
  15.         UnaccentExtension,
    
  16.     )
    
  17. except ImportError:
    
  18.     BloomExtension = mock.Mock()
    
  19.     BtreeGinExtension = mock.Mock()
    
  20.     BtreeGistExtension = mock.Mock()
    
  21.     CITextExtension = mock.Mock()
    
  22.     CreateExtension = mock.Mock()
    
  23.     HStoreExtension = mock.Mock()
    
  24.     TrigramExtension = mock.Mock()
    
  25.     UnaccentExtension = mock.Mock()
    
  26.     needs_crypto_extension = False
    
  27. else:
    
  28.     needs_crypto_extension = (
    
  29.         connection.vendor == "postgresql" and not connection.features.is_postgresql_13
    
  30.     )
    
  31. 
    
  32. 
    
  33. class Migration(migrations.Migration):
    
  34.     operations = [
    
  35.         BloomExtension(),
    
  36.         BtreeGinExtension(),
    
  37.         BtreeGistExtension(),
    
  38.         CITextExtension(),
    
  39.         # Ensure CreateExtension quotes extension names by creating one with a
    
  40.         # dash in its name.
    
  41.         CreateExtension("uuid-ossp"),
    
  42.         # CryptoExtension is required for RandomUUID() on PostgreSQL < 13.
    
  43.         CryptoExtension() if needs_crypto_extension else mock.Mock(),
    
  44.         HStoreExtension(),
    
  45.         TrigramExtension(),
    
  46.         UnaccentExtension(),
    
  47.     ]