Add project schema version
This commit is contained in:
parent
e22ee600b9
commit
73ab153b02
4 changed files with 24 additions and 5 deletions
15
clips/migrations/0006_project_schema_version.py
Normal file
15
clips/migrations/0006_project_schema_version.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("clips", "0005_footage_stream_alter_footage_video"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="project",
|
||||
name="schema_version",
|
||||
field=models.PositiveIntegerField(default=1),
|
||||
),
|
||||
]
|
||||
|
|
@ -199,14 +199,14 @@ class Block(models.Model):
|
|||
class Project(models.Model):
|
||||
"""Tier 1: the document's root.
|
||||
|
||||
`seq` is the monotonic project version docs/architecture.md asks for. Every
|
||||
write bumps it, and a client that sees `seq > local + 1` refetches — which is
|
||||
what makes staleness self-healing rather than permanent once there is a
|
||||
broadcast to miss.
|
||||
`schema_version` identifies the stored document format. `seq` counts writes
|
||||
to this particular project; it is not a format version. Every write bumps
|
||||
`seq`, and a client that sees `seq > local + 1` refetches once broadcasts exist.
|
||||
"""
|
||||
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
name = models.CharField(max_length=200, default="untitled")
|
||||
schema_version = models.PositiveIntegerField(default=1)
|
||||
seq = models.PositiveBigIntegerField(default=0)
|
||||
palette = models.CharField(max_length=64, default="arthur/default")
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
|
|
|
|||
|
|
@ -379,6 +379,7 @@ class DocumentTests(TestCase):
|
|||
self.assertEqual(5, len(response.json()["written"]))
|
||||
|
||||
loaded = self.client.get(f"/api/projects/{self.project.id}").json()
|
||||
self.assertEqual(1, loaded["schema_version"])
|
||||
self.assertEqual(1, len(loaded["clips"]))
|
||||
clip = loaded["clips"][0]
|
||||
self.assertEqual("c1", clip["cid"])
|
||||
|
|
|
|||
|
|
@ -571,6 +571,7 @@ def _project_json(project: Project):
|
|||
return {
|
||||
"id": str(project.id),
|
||||
"name": project.name,
|
||||
"schema_version": project.schema_version,
|
||||
"seq": project.seq,
|
||||
"palette": project.palette,
|
||||
"clips": clips,
|
||||
|
|
@ -583,7 +584,8 @@ def projects(request):
|
|||
return JsonResponse(
|
||||
{
|
||||
"projects": [
|
||||
{"id": str(p.id), "name": p.name, "seq": p.seq,
|
||||
{"id": str(p.id), "name": p.name,
|
||||
"schema_version": p.schema_version, "seq": p.seq,
|
||||
"updated": p.updated.isoformat()}
|
||||
for p in Project.objects.all()[:100]
|
||||
]
|
||||
|
|
@ -690,6 +692,7 @@ def _save(project: Project, data):
|
|||
return JsonResponse(
|
||||
{
|
||||
"id": str(project.id),
|
||||
"schema_version": project.schema_version,
|
||||
"seq": seq,
|
||||
"written": sorted(written),
|
||||
"removed": sorted(removed),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue