Comments (4)
This is a way to do it if you don't care about backwards compatibility or running multiple version of your code against the same database.
If you for instance want to update one frontend while keeping the old running this is not for you.
from __future__ import unicode_literals
from django.db import migrations, models
def migrate_deleted(apps, schema_editor):
db_alias = schema_editor.connection.alias
Model = apps.get_model('app', 'Model')
for obj in Model.objects.using(db_alias).all():
if obj.deleted:
obj.deleted_at = obj.modified
obj.save()
class Migration(migrations.Migration):
dependencies = [
('app', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='model',
name='deleted_at',
field=models.DateTimeField(editable=False, null=True),
),
migrations.RunPython(migrate_deleted, migrations.RunPython.noop),
migrations.RemoveField('Model', 'deleted'),
migrations.RenameField(
model_name='model',
old_name='deleted_at',
new_name='deleted',
),
]
from django-safedelete.
We discussed it in #55. I don't have time right now but I will definitively add some documentation about how to migrate later.
If someone is willing to do it before then, don't hesitate to do a PR.
from django-safedelete.
Did some more thinking about this.
Just renaming the columns is not going to work for anything with more then one frontend (unless you are willing to take some downtime).
You need to be able to put the new code on one frontend, run the migrations and still keep the old code working with the database.
It would have been better if the deleted column was renamed to deleted_at
then it could have just been added (it's nullable, so old code keeps working) and after a while you could delete the old column.
from django-safedelete.
Yup this is indeed missing
from django-safedelete.
Related Issues (20)
- Safe delete does not work as expected with OneToOneField HOT 2
- TypeError: cannot unpack non-iterable NoneType object HOT 3
- add type annotation HOT 3
- SafeDeleteQuery AttributeError on _safedelete_visibility and _safedelete_visibility_field HOT 8
- Setting highlight_deleted_field.short_description mistakenly affects all subclasses of SafeDeleteAdmin HOT 1
- Behaviour of SOFT_DELETE on an object with a PROTECTED relationship to another SOFT_DELETED object HOT 1
- Django 4.2 support HOT 1
- Soft delete model object and cascading delete all related objects which are not instance of SafeDeleteModel HOT 2
- deleted_objects is not documented anywhere HOT 2
- Fields uniqueness with MySQL HOT 2
- delete method hangs on raise ProtectedError, when a lot of related protected objects HOT 1
- HARD_DELETE in SafeDeleteQueryset bypasses custom delete logic HOT 1
- Infinite recursive loop with SafeDeleteQueryset HOT 2
- Is it possible to set _safedelete_visibility without having to define a Manager? HOT 1
- cannot unpack non-iterable NoneType object with `SOFT_DELETE_CASCADE` HOT 17
- get_queryset filteration for related models
- If using django-simple-history, is this needed? HOT 2
- How can I use SafeDeleteQueryset and SafeDeleteManager at the same time?
- pkg_resources deprecation warning HOT 1
- Custom UniqueConstraint do not works with OneToOneField HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-safedelete.