Daybook: a self-hosted, multi-user Django + DRF app where agents, scripts, or people publish artifacts and each logged-in user browses their own time-ordered, label-filterable feed. This squashes prior local development history (kept privately on a separate branch) into a single clean starting point for the public repository. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
from pathlib import Path
|
|
|
|
from django.conf import settings
|
|
from django.db import migrations
|
|
|
|
|
|
def backfill(apps, schema_editor):
|
|
Artifact = apps.get_model("artifacts", "Artifact")
|
|
User = apps.get_model("auth", "User")
|
|
UserProfile = apps.get_model("artifacts", "UserProfile")
|
|
|
|
root = Path(settings.ARTIFACTS_ROOT)
|
|
for artifact in Artifact.objects.all():
|
|
total = 0
|
|
primary = root / artifact.path
|
|
if primary.exists():
|
|
total += primary.stat().st_size
|
|
if artifact.kind == "markdown":
|
|
sidecar = primary.with_suffix(".md")
|
|
if sidecar.exists():
|
|
total += sidecar.stat().st_size
|
|
if artifact.size_bytes != total:
|
|
artifact.size_bytes = total
|
|
artifact.save(update_fields=["size_bytes"])
|
|
|
|
default_quota = 1024 * 1024 * 1024 # 1 GB
|
|
for user in User.objects.all():
|
|
UserProfile.objects.get_or_create(user=user, defaults={"quota_bytes": default_quota})
|
|
|
|
|
|
def noop_reverse(apps, schema_editor):
|
|
pass
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
("artifacts", "0009_quota_and_keep"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(backfill, noop_reverse),
|
|
]
|