Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(file-system): retire the orphaned PersistedFolder model (#97092)

posthog[bot]3061dcbcb1bf
diff --git a/.semgrep/rules/security/idor-team-scoped-models.yaml b/.semgrep/rules/security/idor-team-scoped-models.yaml
index 78d1994043ab..fc086763065c 100644
--- a/.semgrep/rules/security/idor-team-scoped-models.yaml
+++ b/.semgrep/rules/security/idor-team-scoped-models.yaml
@@ -1227,7 +1227,6 @@ rules:
|InsightViewed
|KernelRuntime
|MCPServerInstallation
- |PersistedFolder
|Reminder
|SessionRecordingViewed
|UserFacetSettings
@@ -1301,7 +1300,6 @@ rules:
|FileSystemViewLog
|InsightViewed
|KernelRuntime
- |PersistedFolder
|Reminder
|SessionRecordingViewed
|UserFacetSettings
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index 4a73a86d2678..35abc11859f2 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -39331,31 +39331,6 @@
"required": ["event"],
"type": "object"
},
- "PersistedFolder": {
- "additionalProperties": false,
- "properties": {
- "created_at": {
- "type": "string"
- },
- "id": {
- "type": "string"
- },
- "path": {
- "type": "string"
- },
- "protocol": {
- "type": "string"
- },
- "type": {
- "type": "string"
- },
- "updated_at": {
- "type": "string"
- }
- },
- "required": ["id", "type", "protocol", "path", "created_at", "updated_at"],
- "type": "object"
- },
"PersonMetadataPropertyFilter": {
"additionalProperties": false,
"properties": {
diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.ts
index bc8c9cb0ca2e..c9f7230e4e07 100644
--- a/frontend/src/queries/schema/schema-general.ts
+++ b/frontend/src/queries/schema/schema-general.ts
@@ -5187,15 +5187,6 @@ export interface FileSystemViewLogEntry {
viewed_at: string
}
-export interface PersistedFolder {
- id: string
- type: string
- protocol: string
- path: string
- created_at: string
- updated_at: string
-}
-
export type DataWarehouseManagedViewsetKind = 'revenue_analytics'
export type InsightQueryNode =
diff --git a/posthog/migrations/1349_delete_persistedfolder_from_state.py b/posthog/migrations/1349_delete_persistedfolder_from_state.py
new file mode 100644
index 000000000000..c696d2f50207
--- /dev/null
+++ b/posthog/migrations/1349_delete_persistedfolder_from_state.py
@@ -0,0 +1,28 @@
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("posthog", "1348_drop_organization_is_hipaa_column"),
+ ]
+
+ operations = [
+ migrations.SeparateDatabaseAndState(
+ # The table stays for now, so a rollback still finds it. A later migration drops it.
+ state_operations=[
+ migrations.DeleteModel(name="PersistedFolder"),
+ ],
+ database_operations=[
+ # Django no longer knows the table, so it cannot include it when tests truncate
+ # posthog_team and posthog_user, and Postgres refuses to truncate a table a foreign
+ # key points to. Both statements are IF EXISTS, so a bin/migrate retry is a no-op.
+ migrations.RunSQL(
+ sql="""
+ ALTER TABLE posthog_persistedfolder DROP CONSTRAINT IF EXISTS posthog_persistedfolder_team_id_a8bb8f3e_fk_posthog_team_id;
+ ALTER TABLE posthog_persistedfolder DROP CONSTRAINT IF EXISTS posthog_persistedfolder_user_id_dee73fbd_fk_posthog_user_id;
+ """,
+ reverse_sql=migrations.RunSQL.noop,
+ ),
+ ],
+ ),
+ ]
diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txt
index bc15f7d0cac7..8717eaf8ac17 100644
--- a/posthog/migrations/max_migration.txt
+++ b/posthog/migrations/max_migration.txt
@@ -1 +1 @@
-1348_drop_organization_is_hipaa_column
+1349_delete_persistedfolder_from_state
diff --git a/posthog/models/__init__.py b/posthog/models/__init__.py
index 12c25a085068..e5df080f1aec 100644
--- a/posthog/models/__init__.py
+++ b/posthog/models/__init__.py
@@ -27,7 +27,6 @@ from products.event_definitions.backend.models import EventDefinition
from products.event_definitions.backend.models import EventProperty
from .file_system.file_system import FileSystem
from .file_system.file_system_view_log import FileSystemViewLog
-from .file_system.persisted_folder import PersistedFolder
from .file_system.user_product_list import UserProductList
from .filters import Filter, RetentionFilter
from .group import Group
@@ -109,7 +108,6 @@ __all__ = [
"EventProperty",
"FileSystem",
"FileSystemViewLog",
- "PersistedFolder",
"UserProductList",
"Filter",
"Group",
diff --git a/posthog/models/file_system/persisted_folder.py b/posthog/models/file_system/persisted_folder.py
deleted file mode 100644
index a536ac29d1e2..000000000000
--- a/posthog/models/file_system/persisted_folder.py
+++ /dev/null
@@ -1,68 +0,0 @@
-from django.db import models
-from django.db.models import Value
-from django.db.models.expressions import F
-from django.db.models.functions import Coalesce
-from django.utils import timezone
-
-from posthog.models.file_system.constants import DEFAULT_SURFACE
-from posthog.models.team import Team
-from posthog.models.user import User
-from posthog.models.utils import uuid7
-
-
-class PersistedFolder(models.Model):
- """
- Per-user, per-team persisted folder.
-
- A single user can have exactly one row of a given `type`
- (home, pinned, …) inside each team.
- """
-
- id: models.UUIDField = models.UUIDField(primary_key=True, default=uuid7, editable=False)
- team: models.ForeignKey = models.ForeignKey(Team, on_delete=models.CASCADE)
- user: models.ForeignKey = models.ForeignKey(User, on_delete=models.CASCADE)
-
- TYPE_HOME = "home"
- TYPE_PINNED = "pinned"
- TYPE_CUSTOM_PRODUCTS = "custom_products"
- type: models.CharField = models.CharField(
- max_length=32,
- choices=[
- (TYPE_HOME, "Home"),
- (TYPE_PINNED, "Pinned"),
- (TYPE_CUSTOM_PRODUCTS, "Custom Products"),
- ],
- )
-
- protocol: models.CharField = models.CharField(max_length=64, default="products://")
- path: models.TextField = models.TextField(blank=True, default="")
-
- # Product surface this folder belongs to (e.g. "web", "desktop"). NULL == DEFAULT_SURFACE.
- # Unlike FileSystem items, a folder `type` (home, pinned, …) is NOT surface-exclusive — each
- # surface has its own "home" — so surface is part of the uniqueness below. The constraint
- # coalesces NULL to the default surface, matching the NULL == "web" rule used for reads, so a
- # legacy NULL row and an explicit "web" row can never both exist for the same (team, user, type).
- surface: models.CharField = models.CharField(max_length=100, null=True, blank=True)
-
- created_at: models.DateTimeField = models.DateTimeField(default=timezone.now, editable=False)
- updated_at: models.DateTimeField = models.DateTimeField(auto_now=True)
-
- class Meta:
- constraints = [
- models.UniqueConstraint(
- F("team_id"),
- F("user_id"),
- F("type"),
- Coalesce(F("surface"), Value(DEFAULT_SURFACE)),
- name="posthog_pf_team_user_type_surface_uniq",
- ),
- ]
- indexes = [
- models.Index(F("team_id"), F("user_id"), name="posthog_pf_team_user"),
- models.Index(F("team_id"), F("user_id"), F("type"), name="posthog_pf_team_user_type"),
- ]
- verbose_name = "Persisted Folder"
- verbose_name_plural = "Persisted Folders"
-
- def __str__(self) -> str:
- return f"{self.team_id}:{self.user_id}:{self.type} → {self.protocol}{self.path}"
diff --git a/posthog/models/scoping/baseline_unmigrated.txt b/posthog/models/scoping/baseline_unmigrated.txt
index dcc75b01fcf3..fdbaf92571cd 100644
--- a/posthog/models/scoping/baseline_unmigrated.txt
+++ b/posthog/models/scoping/baseline_unmigrated.txt
@@ -124,7 +124,6 @@ Notebook
NotificationEvent
ObjectMediaPreview
OptOutSyncConfig
-PersistedFolder
PluginConfig
ProductTour
ProjectSecretAPIKey
diff --git a/posthog/schema.py b/posthog/schema.py
index ea0bb9221876..02b913e1a55e 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -2534,18 +2534,6 @@ class PathsV2StepSource(BaseModel):
)
-class PersistedFolder(BaseModel):
- model_config = ConfigDict(
- extra="forbid",
- )
- created_at: str
- id: str
- path: str
- protocol: str
- type: str
- updated_at: str
-
-
class PersonType(BaseModel):
model_config = ConfigDict(
extra="forbid",