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(devex): move batch imports to managed migrations product (#61445)

Julian Bezf9283cd91a5b
diff --git a/posthog/api/__init__.py b/posthog/api/__init__.py
index 48b7626dfc48..a7cee12bf3a0 100644
--- a/posthog/api/__init__.py
+++ b/posthog/api/__init__.py
@@ -24,9 +24,9 @@ from products.batch_exports.backend.api import (
batch_export as batch_exports,
file_download,
)
-from products.batch_exports.backend.api.batch_imports import BatchImportViewSet
from products.dashboards.backend.api import dashboard, dashboard_templates
from products.exports.backend.api import exports
+from products.managed_migrations.backend.api.batch_imports import BatchImportViewSet
from products.notebooks.backend.api.notebook import NotebookViewSet
from ee.api.quota_limits import QuotaLimitsViewSet
diff --git a/posthog/settings/web.py b/posthog/settings/web.py
index 476f240b5111..f05cff3a82f1 100644
--- a/posthog/settings/web.py
+++ b/posthog/settings/web.py
@@ -86,6 +86,7 @@ PRODUCTS_APPS = [
"products.annotations.backend.apps.AnnotationsConfig",
"products.batch_exports.backend.apps.BatchExportsConfig",
"products.engineering_analytics.backend.apps.EngineeringAnalyticsConfig",
+ "products.managed_migrations.backend.apps.ManagedMigrationsConfig",
]
INSTALLED_APPS = [
diff --git a/products/batch_exports/backend/migrations/0004_migrate_managed_migrations_models.py b/products/batch_exports/backend/migrations/0004_migrate_managed_migrations_models.py
new file mode 100644
index 000000000000..6a186f345784
--- /dev/null
+++ b/products/batch_exports/backend/migrations/0004_migrate_managed_migrations_models.py
@@ -0,0 +1,56 @@
+# Generated by Django 5.2.14 on 2026-06-03 16:07
+
+from django.db import migrations
+
+MODELS_TO_MOVE = ("batchimport",)
+
+
+def _move_content_types(apps, schema_editor, from_label, to_label):
+ """Move ContentTypes between apps, handling duplicates idempotently.
+
+ If the target (app_label, model) already exists (e.g. Django auto-created it,
+ or a prior failed attempt left one behind), merge permissions onto the target
+ and delete the source to avoid a unique-constraint violation. Uses the
+ migration's own connection alias for multi-DB safety.
+ """
+ db_alias = schema_editor.connection.alias
+ ContentType = apps.get_model("contenttypes", "ContentType")
+ Permission = apps.get_model("auth", "Permission")
+
+ for model_name in MODELS_TO_MOVE:
+ source = ContentType.objects.using(db_alias).filter(app_label=from_label, model=model_name).first()
+ target = ContentType.objects.using(db_alias).filter(app_label=to_label, model=model_name).first()
+
+ if source and target:
+ Permission.objects.using(db_alias).filter(content_type=source).update(content_type=target)
+ source.delete(using=db_alias)
+ elif source:
+ source.app_label = to_label
+ source.save(using=db_alias)
+
+
+def update_content_types(apps, schema_editor):
+ _move_content_types(apps, schema_editor, "batch_exports", "managed_migrations")
+
+
+def reverse_content_types(apps, schema_editor):
+ _move_content_types(apps, schema_editor, "managed_migrations", "batch_exports")
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("batch_exports", "0003_alter_batchexportdestination_type"),
+ ("managed_migrations", "0001_migrate_managed_migrations_models"),
+ ]
+
+ operations = [
+ migrations.SeparateDatabaseAndState(
+ state_operations=[
+ migrations.DeleteModel(
+ name="BatchImport",
+ ),
+ ],
+ database_operations=[],
+ ),
+ migrations.RunPython(update_content_types, reverse_content_types),
+ ]
diff --git a/products/batch_exports/backend/migrations/max_migration.txt b/products/batch_exports/backend/migrations/max_migration.txt
index 9619a5d6c573..9e0ef6f5da0c 100644
--- a/products/batch_exports/backend/migrations/max_migration.txt
+++ b/products/batch_exports/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0003_alter_batchexportdestination_type
+0004_migrate_managed_migrations_models
diff --git a/products/batch_exports/backend/models/__init__.py b/products/batch_exports/backend/models/__init__.py
index 16d2752fa5c6..c6b1f105f738 100644
--- a/products/batch_exports/backend/models/__init__.py
+++ b/products/batch_exports/backend/models/__init__.py
@@ -7,7 +7,6 @@ from .batch_export import (
BatchExportRun,
DayOfWeek,
)
-from .batch_imports import BatchImport, ContentType, DateRangeExportSource
__all__ = [
"BatchExport",
@@ -16,8 +15,5 @@ __all__ = [
"BatchExportFileDownload",
"BatchExportOnDemand",
"BatchExportRun",
- "BatchImport",
- "ContentType",
- "DateRangeExportSource",
"DayOfWeek",
]
diff --git a/products/batch_exports/frontend/generated/api.schemas.ts b/products/batch_exports/frontend/generated/api.schemas.ts
index b02cffef8e58..1e5008c45dd8 100644
--- a/products/batch_exports/frontend/generated/api.schemas.ts
+++ b/products/batch_exports/frontend/generated/api.schemas.ts
@@ -1502,74 +1502,6 @@ export interface FileDownloadBatchExportOnDemandApi {
data_interval_end: string
}
-/**
- * * `completed` - Completed
- * `failed` - Failed
- * `paused` - Paused
- * `running` - Running
- */
-export type BatchImportStatusEnumApi = (typeof BatchImportStatusEnumApi)[keyof typeof BatchImportStatusEnumApi]
-
-export const BatchImportStatusEnumApi = {
- Completed: 'completed',
- Failed: 'failed',
- Paused: 'paused',
- Running: 'running',
-} as const
-
-/**
- * @nullable
- */
-export type BatchImportApiCreatedBy = { [key: string]: unknown } | null
-
-/**
- * Serializer for BatchImport model
- */
-export interface BatchImportApi {
- readonly id: string
- readonly team_id: number
- readonly created_at: string
- readonly updated_at: string
- readonly state: unknown
- /** @nullable */
- readonly created_by: BatchImportApiCreatedBy
- readonly status: BatchImportStatusEnumApi
- /** @nullable */
- readonly display_status_message: string | null
- readonly import_config: unknown
-}
-
-export interface PaginatedBatchImportListApi {
- count: number
- /** @nullable */
- next?: string | null
- /** @nullable */
- previous?: string | null
- results: BatchImportApi[]
-}
-
-/**
- * @nullable
- */
-export type PatchedBatchImportApiCreatedBy = { [key: string]: unknown } | null
-
-/**
- * Serializer for BatchImport model
- */
-export interface PatchedBatchImportApi {
- readonly id?: string
- readonly team_id?: number
- readonly created_at?: string
- readonly updated_at?: string
- readonly state?: unknown
- /** @nullable */
- readonly created_by?: PatchedBatchImportApiCreatedBy
- readonly status?: BatchImportStatusEnumApi
- /** @nullable */
- readonly display_status_message?: string | null
- readonly import_config?: unknown
-}
-
/**
* * `events` - events
*/
@@ -1811,38 +1743,3 @@ export type FileDownloadBatchExportsLogsRetrieveParams = {
*/
search?: string
}
-
-export type ManagedMigrationsListParams = {
- /**
- * Number of results to return per page.
- */
- limit?: number
- /**
- * The initial index from which to return the results.
- */
- offset?: number
- /**
- * Which field to use when ordering the results.
- */
- ordering?: string
- /**
- * A search term.
- */
- search?: string
- /**
- * * `completed` - Completed
- * `failed` - Failed
- * `paused` - Paused
- * `running` - Running
- */
- status?: ManagedMigrationsListStatus
-}
-
-export type ManagedMigrationsListStatus = (typeof ManagedMigrationsListStatus)[keyof typeof ManagedMigrationsListStatus]
-
-export const ManagedMigrationsListStatus = {
- Completed: 'completed',
- Failed: 'failed',
- Paused: 'paused',
- Running: 'running',
-} as const
diff --git a/products/batch_exports/frontend/generated/api.ts b/products/batch_exports/frontend/generated/api.ts
index e9ee25a70834..1786b484fc03 100644
--- a/products/batch_exports/frontend/generated/api.ts
+++ b/products/batch_exports/frontend/generated/api.ts
@@ -18,20 +18,16 @@ import type {
BatchExportsLogsRetrieveParams,
BatchExportsRunsListParams,
BatchExportsRunsLogsRetrieveParams,
- BatchImportApi,
CreateFileDownloadRequestApi,
CreateOutputApi,
FileDownloadBatchExportOnDemandApi,
FileDownloadBatchExportsListParams,
FileDownloadBatchExportsLogsRetrieveParams,
- ManagedMigrationsListParams,
PaginatedBatchExportBackfillListApi,
PaginatedBatchExportListApi,
PaginatedBatchExportRunListApi,
- PaginatedBatchImportListApi,
PaginatedListOutputListApi,
PatchedBatchExportRequestApi,
- PatchedBatchImportApi,
RetrieveFileDownloadResponseApi,
} from './api.schemas'
@@ -658,169 +654,3 @@ export const fileDownloadBatchExportsLogsRetrieve = async (
method: 'GET',
})
}
-
-export const getManagedMigrationsListUrl = (projectId: string, params?: ManagedMigrationsListParams) => {
- const normalizedParams = new URLSearchParams()
-
- Object.entries(params || {}).forEach(([key, value]) => {
- if (value !== undefined) {
- normalizedParams.append(key, value === null ? 'null' : value.toString())
- }
- })
-
- const stringifiedParams = normalizedParams.toString()
-
- return stringifiedParams.length > 0
- ? `/api/projects/${projectId}/managed_migrations/?${stringifiedParams}`
- : `/api/projects/${projectId}/managed_migrations/`
-}
-
-/**
- * List managed migrations using the response serializer
- */
-export const managedMigrationsList = async (
- projectId: string,
- params?: ManagedMigrationsListParams,
- options?: RequestInit
-): Promise<PaginatedBatchImportListApi> => {
- return apiMutator<PaginatedBatchImportListApi>(getManagedMigrationsListUrl(projectId, params), {
- ...options,
- method: 'GET',
- })
-}
-
-export const getManagedMigrationsCreateUrl = (projectId: string) => {
- return `/api/projects/${projectId}/managed_migrations/`
-}
-
-/**
- * Create a new managed migration/batch import.
- */
-export const managedMigrationsCreate = async (
- projectId: string,
- batchImportApi?: NonReadonly<BatchImportApi>,
- options?: RequestInit
-): Promise<BatchImportApi> => {
- return apiMutator<BatchImportApi>(getManagedMigrationsCreateUrl(projectId), {
- ...options,
- method: 'POST',
- headers: { 'Content-Type': 'application/json', ...options?.headers },
- body: JSON.stringify(batchImportApi),
- })
-}
-
-export const getManagedMigrationsRetrieveUrl = (projectId: string, id: string) => {
- return `/api/projects/${projectId}/managed_migrations/${id}/`
-}
-
-/**
- * Viewset for BatchImport model
- */
-export const managedMigrationsRetrieve = async (
- projectId: string,
- id: string,
- options?: RequestInit
-): Promise<BatchImportApi> => {
- return apiMutator<BatchImportApi>(getManagedMigrationsRetrieveUrl(projectId, id), {
- ...options,
- method: 'GET',
- })
-}
-
-export const getManagedMigrationsUpdateUrl = (projectId: string, id: string) => {
- return `/api/projects/${projectId}/managed_migrations/${id}/`
-}
-
-/**
- * Viewset for BatchImport model
- */
-export const managedMigrationsUpdate = async (
- projectId: string,
- id: string,
- batchImportApi?: NonReadonly<BatchImportApi>,
- options?: RequestInit
-): Promise<BatchImportApi> => {
- return apiMutator<BatchImportApi>(getManagedMigrationsUpdateUrl(projectId, id), {
- ...options,
- method: 'PUT',
- headers: { 'Content-Type': 'application/json', ...options?.headers },
- body: JSON.stringify(batchImportApi),
- })
-}
-
-export const getManagedMigrationsPartialUpdateUrl = (projectId: string, id: string) => {
- return `/api/projects/${projectId}/managed_migrations/${id}/`
-}
-
-/**
- * Viewset for BatchImport model
- */
-export const managedMigrationsPartialUpdate = async (
- projectId: string,
- id: string,
- patchedBatchImportApi?: NonReadonly<PatchedBatchImportApi>,
- options?: RequestInit
-): Promise<BatchImportApi> => {
- return apiMutator<BatchImportApi>(getManagedMigrationsPartialUpdateUrl(projectId, id), {
- ...options,
- method: 'PATCH',
- headers: { 'Content-Type': 'application/json', ...options?.headers },
- body: JSON.stringify(patchedBatchImportApi),
- })
-}
-
-export const getManagedMigrationsDestroyUrl = (projectId: string, id: string) => {
- return `/api/projects/${projectId}/managed_migrations/${id}/`
-}
-
-/**
- * Viewset for BatchImport model
- */
-export const managedMigrationsDestroy = async (projectId: string, id: string, options?: RequestInit): Promise<void> => {
- return apiMutator<void>(getManagedMigrationsDestroyUrl(projectId, id), {
- ...options,
- method: 'DELETE',
- })
-}
-
-export const getManagedMigrationsPauseCreateUrl = (projectId: string, id: string) => {
- return `/api/projects/${projectId}/managed_migrations/${id}/pause/`
-}
-
-/**
- * Pause a running batch import.
- */
-export const managedMigrationsPauseCreate = async (
- projectId: string,
- id: string,
- batchImportApi?: NonReadonly<BatchImportApi>,
- options?: RequestInit
-): Promise<BatchImportApi> => {
- return apiMutator<BatchImportApi>(getManagedMigrationsPauseCreateUrl(projectId, id), {
- ...options,
- method: 'POST',
- headers: { 'Content-Type': 'application/json', ...options?.headers },
- body: JSON.stringify(batchImportApi),
- })
-}
-
-export const getManagedMigrationsResumeCreateUrl = (projectId: string, id: string) => {
- return `/api/projects/${projectId}/managed_migrations/${id}/resume/`
-}
-
-/**
- * Resume a paused batch import.
- */
-export const managedMigrationsResumeCreate = async (
- projectId: string,
- id: string,
- batchImportApi?: NonReadonly<BatchImportApi>,
- options?: RequestInit
-): Promise<BatchImportApi> => {
- return apiMutator<BatchImportApi>(getManagedMigrationsResumeCreateUrl(projectId, id), {
- ...options,
- method: 'POST',
- headers: { 'Content-Type': 'application/json', ...options?.headers },
- body: JSON.stringify(batchImportApi),
- })
-}
diff --git a/products/batch_exports/frontend/generated/api.zod.ts b/products/batch_exports/frontend/generated/api.zod.ts
index 0d58e908052e..d22822f92cb5 100644
--- a/products/batch_exports/frontend/generated/api.zod.ts
+++ b/products/batch_exports/frontend/generated/api.zod.ts
@@ -1761,38 +1761,3 @@ export const FileDownloadBatchExportsCancelCreateBody = /* @__PURE__ */ zod
data_interval_end: zod.iso.datetime({ offset: true }),
})
.describe('Request shape for a FileDownload batch export on demand.')
-
-/**
- * Create a new managed migration/batch import.
- */
-export const ManagedMigrationsCreateBody = /* @__PURE__ */ zod
- .looseObject({})
- .describe('Serializer for BatchImport model')
-
-/**
- * Viewset for BatchImport model
- */
-export const ManagedMigrationsUpdateBody = /* @__PURE__ */ zod
- .looseObject({})
- .describe('Serializer for BatchImport model')
-
-/**
- * Viewset for BatchImport model
- */
-export const ManagedMigrationsPartialUpdateBody = /* @__PURE__ */ zod
- .looseObject({})
- .describe('Serializer for BatchImport model')
-
-/**
- * Pause a running batch import.
- */
-export const ManagedMigrationsPauseCreateBody = /* @__PURE__ */ zod
- .looseObject({})
- .describe('Serializer for BatchImport model')
-
-/**
- * Resume a paused batch import.
- */
-export const ManagedMigrationsResumeCreateBody = /* @__PURE__ */ zod
- .looseObject({})
- .describe('Serializer for BatchImport model')
diff --git a/products/batch_exports/mcp/tools.yaml b/products/batch_exports/mcp/tools.yaml
index e345b9d7d079..0227162d6be1 100644
--- a/products/batch_exports/mcp/tools.yaml
+++ b/products/batch_exports/mcp/tools.yaml
@@ -230,27 +230,3 @@ tools:
status is Completed, use the downloading-batch-export-files skill to download each file through the existing
REST download endpoint; the generated MCP download operation is intentionally not enabled because it is a
redirect to the file body.
- managed-migrations-create:
- operation: managed_migrations_create
- enabled: false
- managed-migrations-destroy:
- operation: managed_migrations_destroy
- enabled: false
- managed-migrations-list:
- operation: managed_migrations_list
- enabled: false
- managed-migrations-partial-update:
- operation: managed_migrations_partial_update
- enabled: false
- managed-migrations-pause-create:
- operation: managed_migrations_pause_create
- enabled: false
- managed-migrations-resume-create:
- operation: managed_migrations_resume_create
- enabled: false
- managed-migrations-retrieve:
- operation: managed_migrations_retrieve
- enabled: false
- managed-migrations-update:
- operation: managed_migrations_update
- enabled: false
diff --git a/products/batch_exports/backend/admin/__init__.py b/products/managed_migrations/backend/admin/__init__.py
similarity index 100%
rename from products/batch_exports/backend/admin/__init__.py
rename to products/managed_migrations/backend/admin/__init__.py
diff --git a/products/batch_exports/backend/admin/batch_imports.py b/products/managed_migrations/backend/admin/batch_imports.py
similarity index 97%
rename from products/batch_exports/backend/admin/batch_imports.py
rename to products/managed_migrations/backend/admin/batch_imports.py
index 9c403cb2e251..227630dc7af3 100644
--- a/products/batch_exports/backend/admin/batch_imports.py
+++ b/products/managed_migrations/backend/admin/batch_imports.py
@@ -1,7 +1,7 @@
from django import forms
from django.contrib import admin
-from products.batch_exports.backend.models.batch_imports import BatchImport
+from products.managed_migrations.backend.models.batch_imports import BatchImport
class BatchImportAdminForm(forms.ModelForm):
diff --git a/products/managed_migrations/backend/api/__init__.py b/products/managed_migrations/backend/api/__init__.py
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/products/batch_exports/backend/api/batch_imports.py b/products/managed_migrations/backend/api/batch_imports.py
similarity index 99%
rename from products/batch_exports/backend/api/batch_imports.py
rename to products/managed_migrations/backend/api/batch_imports.py
index 444fa6ec132e..bea8cedda316 100644
--- a/products/batch_exports/backend/api/batch_imports.py
+++ b/products/managed_migrations/backend/api/batch_imports.py
@@ -17,17 +17,17 @@ from posthog.api.documentation import _FallbackSerializer
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.shared import UserBasicSerializer
from posthog.models.activity_logging.activity_log import ActivityContextBase, Detail, changes_between, log_activity
-from posthog.models.activity_logging.batch_import_utils import (
- extract_batch_import_info,
- get_batch_import_created_by_info,
- get_batch_import_detail_name,
-)
from posthog.models.activity_logging.model_activity import get_current_user, get_was_impersonated
from posthog.models.signals import model_activity_signal, mutable_receiver
from posthog.models.user import User
from products.batch_exports.backend.api.batch_export import resolve_and_validate_url
-from products.batch_exports.backend.models.batch_imports import BatchImport, ContentType, DateRangeExportSource
+from products.managed_migrations.backend.models.batch_import_utils import (
+ extract_batch_import_info,
+ get_batch_import_created_by_info,
+ get_batch_import_detail_name,
+)
+from products.managed_migrations.backend.models.batch_imports import BatchImport, ContentType, DateRangeExportSource
class BatchImportSerializer(serializers.ModelSerializer):
diff --git a/products/managed_migrations/backend/api/test/__init__.py b/products/managed_migrations/backend/api/test/__init__.py
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/products/batch_exports/backend/api/test/test_batch_imports.py b/products/managed_migrations/backend/api/test/test_batch_imports.py
similarity index 99%
rename from products/batch_exports/backend/api/test/test_batch_imports.py
rename to products/managed_migrations/backend/api/test/test_batch_imports.py
index 61f2a2da7e73..3d354b03d453 100644
--- a/products/batch_exports/backend/api/test/test_batch_imports.py
+++ b/products/managed_migrations/backend/api/test/test_batch_imports.py
@@ -4,7 +4,7 @@ from posthog.test.base import APIBaseTest, BaseTest
from parameterized import parameterized
-from products.batch_exports.backend.models.batch_imports import BatchImport, BatchImportConfigBuilder, ContentType
+from products.managed_migrations.backend.models.batch_imports import BatchImport, BatchImportConfigBuilder, ContentType
class TestBatchImportModel(BaseTest):
diff --git a/products/managed_migrations/backend/migrations/0001_migrate_managed_migrations_models.py b/products/managed_migrations/backend/migrations/0001_migrate_managed_migrations_models.py
new file mode 100644
index 000000000000..37e5d9a0f0a7
--- /dev/null
+++ b/products/managed_migrations/backend/migrations/0001_migrate_managed_migrations_models.py
@@ -0,0 +1,72 @@
+# Generated by Django 5.2.14 on 2026-06-03 16:07
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+import posthog.models.utils
+import posthog.helpers.encrypted_fields
+
+
+class Migration(migrations.Migration):
+ initial = True
+
+ dependencies = [
+ ("posthog", "1207_migrate_ai_observability_models"),
+ ("batch_exports", "0003_alter_batchexportdestination_type"),
+ ]
+
+ operations = [
+ migrations.SeparateDatabaseAndState(
+ state_operations=[
+ migrations.CreateModel(
+ name="BatchImport",
+ fields=[
+ (
+ "id",
+ models.UUIDField(
+ default=posthog.models.utils.UUIDT,
+ editable=False,
+ primary_key=True,
+ serialize=False,
+ ),
+ ),
+ ("created_by_id", models.IntegerField(blank=True, null=True)),
+ ("created_at", models.DateTimeField(auto_now_add=True)),
+ ("updated_at", models.DateTimeField(auto_now=True)),
+ ("lease_id", models.TextField(blank=True, null=True)),
+ ("leased_until", models.DateTimeField(blank=True, null=True)),
+ (
+ "status",
+ models.TextField(
+ choices=[
+ ("completed", "Completed"),
+ ("failed", "Failed"),
+ ("paused", "Paused"),
+ ("running", "Running"),
+ ],
+ default="running",
+ ),
+ ),
+ ("status_message", models.TextField(blank=True, null=True)),
+ ("display_status_message", models.TextField(blank=True, null=True)),
+ ("state", models.JSONField(blank=True, null=True)),
+ ("import_config", models.JSONField()),
+ (
+ "secrets",
+ posthog.helpers.encrypted_fields.EncryptedJSONStringField(),
+ ),
+ ("backoff_attempt", models.IntegerField(default=0)),
+ ("backoff_until", models.DateTimeField(blank=True, null=True)),
+ (
+ "team",
+ models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="posthog.team"),
+ ),
+ ],
+ options={
+ "db_table": "posthog_batchimport",
+ },
+ ),
+ ],
+ database_operations=[],
+ )
+ ]
diff --git a/products/managed_migrations/backend/migrations/__init__.py b/products/managed_migrations/backend/migrations/__init__.py
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/products/managed_migrations/backend/migrations/max_migration.txt b/products/managed_migrations/backend/migrations/max_migration.txt
new file mode 100644
index 000000000000..9a52df6b05e6
--- /dev/null
+++ b/products/managed_migrations/backend/migrations/max_migration.txt
@@ -0,0 +1 @@
+0001_migrate_managed_migrations_models
diff --git a/products/managed_migrations/backend/models/__init__.py b/products/managed_migrations/backend/models/__init__.py
new file mode 100644
index 000000000000..d95af7472195
--- /dev/null
+++ b/products/managed_migrations/backend/models/__init__.py
@@ -0,0 +1,7 @@
+from .batch_imports import BatchImport, ContentType, DateRangeExportSource
+
+__all__ = [
+ "BatchImport",
+ "ContentType",
+ "DateRangeExportSource",
+]
diff --git a/posthog/models/activity_logging/batch_import_utils.py b/products/managed_migrations/backend/models/batch_import_utils.py
similarity index 100%
rename from posthog/models/activity_logging/batch_import_utils.py
rename to products/managed_migrations/backend/models/batch_import_utils.py
diff --git a/products/batch_exports/backend/models/batch_imports.py b/products/managed_migrations/backend/models/batch_imports.py
similarity index 100%
rename from products/batch_exports/backend/models/batch_imports.py
rename to products/managed_migrations/backend/models/batch_imports.py
diff --git a/products/managed_migrations/backend/tests/__init__.py b/products/managed_migrations/backend/tests/__init__.py
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/posthog/test/activity_logging/test_batch_import_activity_logging.py b/products/managed_migrations/backend/tests/test_batch_import_activity_logging.py
similarity index 98%
rename from posthog/test/activity_logging/test_batch_import_activity_logging.py
rename to products/managed_migrations/backend/tests/test_batch_import_activity_logging.py
index f87b37ca3549..c4cb0a89ded0 100644
--- a/posthog/test/activity_logging/test_batch_import_activity_logging.py
+++ b/products/managed_migrations/backend/tests/test_batch_import_activity_logging.py
@@ -1,6 +1,6 @@
from posthog.test.activity_log_utils import ActivityLogTestHelper
-from products.batch_exports.backend.models.batch_imports import BatchImport
+from products.managed_migrations.backend.models.batch_imports import BatchImport
class TestBatchImportActivityLogging(ActivityLogTestHelper):
diff --git a/products/managed_migrations/frontend/generated/api.schemas.ts b/products/managed_migrations/frontend/generated/api.schemas.ts
index 53112339e5be..50b1cb92ea3e 100644
--- a/products/managed_migrations/frontend/generated/api.schemas.ts
+++ b/products/managed_migrations/frontend/generated/api.schemas.ts
@@ -7,11 +7,6 @@
* PostHog API - generated
* OpenAPI spec version: 1.0.0
*/
-/**
- * @nullable
- */
-export type BatchImportApiCreatedBy = { [key: string]: unknown } | null
-
/**
* * `completed` - Completed
* `failed` - Failed
@@ -27,6 +22,11 @@ export const BatchImportStatusEnumApi = {
Running: 'running',
} as const
+/**
+ * @nullable
+ */
+export type BatchImportApiCreatedBy = { [key: string]: unknown } | null
+
/**
* Serializer for BatchImport model
*/
@@ -44,6 +44,15 @@ export interface BatchImportApi {
readonly import_config: unknown
}
+export interface PaginatedBatchImportListApi {
+ count: number
+ /** @nullable */
+ next?: string | null
+ /** @nullable */
+ previous?: string | null
+ results: BatchImportApi[]
+}
+
/**
* @nullable
*/
@@ -65,3 +74,38 @@ export interface PatchedBatchImportApi {
readonly display_status_message?: string | null
readonly import_config?: unknown
}
+
+export type ManagedMigrationsListParams = {
+ /**
+ * Number of results to return per page.
+ */
+ limit?: number
+ /**
+ * The initial index from which to return the results.
+ */
+ offset?: number
+ /**
+ * Which field to use when ordering the results.
+ */
+ ordering?: string
+ /**
+ * A search term.
+ */
+ search?: string
+ /**
+ * * `completed` - Completed
+ * `failed` - Failed
+ * `paused` - Paused
+ * `running` - Running
+ */
+ status?: ManagedMigrationsListStatus
+}
+
+export type ManagedMigrationsListStatus = (typeof ManagedMigrationsListStatus)[keyof typeof ManagedMigrationsListStatus]
+
+export const ManagedMigrationsListStatus = {
+ Completed: 'completed',
+ Failed: 'failed',
+ Paused: 'paused',
+ Running: 'running',
+} as const
diff --git a/products/managed_migrations/frontend/generated/api.ts b/products/managed_migrations/frontend/generated/api.ts
index efacf3acfdbf..4dbabe53b8a4 100644
--- a/products/managed_migrations/frontend/generated/api.ts
+++ b/products/managed_migrations/frontend/generated/api.ts
@@ -8,7 +8,12 @@ import { apiMutator } from '../../../../frontend/src/lib/api-orval-mutator'
* PostHog API - generated
* OpenAPI spec version: 1.0.0
*/
-import type { BatchImportApi, PatchedBatchImportApi } from './api.schemas'
+import type {
+ BatchImportApi,
+ ManagedMigrationsListParams,
+ PaginatedBatchImportListApi,
+ PatchedBatchImportApi,
+} from './api.schemas'
// https://stackoverflow.com/questions/49579094/typescript-conditional-types-filter-out-readonly-properties-pick-only-requir/49579497#49579497
type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B
@@ -27,6 +32,56 @@ type NonReadonly<T> = [T] extends [UnionToIntersection<T>]
}
: DistributeReadOnlyOverUnions<T>
+export const getManagedMigrationsListUrl = (projectId: string, params?: ManagedMigrationsListParams) => {
+ const normalizedParams = new URLSearchParams()
+
+ Object.entries(params || {}).forEach(([key, value]) => {
+ if (value !== undefined) {
+ normalizedParams.append(key, value === null ? 'null' : value.toString())
+ }
+ })
+
+ const stringifiedParams = normalizedParams.toString()
+
+ return stringifiedParams.length > 0
+ ? `/api/projects/${projectId}/managed_migrations/?${stringifiedParams}`
+ : `/api/projects/${projectId}/managed_migrations/`
+}
+
+/**
+ * List managed migrations using the response serializer
+ */
+export const managedMigrationsList = async (
+ projectId: string,
+ params?: ManagedMigrationsListParams,
+ options?: RequestInit
+): Promise<PaginatedBatchImportListApi> => {
+ return apiMutator<PaginatedBatchImportListApi>(getManagedMigrationsListUrl(projectId, params), {
+ ...options,
+ method: 'GET',
+ })
+}
+
+export const getManagedMigrationsCreateUrl = (projectId: string) => {
+ return `/api/projects/${projectId}/managed_migrations/`
+}
+
+/**
+ * Create a new managed migration/batch import.
+ */
+export const managedMigrationsCreate = async (
+ projectId: string,
+ batchImportApi?: NonReadonly<BatchImportApi>,
+ options?: RequestInit
+): Promise<BatchImportApi> => {
+ return apiMutator<BatchImportApi>(getManagedMigrationsCreateUrl(projectId), {
+ ...options,
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json', ...options?.headers },
+ body: JSON.stringify(batchImportApi),
+ })
+}
+
export const getManagedMigrationsRetrieveUrl = (projectId: string, id: string) => {
return `/api/projects/${projectId}/managed_migrations/${id}/`
}
diff --git a/products/managed_migrations/frontend/generated/api.zod.ts b/products/managed_migrations/frontend/generated/api.zod.ts
index b9087d7d8154..e2a13a1c186a 100644
--- a/products/managed_migrations/frontend/generated/api.zod.ts
+++ b/products/managed_migrations/frontend/generated/api.zod.ts
@@ -9,6 +9,13 @@
*/
import * as zod from 'zod'
+/**
+ * Create a new managed migration/batch import.
+ */
+export const ManagedMigrationsCreateBody = /* @__PURE__ */ zod
+ .looseObject({})
+ .describe('Serializer for BatchImport model')
+
/**
* Viewset for BatchImport model
*/
diff --git a/products/managed_migrations/package.json b/products/managed_migrations/package.json
index fede8244feba..430f02e7cd8c 100644
--- a/products/managed_migrations/package.json
+++ b/products/managed_migrations/package.json
@@ -1,7 +1,7 @@
{
"name": "@posthog/products-managed-migrations",
"scripts": {
- "backend:test": "echo 'No backend tests'"
+ "backend:test": "pytest -c ../../pytest.ini --rootdir ../.. backend/tests backend/api/test -v --tb=short"
},
"dependencies": {
"kea": "catalog:",
diff --git a/products/ruff.toml b/products/ruff.toml
index e605e568a453..afe5a61513ac 100644
--- a/products/ruff.toml
+++ b/products/ruff.toml
@@ -37,6 +37,7 @@ extend-select = ["ANN001", "ANN201", "ANN202", "ANN204"]
"feature_flags/backend/**" = ["ANN"]
"ai_observability/backend/**" = ["ANN"]
"logs/backend/**" = ["ANN"]
+"managed_migrations/backend/**" = ["ANN"]
"marketing_analytics/backend/**" = ["ANN"]
"messaging/backend/**" = ["ANN"]
"notebooks/backend/**" = ["ANN"]
@@ -81,6 +82,7 @@ extend-select = ["ANN001", "ANN201", "ANN202", "ANN204"]
"live_debugger/**" = ["PLC0415"]
"ai_observability/**" = ["PLC0415"]
"logs/**" = ["PLC0415"]
+"managed_migrations/**" = ["PLC0415"]
"marketing_analytics/**" = ["PLC0415"]
"mcp_analytics/**" = ["PLC0415"]
"mcp_store/**" = ["PLC0415"]
diff --git a/tach.toml b/tach.toml
index 0791d0e28cf9..ef1f13308395 100644
--- a/tach.toml
+++ b/tach.toml
@@ -88,6 +88,7 @@ depends_on = [
"products.live_debugger",
"products.ai_observability",
"products.logs",
+ "products.managed_migrations",
"products.marketing_analytics",
"products.mcp_store",
"products.messaging",
@@ -352,7 +353,10 @@ layer = "modules"
[[modules]]
path = "products.managed_migrations"
-depends_on = []
+depends_on = [
+ "posthog",
+ "products.batch_exports",
+]
layer = "modules"
[[modules]]