mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
114 lines
4.3 KiB
Python
114 lines
4.3 KiB
Python
import uuid
|
|
|
|
from django.db import models
|
|
|
|
from insights.models.scoping.root_mixin import TeamScopedRootMixin
|
|
from insights.utils import generate_short_id
|
|
|
|
MIN_CPU_CORES = 0.25
|
|
MAX_CPU_CORES = 8.0
|
|
MIN_MEMORY_GB = 0.5
|
|
MAX_MEMORY_GB = 16.0
|
|
|
|
|
|
class StreamlitApp(TeamScopedRootMixin):
|
|
# `objects` (TeamScopedManager) inherited from TeamScopedRootMixin is fail-closed for
|
|
# explicit user code. `all_teams` is the unscoped sibling for Django framework internals
|
|
# (related-object access, prefetch_related, DRF class-body querysets) — Meta's
|
|
# default_manager_name routes _default_manager/_base_manager there. Same pattern as
|
|
# products/signals.
|
|
all_teams = models.Manager() # noqa: DJ012
|
|
|
|
# nosemgrep: prefer-uuid7-django-pk -- TODO: migrate to uuid7 or clarify intent
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
short_id = models.CharField(max_length=12, blank=True, default=generate_short_id)
|
|
team = models.ForeignKey("insights.Team", on_delete=models.CASCADE)
|
|
name = models.CharField(max_length=255)
|
|
description = models.TextField(blank=True, default="")
|
|
|
|
active_version = models.ForeignKey(
|
|
"StreamlitAppVersion",
|
|
null=True,
|
|
blank=True,
|
|
on_delete=models.SET_NULL,
|
|
related_name="+",
|
|
)
|
|
|
|
cpu_cores = models.FloatField(default=0.5)
|
|
memory_gb = models.FloatField(default=1)
|
|
|
|
# Reset to zero on a healthy run so transient failures don't ratchet the cap.
|
|
restart_count = models.PositiveIntegerField(default=0)
|
|
|
|
deleted = models.BooleanField(default=False)
|
|
deleted_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
created_by = models.ForeignKey("insights.User", on_delete=models.SET_NULL, null=True, blank=True)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
class Meta:
|
|
default_manager_name = "all_teams"
|
|
constraints = [
|
|
models.UniqueConstraint(
|
|
fields=["team", "short_id"],
|
|
condition=models.Q(deleted=False),
|
|
name="streamlit_apps_app_unique_active_short_id_per_team",
|
|
),
|
|
]
|
|
|
|
def __str__(self) -> str:
|
|
return self.name
|
|
|
|
|
|
class StreamlitAppVersion(models.Model):
|
|
# nosemgrep: prefer-uuid7-django-pk -- TODO: migrate to uuid7 or clarify intent
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
app = models.ForeignKey(StreamlitApp, on_delete=models.CASCADE, related_name="versions")
|
|
version_number = models.PositiveIntegerField()
|
|
|
|
zip_file = models.CharField(max_length=500)
|
|
zip_hash = models.CharField(max_length=64)
|
|
|
|
snapshot_id = models.CharField(max_length=255, null=True, blank=True)
|
|
snapshot_created_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
created_by = models.ForeignKey("insights.User", on_delete=models.SET_NULL, null=True, blank=True)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
class Meta:
|
|
unique_together = ("app", "version_number")
|
|
ordering = ["-version_number"]
|
|
|
|
def __str__(self) -> str:
|
|
return f"{self.app.name} v{self.version_number}"
|
|
|
|
|
|
class StreamlitAppSandbox(models.Model):
|
|
class Status(models.TextChoices):
|
|
STARTING = "starting", "Starting"
|
|
RUNNING = "running", "Running"
|
|
STOPPING = "stopping", "Stopping"
|
|
STOPPED = "stopped", "Stopped"
|
|
ERROR = "error", "Error"
|
|
|
|
# nosemgrep: prefer-uuid7-django-pk -- TODO: migrate to uuid7 or clarify intent
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
app = models.OneToOneField(StreamlitApp, on_delete=models.CASCADE, related_name="sandbox")
|
|
version = models.ForeignKey(StreamlitAppVersion, on_delete=models.SET_NULL, null=True, blank=True)
|
|
|
|
sandbox_id = models.CharField(max_length=255)
|
|
status = models.CharField(max_length=20, choices=Status, default=Status.STARTING)
|
|
|
|
last_error = models.TextField(blank=True, default="")
|
|
|
|
started_at = models.DateTimeField(null=True, blank=True)
|
|
last_activity_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
# The row is reused in place across lifecycles, so this drifts. Use
|
|
# started_at (refreshed on each attempt) for "this attempt began" logic.
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
def __str__(self) -> str:
|
|
return f"{self.app.name} sandbox ({self.status})"
|