feat(nimbus): Add NimbusFeatureVersion model (#9812)

Because:

- we want to filter NimbusVersionedSchema based on its version; and
- having that information in the database makes it much easier to qeury

This commit:

- adds the NimbusFeatureVersion model.

Fixes #9811
This commit is contained in:
Barret Rennie 2023-11-22 13:33:33 -05:00 коммит произвёл GitHub
Родитель 4431d1a702
Коммит 254d73c610
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 73 добавлений и 3 удалений

Просмотреть файл

@ -0,0 +1,45 @@
# Generated by Django 3.2.23 on 2023-11-22 18:02
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("experiments", "0250_nimbusexperiment_qa_status"),
]
operations = [
migrations.CreateModel(
name="NimbusFeatureVersion",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("major", models.IntegerField()),
("minor", models.IntegerField()),
("patch", models.IntegerField()),
],
options={
"verbose_name": "Nimbus Feature Version",
"verbose_name_plural": "Nimbus Feature Versions",
"unique_together": {("major", "minor", "patch")},
},
),
migrations.AlterField(
model_name="nimbusversionedschema",
name="version",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="experiments.nimbusfeatureversion",
),
),
]

Просмотреть файл

@ -1245,13 +1245,30 @@ class NimbusFeatureConfig(models.Model):
return self.name
class NimbusFeatureVersion(models.Model):
major = models.IntegerField(null=False)
minor = models.IntegerField(null=False)
patch = models.IntegerField(null=False)
class Meta:
verbose_name = "Nimbus Feature Version"
verbose_name_plural = "Nimbus Feature Versions"
unique_together = ("major", "minor", "patch")
def __repr__(self): # pragma: no cover
return f"<NimbusFeatureVersion({self.major}, {self.minor}, {self.patch})>"
def __str__(self): # pragma: no cover
return f"{self.major}.{self.minor}.{self.patch}"
class NimbusVersionedSchema(models.Model):
feature_config = models.ForeignKey(
NimbusFeatureConfig,
related_name="schemas",
on_delete=models.CASCADE,
)
version = models.CharField(max_length=255, null=True)
version = models.ForeignKey(NimbusFeatureVersion, on_delete=models.CASCADE, null=True)
schema = models.TextField(blank=True, null=True)
sets_prefs = ArrayField(models.CharField(max_length=255, null=False, default=list))
@ -1260,12 +1277,20 @@ class NimbusVersionedSchema(models.Model):
verbose_name_plural = "Nimbus Versioned Schemas"
unique_together = ("feature_config", "version")
def __str__(self): # pragma: no cover
def __repr__(self): # pragma: no cover
return (
f"<NimbusVersionedSchema(feature_config_id={self.feature_config_id}, "
f"version={self.version!r})>"
f"version={self.version})>"
)
def __str__(self): # pragma: no cover
as_str = f"NimbusVersionedSchema for {self.feature_config_id}"
if self.version is not None:
as_str = f"{as_str} at {self.version}"
return as_str
class NimbusChangeLogManager(models.Manager["NimbusChangeLog"]):
def latest_change(self):