81 lines
2.8 KiB
Python
81 lines
2.8 KiB
Python
# Generated by Django 4.1.3 on 2023-01-31 20:01
|
|
|
|
from datetime import date
|
|
|
|
from django.db import migrations, models
|
|
import django.db.models.deletion
|
|
|
|
from semver import VersionInfo
|
|
|
|
|
|
def migrate_version(apps, schema_editor):
|
|
CertificationVersion = apps.get_model("paperwork", "CertificationVersion")
|
|
for certification_version in CertificationVersion.objects.all():
|
|
if certification_version.version is None:
|
|
semver = VersionInfo.parse("0.0.0")
|
|
elif " - " in certification_version.version:
|
|
version, _, approval_date = certification_version.version.partition(" - ")
|
|
semver = VersionInfo.parse(version)
|
|
certification_version.approval_date = date.fromisoformat(approval_date)
|
|
else:
|
|
semver = VersionInfo.parse("0.0.1")
|
|
certification_version.prerelease = certification_version.version
|
|
|
|
certification_version.major = semver.major
|
|
certification_version.minor = semver.minor
|
|
certification_version.patch = semver.patch
|
|
certification_version.save()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
("paperwork", "0009_rename_department_list_moderator_flag_to_shop_lead_flag"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AddField(
|
|
model_name="certificationversion",
|
|
name="major",
|
|
field=models.PositiveSmallIntegerField(default=0),
|
|
preserve_default=False,
|
|
),
|
|
migrations.AddField(
|
|
model_name="certificationversion",
|
|
name="minor",
|
|
field=models.PositiveSmallIntegerField(default=0),
|
|
preserve_default=False,
|
|
),
|
|
migrations.AddField(
|
|
model_name="certificationversion",
|
|
name="patch",
|
|
field=models.PositiveSmallIntegerField(default=0),
|
|
preserve_default=False,
|
|
),
|
|
migrations.AddField(
|
|
model_name="certificationversion",
|
|
name="prerelease",
|
|
field=models.CharField(blank=True, max_length=255),
|
|
),
|
|
migrations.AddField(
|
|
model_name="certificationversion",
|
|
name="approval_date",
|
|
field=models.DateField(blank=True, null=True),
|
|
),
|
|
migrations.RunPython(migrate_version, atomic=True),
|
|
migrations.RemoveConstraint(
|
|
model_name="certificationversion",
|
|
name="unique_certification_version",
|
|
),
|
|
migrations.AddConstraint(
|
|
model_name="certificationversion",
|
|
constraint=models.UniqueConstraint(
|
|
fields=("definition", "major", "minor", "patch", "prerelease"),
|
|
name="unique_certification_version",
|
|
),
|
|
),
|
|
migrations.RemoveField(
|
|
model_name="certificationversion",
|
|
name="version",
|
|
),
|
|
]
|