mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-24 12:32:42 -06:00
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
# Generated by Django 5.2.5 on 2025-09-09 16:48
|
|
|
|
from django.db import migrations, models
|
|
|
|
|
|
def get_active(apps, schema_editor):
|
|
from django.core.cache import cache
|
|
ConfigRevision = apps.get_model('core', 'ConfigRevision')
|
|
version = None
|
|
revision = None
|
|
|
|
try:
|
|
version = cache.get('config_version')
|
|
except Exception:
|
|
pass
|
|
|
|
if version:
|
|
revision = ConfigRevision.objects.filter(pk=version).first()
|
|
else:
|
|
revision = ConfigRevision.objects.order_by('-created').first()
|
|
|
|
if revision:
|
|
revision.active = True
|
|
revision.save()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('core', '0015_remove_redundant_indexes'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AddField(
|
|
model_name='configrevision',
|
|
name='active',
|
|
field=models.BooleanField(default=False),
|
|
),
|
|
migrations.RunPython(code=get_active, reverse_code=migrations.RunPython.noop),
|
|
migrations.AddConstraint(
|
|
model_name='configrevision',
|
|
constraint=models.UniqueConstraint(
|
|
condition=models.Q(('active', True)), fields=('active',), name='unique_active_config_revision'
|
|
),
|
|
),
|
|
]
|