cmsmanage/paperwork/migrations/0002_add_certification_version_model.py

88 lines
2.9 KiB
Python
Raw Permalink Normal View History

# (Partially) Generated by Django 4.0.2 on 2022-02-04 18:01
import django.db.models.deletion
from django.db import migrations, models
def migrate_certification_version_forward(apps, schema_editor):
db_alias = schema_editor.connection.alias
Certification = apps.get_model("paperwork", "Certification")
CertificationVersion = apps.get_model("paperwork", "CertificationVersion")
for certification in Certification.objects.using(db_alias).all():
(version, _) = CertificationVersion.objects.using(db_alias).get_or_create(
definition=certification.certification, version=certification.version
)
certification.certification_version = version
certification.save()
class Migration(migrations.Migration):
dependencies = [
2022-02-11 13:48:47 -05:00
("paperwork", "0001_initial"),
]
operations = [
migrations.CreateModel(
2022-02-11 13:48:47 -05:00
name="CertificationVersion",
fields=[
2022-02-11 13:48:47 -05:00
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"version",
models.CharField(
blank=True, db_column="Version", max_length=255, null=True
),
),
(
"definition",
models.ForeignKey(
db_column="Certification",
on_delete=django.db.models.deletion.PROTECT,
to="paperwork.certificationdefinition",
),
),
],
),
migrations.AddConstraint(
2022-02-11 13:48:47 -05:00
model_name="certificationversion",
constraint=models.UniqueConstraint(
fields=("definition", "version"), name="unique_certification_version"
),
),
migrations.AddField(
2022-02-11 13:48:47 -05:00
model_name="certification",
name="certification_version",
field=models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="paperwork.certificationversion",
null=True,
),
),
migrations.RunPython(migrate_certification_version_forward),
migrations.AlterField(
2022-02-11 13:48:47 -05:00
model_name="certification",
name="certification_version",
field=models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="paperwork.certificationversion",
),
),
migrations.RemoveField(
2022-02-11 13:48:47 -05:00
model_name="certification",
name="certification",
),
migrations.RemoveField(
2022-02-11 13:48:47 -05:00
model_name="certification",
name="version",
),
]