Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

add-fpr-rule: generate migrations #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

mistydemeo
Copy link
Contributor

This replaces raw SQL output with migrations.

Here's a sample session. Input:

$ am add-fpr-rule idcommand
description:
test tool
config:
puid
replaces_id:
a8e45bc1-eb35-4545-885c-dd552f1fde9a
script:
rm -rf
script_type:
bashScript
tool_id:
8f04f36d-8d43-43c2-92f9-da64c5530106

Output:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import main.models

def forwards_fn(apps, schema_editor):
    db_alias = schema_editor.connection.alias
    IDCommand = apps.get_model("fpr", "IDCommand")
    IDCommand.objects.filter(uuid=u'a8e45bc1-eb35-4545-885c-dd552f1fde9a').update(**{'enabled': False})
    IDCommand = apps.get_model("fpr", "IDCommand")
    IDCommand.objects.using(db_alias).create(**{'tool_id': '8f04f36d-8d43-43c2-92f9-da64c5530106', 'uuid': u'5c28dda3-80f2-49a4-a5d0-e7bb096cef13', 'script': 'rm -rf', 'lastmodified': '2016-02-25T00:48:19.477494+00:00', 'enabled': True, 'replaces_id': 'a8e45bc1-eb35-4545-885c-dd552f1fde9a', 'script_type': 'bashScript', 'config': 'puid', 'id': 9L, 'description': 'test tool'})

def reverse_fn(apps, schema_editor):
    db_alias = schema_editor.connection.alias
    IDCommand = apps.get_model("fpr", "IDCommand")
    IDCommand.objects.filter(uuid=u'a8e45bc1-eb35-4545-885c-dd552f1fde9a').update(**{'enabled': True})
    IDCommand = apps.get_model("fpr", "IDCommand")
    IDCommand.objects.filter(**{'tool_id': '8f04f36d-8d43-43c2-92f9-da64c5530106', 'uuid': u'5c28dda3-80f2-49a4-a5d0-e7bb096cef13', 'script': 'rm -rf', 'lastmodified': '2016-02-25T00:48:19.477494+00:00', 'enabled': True, 'replaces_id': 'a8e45bc1-eb35-4545-885c-dd552f1fde9a', 'script_type': 'bashScript', 'config': 'puid', 'id': 9L, 'description': 'test tool'}).delete()

class Migration(migrations.Migration):
    dependencies = []
    operations = [
        migrations.RunPython(forwards_fn, reverse_fn),
    ]

@qubot qubot force-pushed the add-fpr-rule branch 4 times, most recently from 6e986a5 to 7f5c918 Compare February 23, 2016 21:00
@mistydemeo
Copy link
Contributor Author

Need to figure out how to handle the datetime() stuff.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant