2017-01-20 01:16:04 +08:00
|
|
|
from unittest import mock
|
|
|
|
|
2020-07-27 05:29:05 +08:00
|
|
|
from django.db import connection, migrations
|
2014-03-15 01:34:49 +08:00
|
|
|
|
2015-04-05 00:10:26 +08:00
|
|
|
try:
|
|
|
|
from django.contrib.postgres.operations import (
|
2019-10-18 17:08:50 +08:00
|
|
|
BloomExtension, BtreeGinExtension, BtreeGistExtension, CITextExtension,
|
2017-07-01 21:30:34 +08:00
|
|
|
CreateExtension, CryptoExtension, HStoreExtension, TrigramExtension,
|
|
|
|
UnaccentExtension,
|
2015-04-05 00:10:26 +08:00
|
|
|
)
|
|
|
|
except ImportError:
|
2019-10-18 17:08:50 +08:00
|
|
|
BloomExtension = mock.Mock()
|
2016-08-08 11:15:08 +08:00
|
|
|
BtreeGinExtension = mock.Mock()
|
2017-07-01 21:30:34 +08:00
|
|
|
BtreeGistExtension = mock.Mock()
|
2017-04-26 06:49:29 +08:00
|
|
|
CITextExtension = mock.Mock()
|
2016-04-26 07:30:48 +08:00
|
|
|
CreateExtension = mock.Mock()
|
2015-04-05 00:10:26 +08:00
|
|
|
HStoreExtension = mock.Mock()
|
2015-06-06 00:37:48 +08:00
|
|
|
TrigramExtension = mock.Mock()
|
2015-04-05 00:10:26 +08:00
|
|
|
UnaccentExtension = mock.Mock()
|
2020-07-27 05:29:05 +08:00
|
|
|
needs_crypto_extension = False
|
|
|
|
else:
|
2020-07-31 18:38:09 +08:00
|
|
|
needs_crypto_extension = (
|
|
|
|
connection.vendor == 'postgresql' and
|
|
|
|
not connection.features.is_postgresql_13
|
|
|
|
)
|
2015-04-05 00:10:26 +08:00
|
|
|
|
2014-03-15 01:34:49 +08:00
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
operations = [
|
2020-05-14 12:33:00 +08:00
|
|
|
BloomExtension(),
|
2016-08-08 11:15:08 +08:00
|
|
|
BtreeGinExtension(),
|
2017-07-01 21:30:34 +08:00
|
|
|
BtreeGistExtension(),
|
2017-04-26 06:49:29 +08:00
|
|
|
CITextExtension(),
|
2016-04-26 07:30:48 +08:00
|
|
|
# Ensure CreateExtension quotes extension names by creating one with a
|
|
|
|
# dash in its name.
|
|
|
|
CreateExtension('uuid-ossp'),
|
2020-07-27 05:29:05 +08:00
|
|
|
# CryptoExtension is required for RandomUUID() on PostgreSQL < 13.
|
|
|
|
CryptoExtension() if needs_crypto_extension else mock.Mock(),
|
2014-03-15 01:34:49 +08:00
|
|
|
HStoreExtension(),
|
2015-06-06 00:37:48 +08:00
|
|
|
TrigramExtension(),
|
2014-09-06 04:53:11 +08:00
|
|
|
UnaccentExtension(),
|
2014-03-15 01:34:49 +08:00
|
|
|
]
|