<commit_before># -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import DataMigration
from django.db import models

class Migration(DataMigration):

    def forwards(self, orm):
        """
        This will migrate the old project->worker->job-template->job structure
        to the new structure of worker pools.
        """
        for worker in orm['job_runner.Worker'].objects.all():
            # create a worker-pool for every worker
            worker_pool = orm['job_runner.WorkerPool'].objects.create(
                title=worker.title,
                enqueue_is_enabled=worker.enqueue_is_enabled,
                notification_addresses=worker.notification_addresses,
            )
            # add the worker to the pool
            worker_pool.workers.add(worker)
            worker_pool.save()

            project = worker.project
            # add the worker-pool to the project
            project.worker_pools.add(worker_pool)
            project.save()

            job_templates = orm['job_runner.JobTemplate'].objects.filter(
                worker=worker)

            # loop over ever job-template for the worker
            for job_template in job_templates:
                # link the job-template to the project
                job_template.project = project
                job_template.save()

                for auth_group in job_template.auth_groups.all():
                    project.auth_groups.add(auth_group)
                project.save()

                for job in job_template.job_set.all():
                    # link the worker-pool to the job
                    job.worker_pool = worker_pool
                    job.save()

    def backwards(self, orm):
        "Write your backwards methods here."

    models = {
        'auth.group': {
            'Meta': {'object_name': 'Group'},
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
        },
        'auth.permission': {
            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
        },
        'contenttypes.contenttype': {
            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
        },<commit_msg>Raise exception when trying to rollback migration.<commit_after># -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import DataMigration
from django.db import models

class Migration(DataMigration):

    def forwards(self, orm):
        """
        This will migrate the old project->worker->job-template->job structure
        to the new structure of worker pools.
        """
        for worker in orm['job_runner.Worker'].objects.all():
            # create a worker-pool for every worker
            worker_pool = orm['job_runner.WorkerPool'].objects.create(
                title=worker.title,
                enqueue_is_enabled=worker.enqueue_is_enabled,
                notification_addresses=worker.notification_addresses,
            )
            # add the worker to the pool
            worker_pool.workers.add(worker)
            worker_pool.save()

            project = worker.project
            # add the worker-pool to the project
            project.worker_pools.add(worker_pool)
            project.save()

            job_templates = orm['job_runner.JobTemplate'].objects.filter(
                worker=worker)

            # loop over ever job-template for the worker
            for job_template in job_templates:
                # link the job-template to the project
                job_template.project = project
                job_template.save()

                for auth_group in job_template.auth_groups.all():
                    project.auth_groups.add(auth_group)
                project.save()

                for job in job_template.job_set.all():
                    # link the worker-pool to the job
                    job.worker_pool = worker_pool
                    job.save()

    def backwards(self, orm):
        raise RuntimeError("Cannot reverse this migration.")

    models = {
        'auth.group': {
            'Meta': {'object_name': 'Group'},
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
        },
        'auth.permission': {
            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
        },
        'contenttypes.contenttype': {
            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
        },
{'fraction_non_alphanumeric': 0.1586489252814739, 'fraction_numerical': 0.005263927474777014, 'mean_word_length': 2.3694581280788176, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '415967', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1858, 'n_words': 398}