Created
January 13, 2020 20:09
-
-
Save alisonamerico/52422beda403789ea71f74952735954b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generated by Django 2.0.5 on 2020-01-13 18:22 | |
from django.db import migrations | |
class Migration(migrations.Migration): | |
dependencies = [ | |
('schemas', '0021_add_packing_type_and_allow_negotiation'), | |
] | |
def create_proposal_template(apps, schema_editor): | |
Schema = apps.get_model('schemas', 'Schema') | |
SchemaOptionDomain = apps.get_model('schemas', 'SchemaOptionDomain') | |
SchemaVersion = apps.get_model('schemas', 'SchemaVersion') | |
version = SchemaVersion.objects.get(name="v1") | |
old_proposal_template_schema = Schema.active.get( | |
key='coffee_deal_proposal_template', version_id=version.id) | |
old_proposal_template_schema.status = 'deleted' | |
old_proposal_template_schema.save() | |
proposal_template_json_schema = { | |
"type": "object", | |
"$schema": "http:\\\\/\\\\/json-schema.org\\\\/draft-04\\\\/schema#", | |
"required": [ | |
"negotiation", | |
"characteristics", | |
"version" | |
], | |
"properties": { | |
"version": { | |
"enum": [ | |
"v1" | |
], | |
"type": "string" | |
}, | |
"negotiation": { | |
"type": "object", | |
"required": [ | |
"batch_type" | |
], | |
"properties": { | |
"batch_type": { | |
"enum": [ | |
"" | |
], | |
"type": "string" | |
}, | |
}, | |
"additionalProperties": False | |
}, | |
"characteristics": { | |
"type": "object", | |
"required": [ | |
"species", | |
"origin", | |
"drying_process", | |
"type", | |
"harvest", | |
"other", | |
"strange_tastes", | |
"culling", | |
"sieves", | |
"defects", | |
"impurities", | |
"borer_beetle", | |
"humidity", | |
"pva", | |
"color", | |
"aspect", | |
"roasting", | |
"certifications" | |
], | |
"properties": { | |
"pva": { | |
"type": "integer", | |
"maximum": 100, | |
"minimum": 0 | |
}, | |
"type": { | |
"enum": [ | |
"" | |
], | |
"type": "string" | |
}, | |
"color": { | |
"enum": [ | |
"" | |
], | |
"type": "string" | |
}, | |
"aspect": { | |
"enum": [ | |
"" | |
], | |
"type": "string" | |
}, | |
"origin": { | |
"enum": [ | |
"" | |
], | |
"type": "integer" | |
}, | |
"sieves": { | |
"type": "object", | |
"required": [ | |
"type" | |
], | |
"properties": { | |
"type": { | |
"enum": [ | |
"detailed", | |
"simplified" | |
], | |
"type": "string" | |
} | |
}, | |
"additionalProperties": False | |
}, | |
"culling": { | |
"type": "object", | |
"properties": { | |
"maximum": { | |
"type": "integer", | |
"minimum": 0 | |
}, | |
"minimum": { | |
"type": "integer", | |
"minimum": 0 | |
} | |
}, | |
"compareFields": [ | |
[ | |
"maximum", | |
"minimum", | |
">=" | |
] | |
], | |
"additionalProperties": False | |
}, | |
"defects": { | |
"type": "integer", | |
"minimum": 0 | |
}, | |
"harvest": { | |
"enum": [ | |
"" | |
], | |
"type": "integer" | |
}, | |
"species": { | |
"enum": [ | |
"arabica", | |
"robusta" | |
], | |
"type": "string" | |
}, | |
"humidity": { | |
"type": "integer", | |
"maximum": 100, | |
"minimum": 0 | |
}, | |
"roasting": { | |
"enum": [ | |
"" | |
], | |
"type": "string" | |
}, | |
"impurities": { | |
"type": "integer", | |
"maximum": 100, | |
"minimum": 0 | |
}, | |
"borer_beetle": { | |
"type": "integer", | |
"maximum": 100, | |
"minimum": 0 | |
}, | |
"certifications": { | |
"type": "array", | |
"items": { | |
"enum": [ | |
"" | |
], | |
"type": "string" | |
} | |
}, | |
"drying_process": { | |
"enum": [ | |
"" | |
], | |
"type": "string" | |
}, | |
"strange_tastes": { | |
"enum": [ | |
"" | |
], | |
"type": "string" | |
} | |
}, | |
"additionalProperties": False | |
} | |
}, | |
"additionalProperties": False | |
} | |
new_proposal_template_schema = Schema.objects.create( | |
version=version, | |
key='coffee_deal_proposal_template', | |
data=proposal_template_json_schema | |
) | |
proposal_template_op_domain = SchemaOptionDomain.active.filter(schema_id=old_proposal_template_schema.id) | |
proposal_template_op_domain.update(schema_id=new_proposal_template_schema) | |
operations = [migrations.RunPython(create_proposal_template, atomic=True)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment