SQUASHING

This commit is contained in:
Matthew Ryan Dillon 2016-06-15 15:12:34 -07:00
parent 8573b0326b
commit a541a6f301
42 changed files with 588 additions and 1001 deletions

View file

@ -1,24 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import autoslug.fields
class Migration(migrations.Migration):
dependencies = [
('misc', '0001_initial'),
('locations', '0001_initial'),
('collections_ccdb', '0001_initial'),
('species', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Experiment',
fields=[
('id', models.AutoField(auto_created=True, serialize=False, verbose_name='ID', primary_key=True)),
('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')),
('name', models.CharField(max_length=150)),
('code', models.CharField(max_length=10, blank=True)),
('description', models.CharField(max_length=255, blank=True)),
('sort_order', models.IntegerField(null=True, blank=True)),
('code', models.CharField(blank=True, max_length=10)),
('description', models.CharField(blank=True, max_length=255)),
('sort_order', models.IntegerField(blank=True, null=True)),
('slug', autoslug.fields.AutoSlugField(populate_from='name', editable=False)),
],
options={
@ -28,10 +28,10 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Flaw',
fields=[
('id', models.AutoField(auto_created=True, serialize=False, verbose_name='ID', primary_key=True)),
('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('description', models.CharField(max_length=255, blank=True)),
('sort_order', models.IntegerField(null=True, blank=True)),
('description', models.CharField(blank=True, max_length=255)),
('sort_order', models.IntegerField(blank=True, null=True)),
('slug', autoslug.fields.AutoSlugField(populate_from='name', editable=False)),
],
options={
@ -41,7 +41,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='ProtocolAttachment',
fields=[
('id', models.AutoField(auto_created=True, serialize=False, verbose_name='ID', primary_key=True)),
('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')),
('protocol', models.FileField(upload_to='experiments/protocols/%Y/%m/%d')),
('experiment', models.ForeignKey(to='experiments.Experiment')),
],
@ -55,4 +55,147 @@ class Migration(migrations.Migration):
name='experiment',
unique_together=set([('name', 'code')]),
),
migrations.CreateModel(
name='TreatmentType',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('code', models.CharField(blank=True, max_length=25)),
('treatment_type', models.CharField(blank=True, max_length=50)),
('placement', models.CharField(blank=True, max_length=25)),
('description', models.CharField(blank=True, max_length=255)),
('sort_order', models.IntegerField(blank=True, null=True)),
('slug', autoslug.fields.AutoSlugField(populate_from='name', editable=False)),
('experiment', models.ForeignKey(to='experiments.Experiment', null=True, blank=True)),
],
options={
'ordering': ['sort_order'],
},
),
migrations.AlterUniqueTogether(
name='treatmenttype',
unique_together=set([('experiment', 'name')]),
),
migrations.CreateModel(
name='Treatment',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')),
('sex', models.CharField(max_length=25)),
('container', models.ForeignKey(to='misc.Container', null=True, blank=True)),
('flaw', models.ForeignKey(to='experiments.Flaw', null=True, blank=True)),
('species', models.ForeignKey(to='species.Species')),
('study_location', models.ForeignKey(to='locations.StudyLocation')),
('treatment_type', models.ForeignKey(to='experiments.TreatmentType')),
],
),
migrations.CreateModel(
name='TreatmentReplicate',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('setup_date', models.DateField(blank=True, null=True)),
('setup_time', models.TimeField(blank=True, null=True)),
('setup_sample_size', models.IntegerField(blank=True, null=True)),
('mass_g', models.FloatField(blank=True, null=True)),
('flaw', models.ForeignKey(to='experiments.Flaw', null=True, blank=True)),
('treatment', models.ForeignKey(to='experiments.Treatment')),
],
),
migrations.AlterUniqueTogether(
name='treatmentreplicate',
unique_together=set([('treatment', 'name', 'setup_date', 'setup_time')]),
),
migrations.CreateModel(
name='AliveDeadCount',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')),
('status_date', models.DateField()),
('status_time', models.TimeField(blank=True, null=True)),
('count_alive', models.IntegerField(blank=True, null=True)),
('count_dead', models.IntegerField(blank=True, null=True)),
('flaw', models.ForeignKey(to='experiments.Flaw', null=True, blank=True)),
('treatment_replicate', models.ForeignKey(to='experiments.TreatmentReplicate')),
],
),
migrations.AddField(
model_name='experiment',
name='collections',
field=models.ManyToManyField(to='collections_ccdb.Collection'),
),
migrations.AlterModelOptions(
name='alivedeadcount',
options={'verbose_name': 'Alive-dead Count'},
),
migrations.AddField(
model_name='treatmentreplicate',
name='display_name',
field=models.CharField(default='x', max_length=255, editable=False),
preserve_default=False,
),
migrations.AddField(
model_name='treatment',
name='display_name',
field=models.CharField(default='x', max_length=255, editable=False),
preserve_default=False,
),
migrations.AlterField(
model_name='alivedeadcount',
name='flaw',
field=models.ForeignKey(related_name='alive_dead_counts', to='experiments.Flaw', null=True, blank=True),
),
migrations.AlterField(
model_name='alivedeadcount',
name='treatment_replicate',
field=models.ForeignKey(related_name='alive_dead_counts', to='experiments.TreatmentReplicate'),
),
migrations.AlterField(
model_name='experiment',
name='flaw',
field=models.ForeignKey(related_name='experiments', to='experiments.Flaw', null=True, blank=True),
),
migrations.AlterField(
model_name='protocolattachment',
name='experiment',
field=models.ForeignKey(related_name='protocols', to='experiments.Experiment'),
),
migrations.AlterField(
model_name='treatment',
name='container',
field=models.ForeignKey(related_name='treatments', to='misc.Container', null=True, blank=True),
),
migrations.AlterField(
model_name='treatment',
name='flaw',
field=models.ForeignKey(related_name='treatments', to='experiments.Flaw', null=True, blank=True),
),
migrations.AlterField(
model_name='treatment',
name='species',
field=models.ForeignKey(related_name='treatments', to='species.Species'),
),
migrations.AlterField(
model_name='treatment',
name='study_location',
field=models.ForeignKey(related_name='treatments', to='locations.StudyLocation'),
),
migrations.AlterField(
model_name='treatment',
name='treatment_type',
field=models.ForeignKey(related_name='treatments', to='experiments.TreatmentType'),
),
migrations.AlterField(
model_name='treatmentreplicate',
name='flaw',
field=models.ForeignKey(related_name='treatment_replicates', to='experiments.Flaw', null=True, blank=True),
),
migrations.AlterField(
model_name='treatmentreplicate',
name='treatment',
field=models.ForeignKey(related_name='treatment_replicates', to='experiments.Treatment'),
),
migrations.AlterField(
model_name='treatmenttype',
name='experiment',
field=models.ForeignKey(related_name='treatment_types', to='experiments.Experiment', null=True, blank=True),
),
]

View file

@ -23,6 +23,10 @@ class Migration(migrations.Migration):
Experiment, Flaw]:
model.objects.all().delete()
Collection = apps.get_model('collections_ccdb', 'Collection')
StudyLocation = apps.get_model('locations', 'StudyLocation')
Species = apps.get_model('species', 'Species')
ExperimentForm = modelform_factory(Experiment, exclude=('collections',))
TreatmentTypeForm = modelform_factory(TreatmentType, fields='__all__')
TreatmentForm = modelform_factory(Treatment, fields='__all__')
@ -50,7 +54,12 @@ class Migration(migrations.Migration):
form = TreatmentForm(dict(treatment_type=r[1], container=r[2],
study_location=r[3], species=r[4], sex=r[5]))
if form.is_valid():
Treatment.objects.create(id=r[0], **form.cleaned_data)
treatment_type = TreatmentType.objects.get(id=r[1])
study_location = StudyLocation.objects.get(id=r[3])
species = Species.objects.get(id=r[4])
d = "{}_{}_{}_{}".format(treatment_type, study_location,
species, form.cleaned_data['sex'])
Treatment.objects.create(id=r[0], display_name=d, **form.cleaned_data)
else:
print('treatment', r[0:], form.errors.as_data())
@ -91,6 +100,17 @@ class Migration(migrations.Migration):
else:
print('alive-dead count', r[0:], form.errors.as_data())
for experiment in Experiment.objects.all():
experiment.collections.all().delete()
for r in c.execute('SELECT * FROM tbl_hash_collection_experiments;'):
c = Collection.objects.get(id=r[0])
e = Experiment.objects.get(id=r[1])
e.collections.add(c)
e.save()
def rollback(apps, schema_editor):
Flaw = apps.get_model('experiments', 'Flaw')
Experiment = apps.get_model('experiments', 'Experiment')
@ -103,9 +123,13 @@ class Migration(migrations.Migration):
Experiment, Flaw]:
model.objects.all().delete()
for experiment in Experiment.objects.all():
experiment.collections.all().delete()
dependencies = [
('experiments', '0008_treatment_display_name'),
('collections_ccdb', '0005_DATA_initial'),
('experiments', '0001_initial'),
('collections_ccdb', '0002_DATA_initial'),
]
operations = [

View file

@ -1,36 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import autoslug.fields
class Migration(migrations.Migration):
dependencies = [
('experiments', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='TreatmentType',
fields=[
('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)),
('name', models.CharField(max_length=200)),
('code', models.CharField(max_length=25, blank=True)),
('treatment_type', models.CharField(max_length=50, blank=True)),
('placement', models.CharField(max_length=25, blank=True)),
('description', models.CharField(max_length=255, blank=True)),
('sort_order', models.IntegerField(null=True, blank=True)),
('slug', autoslug.fields.AutoSlugField(populate_from='name', editable=False)),
('experiment', models.ForeignKey(null=True, blank=True, to='experiments.Experiment')),
],
options={
'ordering': ['sort_order'],
},
),
migrations.AlterUniqueTogether(
name='treatmenttype',
unique_together=set([('experiment', 'name')]),
),
]

View file

@ -1,29 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('misc', '0001_initial'),
('species', '0003_collectionspecies'),
('locations', '0002_remove_site_fk_dupes'),
('experiments', '0002_treatment_type'),
]
operations = [
migrations.CreateModel(
name='Treatment',
fields=[
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
('sex', models.CharField(max_length=25)),
('container', models.ForeignKey(blank=True, null=True, to='misc.Container')),
('flaw', models.ForeignKey(blank=True, null=True, to='experiments.Flaw')),
('species', models.ForeignKey(to='species.Species')),
('study_location', models.ForeignKey(to='locations.StudyLocation')),
('treatment_type', models.ForeignKey(to='experiments.TreatmentType')),
],
),
]

View file

@ -1,31 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('experiments', '0003_treatment'),
]
operations = [
migrations.CreateModel(
name='TreatmentReplicate',
fields=[
('id', models.AutoField(verbose_name='ID', auto_created=True, primary_key=True, serialize=False)),
('name', models.CharField(max_length=50)),
('setup_date', models.DateField(null=True, blank=True)),
('setup_time', models.TimeField(null=True, blank=True)),
('setup_sample_size', models.IntegerField(null=True, blank=True)),
('mass_g', models.FloatField(null=True, blank=True)),
('flaw', models.ForeignKey(null=True, to='experiments.Flaw', blank=True)),
('treatment', models.ForeignKey(to='experiments.Treatment')),
],
),
migrations.AlterUniqueTogether(
name='treatmentreplicate',
unique_together=set([('treatment', 'name', 'setup_date', 'setup_time')]),
),
]

