Token导航 LogoToken导航TokenDH.com
研究检索只读unknown未标认证来源可访问许可证需确认审计未展示

database-migration数据库迁移

Agent Skill

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

总安装

282

周安装

12

下载量

99
Local Agent

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:database-migration(数据库迁移)
来源仓库:https://smithery.ai
仓库路径:database-migration
安装命令:
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。当前暂无明确安装命令,请以来源页面说明为准。

简介

database-migration 用于辅助数据库表结构、查询语句和迁移脚本维护,支持数据管理任务。

  • 适合让 Agent 分析 schema、编写 SQL、排查查询问题或生成迁移建议。
  • 使用时需明确数据库类型、连接环境和目标表,区分只读与分析变更。
  • 涉及删除、更新或批量导入时,应优先 dry-run 或事务保护,避免误操作。
  • 建议在使用前评估其对数据库安全和一致性的影响。

SKILL.md

You help create and manage database migrations using Alembic for the QA Team Portal backend.

When to Use This Skill

  • Creating new database tables (new SQLAlchemy models)
  • Adding/removing/modifying columns in existing tables
  • Adding indexes or constraints
  • Data migrations (transforming existing data)
  • Reviewing migration files before applying

Prerequisites

  • SQLAlchemy models exist in backend/app/models/
  • Models are imported in backend/app/db/base.py
  • Alembic is initialized (backend/alembic/ directory exists)
  • Database connection configured in .env

Workflow

1. Create Migration

cd backend

# Auto-generate migration from model changes
uv run alembic revision --autogenerate -m "descriptive message"

# Or create empty migration for data changes
uv run alembic revision -m "migrate existing data"

2. Review Generated Migration

  • Open the new file in backend/alembic/versions/
  • Check upgrade() function for forward migration
  • Check downgrade() function for rollback
  • Verify changes match your intent
  • Add any custom logic if needed (e.g., data transformation)

3. Apply Migration

# Apply to database
uv run alembic upgrade head

# Or apply one version
uv run alembic upgrade +1

4. Verify Migration

# Check current version
uv run alembic current

# View migration history
uv run alembic history --verbose

Common Migration Patterns

Adding a New Table

def upgrade():
    op.create_table(
        'research',
        sa.Column('id', postgresql.UUID(), nullable=False),
        sa.Column('title', sa.String(length=255), nullable=False),
        sa.Column('description', sa.Text(), nullable=True),
        sa.Column('status', sa.Enum('ongoing', 'completed', 'planned'), nullable=False),
        sa.Column('created_at', sa.DateTime(), nullable=False),
        sa.Column('updated_at', sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_research_status', 'research', ['status'])

def downgrade():
    op.drop_index('ix_research_status', table_name='research')
    op.drop_table('research')

Adding a Column

def upgrade():
    op.add_column('team_members',
        sa.Column('linkedin_url', sa.String(length=255), nullable=True)
    )

def downgrade():
    op.drop_column('team_members', 'linkedin_url')

Data Migration

def upgrade():
    # Add column
    op.add_column('users', sa.Column('role', sa.String(50), nullable=True))

    # Migrate data
    connection = op.get_bind()
    connection.execute(
        "UPDATE users SET role = 'member' WHERE role IS NULL"
    )

    # Make not nullable
    op.alter_column('users', 'role', nullable=False)

def downgrade():
    op.drop_column('users', 'role')

Rollback Migrations

# Rollback one version
uv run alembic downgrade -1

# Rollback to specific version
uv run alembic downgrade <revision_id>

# Rollback all migrations
uv run alembic downgrade base

Troubleshooting

"Target database is not up to date"

# Check current version
uv run alembic current

# Stamp database with current code version
uv run alembic stamp head

Migration conflicts

# List all heads
uv run alembic heads

# Merge conflicting branches
uv run alembic merge -m "merge branches" <rev1> <rev2>

Reset migrations (development only!)

# Drop all tables
uv run alembic downgrade base

# Or drop database and recreate
dropdb qa_portal
createdb qa_portal
uv run alembic upgrade head

Best Practices

  1. Always review auto-generated migrations - Alembic may miss some changes
  2. Test migrations on dev database first - Don't apply directly to production
  3. Write reversible migrations - Ensure downgrade() actually works
  4. One logical change per migration - Keep migrations focused
  5. Include data migrations when needed - Don't just change schema
  6. Backup production database before applying migrations
  7. Use descriptive messages - Clear commit-style messages

Safety Checks

Before applying to production:

  • Migration reviewed and tested on dev database
  • Downgrade tested and works
  • No data loss in migration
  • Indexes added for new query patterns
  • Foreign key constraints properly defined
  • Backup of production database taken
  • Deployment plan includes rollback procedure

Output Format

After creating/applying migration, report:

  1. Migration file created: <filename>
  2. Changes summary: What tables/columns affected
  3. Applied successfully: Yes/No
  4. Current database version: <revision_id>
  5. Any warnings or issues encountered

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Local Agent

77.06%
按下载量换算76

安全审计

暂无安全审计结果可展示。

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills