Giter Site home page Giter Site logo

Comments (4)

hvdklauw avatar hvdklauw commented on July 17, 2024 1

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.

Gagaro avatar Gagaro commented on July 17, 2024

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.

hvdklauw avatar hvdklauw commented on July 17, 2024

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.

BeOleg avatar BeOleg commented on July 17, 2024

Yup this is indeed missing

from django-safedelete.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.