View file

@ -1,26 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('experiments', '0004_treatment_replicate'),
]
operations = [
migrations.CreateModel(
name='AliveDeadCount',
fields=[
('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)),
('status_date', models.DateField()),
('status_time', models.TimeField(blank=True, null=True)),
('count_alive', models.IntegerField(blank=True, null=True)),
('count_dead', models.IntegerField(blank=True, null=True)),
('flaw', models.ForeignKey(to='experiments.Flaw', blank=True, null=True)),
('treatment_replicate', models.ForeignKey(to='experiments.TreatmentReplicate')),
],
),
]

View file

@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('collections_ccdb', '0001_initial'),
('experiments', '0005_alivedeadcount'),
]
operations = [
migrations.AddField(
model_name='experiment',
name='collections',
field=models.ManyToManyField(to='collections_ccdb.Collection'),
),
]

View file

@ -1,24 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('experiments', '0006_experiment_collections'),
]
operations = [
migrations.AlterModelOptions(
name='alivedeadcount',
options={'verbose_name': 'Alive-dead Count'},
),
migrations.AddField(
model_name='treatmentreplicate',
name='display_name',
field=models.CharField(editable=False, max_length=255, default='x'),
preserve_default=False,
),
]

View file

@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('experiments', '0007_treatment_replicates_display'),
]
operations = [
migrations.AddField(
model_name='treatment',
name='display_name',
field=models.CharField(editable=False, default='x', max_length=255),
preserve_default=False,
),
]

View file

@ -1,38 +0,0 @@
from django.db import migrations
from ccdb.utils.data import get_data_sources
class Migration(migrations.Migration):
def migrate(apps, schema_editor):
sources = get_data_sources()
if not sources:
return
c = sources['db0']
Collection = apps.get_model('collections_ccdb', 'Collection')
Experiment = apps.get_model('experiments', 'Experiment')
for experiment in Experiment.objects.all():
experiment.collections.all().delete()
for r in c.execute('SELECT * FROM tbl_hash_collection_experiments;'):
c = Collection.objects.get(id=r[0])
e = Experiment.objects.get(id=r[1])
e.collections.add(c)
e.save()
def rollback(apps, schema_editor):
Experiment = apps.get_model('experiments', 'Experiment')
for experiment in Experiment.objects.all():
experiment.collections.all().delete()
dependencies = [
('experiments', '0009_DATA_initial'),
]
operations = [
migrations.RunPython(migrate, rollback),
]

View file

@ -1,74 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('experiments', '0010_DATA_collections_experiments'),
]
operations = [
migrations.AlterField(
model_name='alivedeadcount',
name='flaw',
field=models.ForeignKey(null=True, to='experiments.Flaw', related_name='alive_dead_counts', blank=True),
),
migrations.AlterField(
model_name='alivedeadcount',
name='treatment_replicate',
field=models.ForeignKey(to='experiments.TreatmentReplicate', related_name='alive_dead_counts'),
),
migrations.AlterField(
model_name='experiment',
name='flaw',
field=models.ForeignKey(null=True, to='experiments.Flaw', related_name='experiments', blank=True),
),
migrations.AlterField(
model_name='protocolattachment',
name='experiment',
field=models.ForeignKey(to='experiments.Experiment', related_name='protocols'),
),
migrations.AlterField(
model_name='treatment',
name='container',
field=models.ForeignKey(null=True, to='misc.Container', related_name='treatments', blank=True),
),
migrations.AlterField(
model_name='treatment',
name='flaw',
field=models.ForeignKey(null=True, to='experiments.Flaw', related_name='treatments', blank=True),
),
migrations.AlterField(
model_name='treatment',
name='species',
field=models.ForeignKey(to='species.Species', related_name='treatments'),
),
migrations.AlterField(
model_name='treatment',
name='study_location',
field=models.ForeignKey(to='locations.StudyLocation', related_name='treatments'),
),
migrations.AlterField(
model_name='treatment',
name='treatment_type',
field=models.ForeignKey(to='experiments.TreatmentType', related_name='treatments'),
),
migrations.AlterField(
model_name='treatmentreplicate',
name='flaw',
field=models.ForeignKey(null=True, to='experiments.Flaw', related_name='treatment_replicates', blank=True),
),
migrations.AlterField(
model_name='treatmentreplicate',
name='treatment',
field=models.ForeignKey(to='experiments.Treatment', related_name='treatment_replicates'),
),
migrations.AlterField(
model_name='treatmenttype',
name='experiment',
field=models.ForeignKey(null=True, to='experiments.Experiment', related_name='treatment_types', blank=True),
),
]