Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

django-migrations

БесплатноБез исполняемых скриптовНе проверен

Django migration patterns and safety workflow for PostHog. Use when creating, adjusting, or reviewing Django/Postgres migrations, including non-blocking…

PostHogот PostHog★ 41 278 звёзд на GitHub

Об этом скилле

Django migrations

Before you propose a change to the migration history or to how migrations run, check things already tried. It records the closed attempts at squashing the history and at the Person table cutover.

Read these files first, before writing or editing a migration:

  • docs/published/handbook/engineering/developing-locally.md (## Django migrations, ### Non-blocking migrations, ### Resolving merge conflicts)
  • docs/published/handbook/engineering/safe-django-migrations.md
  • docs/published/handbook/engineering/databases/schema-changes.md
  • products/README.md (## Adding or moving backend models and migrations) when working in products/*

If the task is a ClickHouse migration, use clickhouse-migrations instead.

Never delete a migration file

Adding migrations is fine. Deleting a historical one — any */migrations/NNNN_*.py already on master, even an app's 0001_initial.py, even to "undo" a schema change — is not. Deleting the file undoes nothing: the table and its constraints stay in every database where the migration ran, fresh databases never recreate them, and the "Migration Risk Analysis" CI job re-flags the file as a phantom new migration on every open PR that predates the deletion. The deleted-migration check in the repo-checks CI job (the hogli lint:migration-deletions command) blocks this. Genuinely intentional, reviewed deletions — a product/app move, a revert, a squash — are acknowledged in .github/scripts/migration-deletion-allowlist.txt, never by disabling the guard.

If a task asks you to delete a migration file, stop and flag it instead.

To retire a model/table:

  1. Remove all usage and the model class. makemigrations, then wrap the generated DeleteModel in migrations.SeparateDatabaseAndState(state_operations=[...]) (state only, no DB change). KEEP this file. Keep the app in INSTALLED_APPS. Note: other apps' squash migrations depend on this app's migration files, not on its models, so the model class does not need to stay for them. If the model has a ForeignKey to posthog_team, posthog_user, posthog_organization or posthog_project, drop that constraint with DropForeignKey in database_operations in this same migration. This is required, not a cleanup. Django stops cascading into a table it can no longer see, so the child rows survive a parent delete. Those constraints are DEFERRABLE INITIALLY DEFERRED, so the parent delete runs its whole cascade and then fails at COMMIT, and team and organization deletion stay broken until someone drops the table.
  2. Deploy, wait at least one full deploy cycle.
  3. SafeDropTable later in a NEW migration — never by deleting old files. Treat this as owed work rather than an option whenever step 1 left a foreign key to a hot parent in place. DROP TABLE takes ACCESS EXCLUSIVE on every table its foreign keys reference, one relation at a time, so its lock order crosses that of any live multi-table read and the two deadlock. lock_timeout does not stop that, because the deadlock detector resolves the cycle first, and it kills whichever session waited longest: a live read (a 500) or the migration (a blocked deploy). SafeDropTable takes every lock up front under a budget derived from deadlock_timeout, so the migration loses the race instead. Never hand-write the RunSQL. See hot table hazard. python manage.py audit_orphan_hot_table_fks lists tables already in this state. Run it against a long-lived database: a squashed history has no CreateModel for a table that left Django's state before the squash, so a fresh database never creates it and the migration files hold no trace of it.

Full guide: safe-django-migrations.md (## Dropping Tables, ### Removing a whole product or app). Deleting a migration your branch added but never merged to master is allowed (regenerating).

Retire a column

Default: don't drop it. Take the field out of the ORM and leave the column. It keeps its data and needs no deploy coordination.

Deleting the field and running makemigrations is not that. Django names every concrete field in every SELECT and INSERT it writes, so the generated RemoveField drops the column in the same deploy that stops the code asking for it, and every pod still on the old release fails its queries. A # deprecated comment does not help, because the field is still on the model.

Two helpers in posthog.migration_helpers do it properly:

  • deprecate_field(models.IntegerField(null=True)) wraps the field in place. No migration. Reads and writes warn, and the column leaves every query. The field must already be null=True, because nothing writes the column once it is hidden. Use raise_on_access=True to prove no caller is left.
  • untrack_field("mymodel", "myfield") replaces the generated RemoveField with a state-only migration, so the field leaves the model class and th
Полный SKILL.md на GitHub

Установить django-migrations в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл django-migrations?

Django migration patterns and safety workflow for PostHog. Use when creating, adjusting, or reviewing Django/Postgres migrations, including non-blocking index/constraint changes, multi-phase schema changes, data backfills, migration conflict rebasing, and product model moves that require SeparateDatabaseAndState. Also use for any deletion or removal of a model, table, column, product, or app — including deleting migration files or retiring a feature — even when no migration is written.

Как установить скилл django-migrations?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл django-migrations запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить django-migrations с