mirror of
https://github.com/django/django.git
synced 2025-10-25 14:46:09 +00:00
Refs #27236 -- Reverted "Refs #27236 -- Added generic mechanism to handle the deprecation of migration operations."
This reverts commit 41019e48bb.
This commit is contained in:
@@ -1,101 +0,0 @@
|
||||
from django.core import checks
|
||||
from django.db import migrations
|
||||
from django.db.migrations.operations.base import Operation
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class DeprecatedMigrationOperationTests(TestCase):
|
||||
def test_default_operation(self):
|
||||
class MyOperation(Operation):
|
||||
system_check_deprecated_details = {}
|
||||
|
||||
my_operation = MyOperation()
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
operations = [my_operation]
|
||||
|
||||
self.assertEqual(
|
||||
Migration("name", "app_label").check(),
|
||||
[
|
||||
checks.Warning(
|
||||
msg="MyOperation has been deprecated.",
|
||||
obj=my_operation,
|
||||
id="migrations.WXXX",
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
def test_user_specified_details(self):
|
||||
class MyOperation(Operation):
|
||||
system_check_deprecated_details = {
|
||||
"msg": "This operation is deprecated and will be removed soon.",
|
||||
"hint": "Use something else.",
|
||||
"id": "migrations.W999",
|
||||
}
|
||||
|
||||
my_operation = MyOperation()
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
operations = [my_operation]
|
||||
|
||||
self.assertEqual(
|
||||
Migration("name", "app_label").check(),
|
||||
[
|
||||
checks.Warning(
|
||||
msg="This operation is deprecated and will be removed soon.",
|
||||
obj=my_operation,
|
||||
hint="Use something else.",
|
||||
id="migrations.W999",
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
class RemovedMigrationOperationTests(TestCase):
|
||||
def test_default_operation(self):
|
||||
class MyOperation(Operation):
|
||||
system_check_removed_details = {}
|
||||
|
||||
my_operation = MyOperation()
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
operations = [my_operation]
|
||||
|
||||
self.assertEqual(
|
||||
Migration("name", "app_label").check(),
|
||||
[
|
||||
checks.Error(
|
||||
msg=(
|
||||
"MyOperation has been removed except for support in historical "
|
||||
"migrations."
|
||||
),
|
||||
obj=my_operation,
|
||||
id="migrations.EXXX",
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
def test_user_specified_details(self):
|
||||
class MyOperation(Operation):
|
||||
system_check_removed_details = {
|
||||
"msg": "Support for this operation is gone.",
|
||||
"hint": "Use something else.",
|
||||
"id": "migrations.E999",
|
||||
}
|
||||
|
||||
my_operation = MyOperation()
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
operations = [my_operation]
|
||||
|
||||
self.assertEqual(
|
||||
Migration("name", "app_label").check(),
|
||||
[
|
||||
checks.Error(
|
||||
msg="Support for this operation is gone.",
|
||||
obj=my_operation,
|
||||
hint="Use something else.",
|
||||
id="migrations.E999",
|
||||
)
|
||||
],
|
||||
)
|
||||
@@ -1,22 +1,11 @@
|
||||
from unittest import mock
|
||||
|
||||
from django.db import migrations
|
||||
from django.db.migrations.operations.base import Operation
|
||||
|
||||
|
||||
class DummyOperation(Operation):
|
||||
def state_forwards(self, app_label, state):
|
||||
pass
|
||||
|
||||
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
||||
pass
|
||||
|
||||
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
||||
pass
|
||||
|
||||
|
||||
try:
|
||||
from django.contrib.postgres.operations import CryptoExtension
|
||||
except ImportError:
|
||||
CryptoExtension = DummyOperation
|
||||
CryptoExtension = mock.Mock()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
from unittest import mock
|
||||
|
||||
from django.db import connection, migrations
|
||||
from django.db.migrations.operations.base import Operation
|
||||
|
||||
|
||||
class DummyOperation(Operation):
|
||||
def state_forwards(self, app_label, state):
|
||||
pass
|
||||
|
||||
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
||||
pass
|
||||
|
||||
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
||||
pass
|
||||
|
||||
|
||||
try:
|
||||
from django.contrib.postgres.operations import (
|
||||
@@ -26,14 +15,14 @@ try:
|
||||
UnaccentExtension,
|
||||
)
|
||||
except ImportError:
|
||||
BloomExtension = DummyOperation
|
||||
BtreeGinExtension = DummyOperation
|
||||
BtreeGistExtension = DummyOperation
|
||||
CITextExtension = DummyOperation
|
||||
CreateExtension = DummyOperation
|
||||
HStoreExtension = DummyOperation
|
||||
TrigramExtension = DummyOperation
|
||||
UnaccentExtension = DummyOperation
|
||||
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 = (
|
||||
@@ -52,7 +41,7 @@ class Migration(migrations.Migration):
|
||||
# dash in its name.
|
||||
CreateExtension("uuid-ossp"),
|
||||
# CryptoExtension is required for RandomUUID() on PostgreSQL < 13.
|
||||
CryptoExtension() if needs_crypto_extension else DummyOperation(),
|
||||
CryptoExtension() if needs_crypto_extension else mock.Mock(),
|
||||
HStoreExtension(),
|
||||
TrigramExtension(),
|
||||
UnaccentExtension(),
|
||||
|
||||
Reference in New Issue
Block a user