2
0

0001_setup_extensions.py 1.4 KB

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