[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M757X4AKKQKBQTKDG0MJFCWC":3,"skill-same:01M757X4AKKQKBQTKDG0MJFCWC":74},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":45,"commitSha":46,"skillDirectory":47,"forksCount":48,"repositoryHtmlUrl":49,"repositoryHomepageUrl":50,"ownerHtmlUrl":51,"ownerBlogUrl":6,"ownerDescription":52,"updatedAt":53,"install":54,"resources":67},"01M757X4AKKQKBQTKDG0MJFCWC","alembic-postgres-migrations",null,"Use when debugging Alembic Postgres migration failures.","lukemcqueen\u002Fsteadfaste-fleet","lukemcqueen","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F405240?v=4","01M757MHPAGRXTJAT46SKZP98R","Luke McQueen","01M757MHPZ573KP8DT9GB8SBQ7",4,"MIT","https:\u002F\u002Fgithub.com\u002Flukemcqueen\u002Fsteadfaste-fleet\u002Fblob\u002Fmain\u002Fskills\u002Fdevops\u002Falembic-postgres-migrations\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: alembic-postgres-migrations\ndescription: Use when debugging Alembic Postgres migration failures.\nversion: 1.1.0\ncategory: devops\nauthor: Steadfaste Fleet\nlicense: MIT\nplatforms: [linux, macos]\nmetadata:\n  hermes:\n    tags: [alembic, sqlalchemy, postgres, migrations, schema, enums, ddl]\n    category: devops\n    related_skills: [dockerized-stack-recovery, root-cause-debugging]\n    aliases: [alembic-enum-double-create]\n---\n\n# Alembic Postgres Migrations\n\nAuthor, review, and debug Alembic migrations for SQLAlchemy + PostgreSQL backends.\n\n## When to Use\n\n- Writing or reviewing an Alembic migration (any schema change)\n- A migration fails on a fresh\u002Fempty database: `DuplicateObject`, `type \"X\" already exists`, `relation \"X\" already exists`\n- A containerized API crash-loops in its entrypoint's `alembic upgrade head` step\n- Schema drift — DB state doesn't match migration history\n\n## Core Rules\n\n1. **One enum creation path per migration.** A PostgreSQL enum type can be created two ways in SQLAlchemy:\n   - Explicit: `sa.Enum(\"a\",\"b\", name=\"my_enum\").create(op.get_bind())`\n   - Implicit: a column typed `sa.Enum(..., name=\"my_enum\", create_constraint=True)` — the `create_constraint=True` flag ALSO emits `CREATE TYPE` during `op.create_table` (via the table's `_on_table_create` → `CreateEnumType` event).\n   Doing BOTH in one migration fails on a fresh DB with `psycopg2.errors.DuplicateObject: type \"my_enum\" already exists` — the explicit create succeeds, then the table creation tries to create the type a second time. **Pick one path.** Prefer the column definitions (drop the explicit `.create()` calls). If you keep explicit creates, the columns must not re-create the type.\n\n2. **Fresh-DB failures roll back the WHOLE chain.** Alembic assumes transactional DDL on Postgres: if migration m15 fails, the DDL from m10–m14 in that run is UNDONE and `alembic_version` stays at the last committed revision (e.g. m10). Never trust partial \"Running upgrade …\" log lines as progress — the whole batch rolled back. Tables and enums created earlier in the same failed run will NOT exist afterward.\n\n3. **Verify DB state with psql before theorizing.** The api's own error message can mislead (it re-runs the chain every restart, so logs interleave multiple attempts):\n   - `SELECT version_num FROM alembic_version;` — where the chain actually stopped\n   - `SELECT typname FROM pg_type WHERE typname LIKE '\u003Cprefix>%';` — whether enum types exist (absent after rollback)\n   - `\\dt` — which tables exist\n   Get the container name right first (`docker ps` — compose names aren't `project-service-1` if `container_name:` is set).\n\n4. **Fix the migration file, never hand-stamp the DB.** `INSERT INTO alembic_version` or dropping types manually only defers the failure to the next fresh checkout\u002Fvolume\u002FCI run. The migration must be idempotent enough to run clean on an empty database — that's the contract.\n\n5. **Test through the real entrypoint.** `alembic upgrade` from the repo isn't the shipping path; the container entrypoint that runs `alembic upgrade head` on every start is. Restart that container and watch its logs. For speed on a baked image, hot-fix via `docker cp` (see `dockerized-stack-recovery`); for durability, rebuild the image.\n\n6. **Enums named in column types must match the model.** The migration's column Enum (`name=\"notification_type\"`) and the ORM model's `Enum(NotificationType, name=\"notification_type\")` must agree on values — drift surfaces as opaque failures at query time, not at migration time.\n\n## Pitfalls\n\n### Column Name Shadowing SQLAlchemy Utility Functions\n\nA column named `text` on any model shadows `sqlalchemy.sql.text()` — the\naliased `from sqlalchemy.sql import text` in the module is inaccessible because\nthe column binding wins. This surfaces as a `TypeError: 'Column' object is not\ncallable` at import time (since SQLAlchemy eagerly evaluates class bodies).\n\n**Pattern:**\n```python\nfrom sqlalchemy import Column, Text\nfrom sqlalchemy.sql import func, text      # ← text() is available here\n\nclass Translation(Base):\n    text = Column(Text, nullable=False)     # ← shadows text() above\n    canonical = Column(Boolean, server_default=text(\"false\"))  # TypeError!\n```\n\n**Fix:** import with an alias that won't collide:\n```python\nfrom sqlalchemy.sql import func, text as sql_text\n\ncanonical = Column(Boolean, server_default=sql_text(\"false\"))\n```\n\n**Scope:** Any column name that matches a commonly-imported sqlalchemy.sql\nfunction — `func`, `text`, `literal`, `case`, `cast`, `type_`, `select` —\ncould shadow the utility. The `text` collision is the most frequent because\n`text` (data) and `text()` (SQL expression) are both ubiquitous.\n\n**Detection:** The API container crash-loops on startup with `TypeError:\n'Column' object is not callable` pointed at the model line. The migration\n`env.py` won't even import. Check the model file for column names matching\nSQLAlchemy function imports.\n\n### Migration DAG Fork Resolution\n\nWhen two migrations share the same `down_revision`, alembic detects multiple\nheads and `alembic upgrade head` refuses to proceed. To find the actual DB\nhead and relinearize:\n\n1. List every migration's revision and down_revision:\n   ```bash\n   for f in migrations\u002Fversions\u002F*.py; do\n     r=$(grep -E '^revision' \"$f\" | head -1 | sed -E 's\u002F.*\"([^\"]+)\".*\u002F\\1\u002F')\n     d=$(grep -E '^down_revision' \"$f\" | head -1 | sed -E 's\u002F.*\"([^\"]+)\".*\u002F\\1\u002F')\n     echo \"$r  \u003C- $d   ($(basename $f))\"\n   done\n   ```\n2. Compare against the DB's actual head (`alembic current` from the running\n   container — note the database may be behind the repo).\n3. The corrective migration's `down_revision` must point to the DB's actual\n   current revision, not the repo's newest head. This creates a single linear\n   chain.\n4. Verify: `alembic heads` returns exactly one revision, and `alembic upgrade\n   head` from a fresh DB applies all migrations.\n\n## Review Checklist (for other people's migrations)\n\n- [ ] Would this migration run clean on an EMPTY database? (fresh volume, CI, new checkout)\n- [ ] Any explicit `sa.Enum(...).create()` that duplicates a column-level enum with `create_constraint=True`?\n- [ ] Does `downgrade()` drop every enum\u002Ftable the upgrade creates (and in dependency-safe order)?\n- [ ] Single head — `alembic heads` returns exactly one revision; two devs branching = merge revision needed\n- [ ] Build-time guards: `check-heads.py`-style gate in CI\u002FDockerfile catches fork-merge issues before runtime\n\n## References\n\n- `references\u002Ffresh-db-migration-recovery.md` — worked example: the notification_type DuplicateObject crash-loop, full diagnosis sequence, and the fix pattern\n","# Alembic Postgres Migrations\n\nAuthor, review, and debug Alembic migrations for SQLAlchemy + PostgreSQL backends.\n\n## When to Use\n\n- Writing or reviewing an Alembic migration (any schema change)\n- A migration fails on a fresh\u002Fempty database: `DuplicateObject`, `type \"X\" already exists`, `relation \"X\" already exists`\n- A containerized API crash-loops in its entrypoint's `alembic upgrade head` step\n- Schema drift — DB state doesn't match migration history\n\n## Core Rules\n\n1. **One enum creation path per migration.** A PostgreSQL enum type can be created two ways in SQLAlchemy:\n   - Explicit: `sa.Enum(\"a\",\"b\", name=\"my_enum\").create(op.get_bind())`\n   - Implicit: a column typed `sa.Enum(..., name=\"my_enum\", create_constraint=True)` — the `create_constraint=True` flag ALSO emits `CREATE TYPE` during `op.create_table` (via the table's `_on_table_create` → `CreateEnumType` event).\n   Doing BOTH in one migration fails on a fresh DB with `psycopg2.errors.DuplicateObject: type \"my_enum\" already exists` — the explicit create succeeds, then the table creation tries to create the type a second time. **Pick one path.** Prefer the column definitions (drop the explicit `.create()` calls). If you keep explicit creates, the columns must not re-create the type.\n\n2. **Fresh-DB failures roll back the WHOLE chain.** Alembic assumes transactional DDL on Postgres: if migration m15 fails, the DDL from m10–m14 in that run is UNDONE and `alembic_version` stays at the last committed revision (e.g. m10). Never trust partial \"Running upgrade …\" log lines as progress — the whole batch rolled back. Tables and enums created earlier in the same failed run will NOT exist afterward.\n\n3. **Verify DB state with psql before theorizing.** The api's own error message can mislead (it re-runs the chain every restart, so logs interleave multiple attempts):\n   - `SELECT version_num FROM alembic_version;` — where the chain actually stopped\n   - `SELECT typname FROM pg_type WHERE typname LIKE '\u003Cprefix>%';` — whether enum types exist (absent after rollback)\n   - `\\dt` — which tables exist\n   Get the container name right first (`docker ps` — compose names aren't `project-service-1` if `container_name:` is set).\n\n4. **Fix the migration file, never hand-stamp the DB.** `INSERT INTO alembic_version` or dropping types manually only defers the failure to the next fresh checkout\u002Fvolume\u002FCI run. The migration must be idempotent enough to run clean on an empty database — that's the contract.\n\n5. **Test through the real entrypoint.** `alembic upgrade` from the repo isn't the shipping path; the container entrypoint that runs `alembic upgrade head` on every start is. Restart that container and watch its logs. For speed on a baked image, hot-fix via `docker cp` (see `dockerized-stack-recovery`); for durability, rebuild the image.\n\n6. **Enums named in column types must match the model.** The migration's column Enum (`name=\"notification_type\"`) and the ORM model's `Enum(NotificationType, name=\"notification_type\")` must agree on values — drift surfaces as opaque failures at query time, not at migration time.\n\n## Pitfalls\n\n### Column Name Shadowing SQLAlchemy Utility Functions\n\nA column named `text` on any model shadows `sqlalchemy.sql.text()` — the\naliased `from sqlalchemy.sql import text` in the module is inaccessible because\nthe column binding wins. This surfaces as a `TypeError: 'Column' object is not\ncallable` at import time (since SQLAlchemy eagerly evaluates class bodies).\n\n**Pattern:**\n```python\nfrom sqlalchemy import Column, Text\nfrom sqlalchemy.sql import func, text      # ← text() is available here\n\nclass Translation(Base):\n    text = Column(Text, nullable=False)     # ← shadows text() above\n    canonical = Column(Boolean, server_default=text(\"false\"))  # TypeError!\n```\n\n**Fix:** import with an alias that won't collide:\n```python\nfrom sqlalchemy.sql import func, text as sql_text\n\ncanonical = Column(Boolean, server_default=sql_text(\"false\"))\n```\n\n**Scope:** Any column name that matches a commonly-imported sqlalchemy.sql\nfunction — `func`, `text`, `literal`, `case`, `cast`, `type_`, `select` —\ncould shadow the utility. The `text` collision is the most frequent because\n`text` (data) and `text()` (SQL expression) are both ubiquitous.\n\n**Detection:** The API container crash-loops on startup with `TypeError:\n'Column' object is not callable` pointed at the model line. The migration\n`env.py` won't even import. Check the model file for column names matching\nSQLAlchemy function imports.\n\n### Migration DAG Fork Resolution\n\nWhen two migrations share the same `down_revision`, alembic detects multiple\nheads and `alembic upgrade head` refuses to proceed. To find the actual DB\nhead and relinearize:\n\n1. List every migration's revision and down_revision:\n   ```bash\n   for f in migrations\u002Fversions\u002F*.py; do\n     r=$(grep -E '^revision' \"$f\" | head -1 | sed -E 's\u002F.*\"([^\"]+)\".*\u002F\\1\u002F')\n     d=$(grep -E '^down_revision' \"$f\" | head -1 | sed -E 's\u002F.*\"([^\"]+)\".*\u002F\\1\u002F')\n     echo \"$r  \u003C- $d   ($(basename $f))\"\n   done\n   ```\n2. Compare against the DB's actual head (`alembic current` from the running\n   container — note the database may be behind the repo).\n3. The corrective migration's `down_revision` must point to the DB's actual\n   current revision, not the repo's newest head. This creates a single linear\n   chain.\n4. Verify: `alembic heads` returns exactly one revision, and `alembic upgrade\n   head` from a fresh DB applies all migrations.\n\n## Review Checklist (for other people's migrations)\n\n- [ ] Would this migration run clean on an EMPTY database? (fresh volume, CI, new checkout)\n- [ ] Any explicit `sa.Enum(...).create()` that duplicates a column-level enum with `create_constraint=True`?\n- [ ] Does `downgrade()` drop every enum\u002Ftable the upgrade creates (and in dependency-safe order)?\n- [ ] Single head — `alembic heads` returns exactly one revision; two devs branching = merge revision needed\n- [ ] Build-time guards: `check-heads.py`-style gate in CI\u002FDockerfile catches fork-merge issues before runtime\n\n## References\n\n- `references\u002Ffresh-db-migration-recovery.md` — worked example: the notification_type DuplicateObject crash-loop, full diagnosis sequence, and the fix pattern\n",{"name":5,"author":24,"license":15,"version":25,"category":26,"metadata":27,"platforms":42,"description":7},"Steadfaste Fleet","1.1.0","devops",{"hermes":28},{"tags":29,"aliases":37,"category":26,"related_skills":39},[30,31,32,33,34,35,36],"alembic","sqlalchemy","postgres","migrations","schema","enums","ddl",[38],"alembic-enum-double-create",[40,41],"dockerized-stack-recovery","root-cause-debugging",[43,44],"linux","macos","main","2e6aa8d15ab0a366c90be54f61bf9c6e97015e83","skills\u002Fdevops\u002Falembic-postgres-migrations",1,"https:\u002F\u002Fgithub.com\u002Flukemcqueen\u002Fsteadfaste-fleet","steadfaste.com","https:\u002F\u002Fgithub.com\u002Flukemcqueen","AI Architect | Building Hermes Cortex: governed multi-agent AI for autonomous software engineering | Enterprise Tech Consultant","2026-11-14 22:33:34",{"source":8,"skillName":5,"commands":55,"prompt":65,"zipAvailable":66},[56,59,62],{"tool":57,"command":58},"npx","npx skills add lukemcqueen\u002Fsteadfaste-fleet --skill alembic-postgres-migrations",{"tool":60,"command":61},"bunx","bunx skills add lukemcqueen\u002Fsteadfaste-fleet --skill alembic-postgres-migrations",{"tool":63,"command":64},"pnpm","pnpm dlx skills add lukemcqueen\u002Fsteadfaste-fleet --skill alembic-postgres-migrations","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flukemcqueen\u002Fsteadfaste-fleet\u002Fblob\u002Fmain\u002Fskills\u002Fdevops\u002Falembic-postgres-migrations\u002FSKILL.md",true,[68],{"path":69,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":72,"sourceHtmlUrl":73},"references\u002Ffresh-db-migration-recovery.md","REFERENCE","参考文档",3671,"https:\u002F\u002Fgithub.com\u002Flukemcqueen\u002Fsteadfaste-fleet\u002Fblob\u002Fmain\u002Fskills\u002Fdevops\u002Falembic-postgres-migrations\u002Freferences\u002Ffresh-db-migration-recovery.md",[75,83,90,97,104,111],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":82},"01M7DXY4G8NSVB59K8B6S2AQNP","macbook-linux-maintenance","Legacy MacBook Linux fixes: GPU wedge, reboot hang, thermal.","https:\u002F\u002Fgithub.com\u002Flukemcqueen\u002Fsteadfaste-fleet\u002Fblob\u002Fmain\u002Fskills\u002Fdevops\u002Fmacbook-linux-maintenance\u002FSKILL.md",[],[],"2026-11-15 14:19:17",{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":82},"01M7DXXYJCXFJ3TGB84ZQ8KFE6","governance-regression-triage","Triage a host's governance issues: what changed.","https:\u002F\u002Fgithub.com\u002Flukemcqueen\u002Fsteadfaste-fleet\u002Fblob\u002Fmain\u002Fskills\u002Fdevops\u002Fgovernance-regression-triage\u002FSKILL.md",[],[],{"skillNo":91,"name":92,"nameZh":6,"description":93,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":82},"01M7DXXSAP1G8FDRJAMXQGBBMK","enforcement-immutability","Use when enforcement files lose their immutable flag.","https:\u002F\u002Fgithub.com\u002Flukemcqueen\u002Fsteadfaste-fleet\u002Fblob\u002Fmain\u002Fskills\u002Fdevops\u002Fenforcement-immutability\u002FSKILL.md",[],[],{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":82},"01M78SSDQVRYX64Y16X32TC0NS","steadfaste-fleet-repo-deploy","Use when committing to the steadfaste-fleet repo.","https:\u002F\u002Fgithub.com\u002Flukemcqueen\u002Fsteadfaste-fleet\u002Fblob\u002Fmain\u002Fskills\u002Fdevops\u002Fsteadfaste-fleet-repo-deploy\u002FSKILL.md",[],[],{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":82},"01M78SS928F3R2RJAYVW4E30CE","steadfaste-fleet-maintenance","Maintain an installed Steadfaste Fleet instance — update both the upstream Hermes Agent and the fleet repo layer, merge diverged histories, sync skills safely, and troubleshoot common issues. Covers the dual-update workflow (hermes update + fleet-update.sh), encrypted brain data backup, mycortex import, and recovery techniques.","https:\u002F\u002Fgithub.com\u002Flukemcqueen\u002Fsteadfaste-fleet\u002Fblob\u002Fmain\u002Fskills\u002Fdevops\u002Fsteadfaste-fleet-maintenance\u002FSKILL.md",[],[],{"skillNo":112,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":82},"01M78SP1CHW0T0BWE5ZT6JBPX8","fleet-preflight","DEPRECATED alias — merged into survey-before-action (2026-08-20). Load survey-before-action instead; its \"Repo-Specific Pre-Flight\" section covers git search, Hermes boundary, and deployment verification.","https:\u002F\u002Fgithub.com\u002Flukemcqueen\u002Fsteadfaste-fleet\u002Fblob\u002Fmain\u002Fskills\u002Fdevops\u002Ffleet-preflight\u002FSKILL.md",[],[]]