mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-18 10:16:34 +00:00
Update migration and arrange for activation changes
This commit is contained in:
parent
42857b15b2
commit
0074199845
@ -3,6 +3,27 @@
|
|||||||
from django.db import migrations, models
|
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):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
@ -15,10 +36,11 @@ class Migration(migrations.Migration):
|
|||||||
name='active',
|
name='active',
|
||||||
field=models.BooleanField(default=False),
|
field=models.BooleanField(default=False),
|
||||||
),
|
),
|
||||||
|
migrations.RunPython(code=get_active, reverse_code=migrations.RunPython.noop),
|
||||||
migrations.AddConstraint(
|
migrations.AddConstraint(
|
||||||
model_name='configrevision',
|
model_name='configrevision',
|
||||||
constraint=models.UniqueConstraint(
|
constraint=models.UniqueConstraint(
|
||||||
condition=models.Q(('actvive', True)), fields=('active',), name='unique_active_config_revision'
|
condition=models.Q(('active', True)), fields=('active',), name='unique_active_config_revision'
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -41,7 +41,7 @@ class ConfigRevision(models.Model):
|
|||||||
constraints = [
|
constraints = [
|
||||||
models.UniqueConstraint(
|
models.UniqueConstraint(
|
||||||
fields=('active',),
|
fields=('active',),
|
||||||
condition=models.Q(actvive=True),
|
condition=models.Q(active=True),
|
||||||
name='unique_active_config_revision',
|
name='unique_active_config_revision',
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
@ -78,4 +78,4 @@ class ConfigRevision(models.Model):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_active(self):
|
def is_active(self):
|
||||||
return cache.get('config_version') == self.pk
|
return self.active
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user