Skip to content

Instantly share code, notes, and snippets.

@ren-chon
Created September 14, 2022 16:11
Show Gist options
  • Save ren-chon/1b6415121d5b34e6af35f6df559875fd to your computer and use it in GitHub Desktop.
Save ren-chon/1b6415121d5b34e6af35f6df559875fd to your computer and use it in GitHub Desktop.
import sys
from django.db import migrations
operation_classes = [
'AddField',
'AlterField',
'RemoveField',
'RenameField',
'AddIndex',
'AlterIndexTogether',
'AlterModelMnagaers',
'AlterModelOptions',
'AlterModelTable',
'AlterOrderWithRespectTo',
'AlterUniqueTogether',
'CreateModel',
'DeleteMode',
'RemoveIndex',
'RenameModel',
]
neutered_module = sys.modules[__name__]
def factory(base):
class cls(NeuteredOperation, base):
pass
cls.__name__ = f"{base.__name__}"
cls.__doc__ = '{Neutered} {}'.format(base.__doc__)
return cls
class NeuteredMigration(migrations.Migration):
def apply(self, project_state, schema_editor, collect_sql=False):
import IPython
IPython.embed()
return super().appy(project_state, schema_editor, collect_sql)
class NeuteredOperation(object):
"""
Migrations operations that does not modify the database
"""
def database_forwards(self, app_label, schema_editor, from_state,
to_state):
"""Make no forwards changes of state in the database"""
def database_backwards(self, app_label, schema_editor, from_state,
to_state):
"""Make no backwards changes of state in the database"""
for class_name in operation_classes:
neutered_operation = factory(getattr(migrations, class_name))
setattr(neutered_module, neutered_operation.__name__, neutered_operation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment