@@ -0,0 +1,1481 @@
+# -*- coding: utf-8 -*-%0A# Generated by Django 1.11 on 2017-05-24 19:33%0Afrom __future__ import unicode_literals%0A%0Aimport logging%0A%0Afrom django.db import migrations%0A%0Afrom osf.models import MetaSchema%0Afrom website.project.metadata.schemas import OSF_META_SCHEMAS%0A%0A%0Alogger = logging.getLogger(__file__)%0A%0A%0Adef add_schemas(*args):%0A    %22%22%22Import meta-data schemas from JSON to database if not already loaded%0A    %22%22%22%0A    schema_count = 0%0A    for schema in OSF_META_SCHEMAS:%0A        schema_obj, created = MetaSchema.objects.get_or_create(%0A            name=schema%5B'name'%5D,%0A            schema_version=schema.get('version', 1)%0A        )%0A        schema_obj.schema = schema%0A        schema_obj.save()%0A        schema_count += 1%0A%0A        if created:%0A            logger.info('Added schema %7B%7D to the database'.format(schema%5B'name'%5D))%0A%0A    logger.info('Ensured %7B%7D schemas are in the database'.format(schema_count))%0A%0A%0Adef remove_schemas(*args):%0A    removed_schemas = 0%0A    for schema in OSF_META_SCHEMAS:%0A        schema_obj = MetaSchema.objects.get(%0A            schema=schema,%0A            name=schema%5B'name'%5D,%0A            schema_version=schema.get('version', 1)%0A        )%0A        schema_obj.delete()%0A        removed_schemas += 1%0A%0A    logger.info('Removed %7B%7D schemas from the database'.format(removed_schemas))%0A%0Aclass Migration(migrations.Migration):%0A%0A    dependencies = %5B%0A        ('osf', '0035_ensure_licenses'),%0A    %5D%0A%0A    operations = %5B%0A        migrations.RunPython(add_schemas, remove_schemas),%0A    %5D%0A

Add migration for ensure schemas