返回顶部
d

database-schema-sync

Database schema management using idempotent sync script instead of Alembic migrations. Use when (1) Adding new database tables, (2) Adding new columns to existing tables, (3) Modifying database schema, (4) Deploying to production, (5) Syncing schema across environments. REQUIRED APPROACH - ALWAYS use scripts/sync-production-schema.py with --dry-run first, NEVER run Alembic migrations directly in production.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
69
下载量
0
收藏
概述
安装方式
版本历史

database-schema-sync

# Database Schema Management ## USE SCHEMA SYNC SCRIPT, NOT ALEMBIC MIGRATIONS **PREFERRED APPROACH:** Smart schema sync script that detects and applies only missing changes. ## STRICT RULES * ✅ **ALWAYS USE:** `scripts/sync-production-schema.py` for production deployments * ✅ **IDEMPOTENT:** Can run multiple times safely without errors * ✅ **TRANSPARENT:** Shows exactly what will change before applying * ❌ **AVOID:** Running Alembic migrations directly in production * ❌ **AVOID:** Manual SQL scripts that aren't version controlled * ⚠️ **KEEP:** Alembic migration files for documentation purposes only ## Why Schema Sync Script? **✅ Advantages:** * **Simpler:** One script vs managing many migration files * **Safer:** Checks what exists before applying changes * **Idempotent:** Run multiple times without errors * **Transparent:** Shows diff before applying * **Flexible:** Works with any database state (dev, staging, prod) * **No tracking:** No need to manage "which migrations have run" **❌ Alembic Migration Problems:** * Fails if run twice (not idempotent) * Requires tracking which migrations applied * All-or-nothing (can't skip one migration) * Complex rollback scenarios * Team coordination overhead ## Workflow ### 1. DRY RUN FIRST (Always!) ```bash # Show what would change WITHOUT applying python scripts/sync-production-schema.py --dry-run ``` ### 2. REVIEW OUTPUT ```bash # Output shows: # ✓ Tables/columns that already exist (skipped) # ℹ New tables/columns that would be created # ⚠ Any potential issues ``` ### 3. APPLY TO PRODUCTION ```bash # Apply changes to production database export DATABASE_URL="postgresql://..." python scripts/sync-production-schema.py --apply ``` ### 4. VERIFY ```bash # Connect and verify schema psql "$DATABASE_URL" -c "\dt" # List tables psql "$DATABASE_URL" -c "\d table_name" # Describe table ``` ## Required Locations * **Schema Sync Script:** `/Users/tobymorning/Desktop/core/scripts/sync-production-schema.py` * **Documentation:** `/Users/tobymorning/Desktop/core/docs/deployment/SCHEMA_SYNC_GUIDE.md` * **Alembic Migrations (for documentation):** `/Users/tobymorning/Desktop/core/src/backend/alembic/versions/` ## When to Update Schema ### Adding New Tables 1. Define models in `src/backend/app/models/` 2. Add table creation logic to `scripts/sync-production-schema.py` 3. Update `docs/deployment/SCHEMA_SYNC_GUIDE.md` with new table info 4. Test with `--dry-run` first 5. Apply to dev, staging, then production ### Adding New Columns 1. Update model in `src/backend/app/models/` 2. Add column check and ADD COLUMN logic to sync script 3. Use IF NOT EXISTS patterns for safety 4. Test with `--dry-run` first 5. Apply to environments ## Safety Checks Built-In * ✅ Checks table exists before creating * ✅ Checks column exists before adding * ✅ Transaction safety (rollback on error) * ✅ Dry-run mode to preview changes * ✅ Color-coded output for easy reading * ✅ Summary of all changes applied ## Integration with CI/CD **Railway Deployment:** ```yaml # In Procfile or deploy script release: python scripts/sync-production-schema.py --apply ``` **GitHub Actions:** ```yaml - name: Sync Production Schema env: DATABASE_URL: ${{ secrets.DATABASE_URL }} run: python scripts/sync-production-schema.py --apply ``` ## ENFORCEMENT * ❌ **NEVER** run `alembic upgrade head` in production * ❌ **NEVER** manually execute SQL in production without sync script * ❌ **NEVER** skip dry-run step for production changes * ✅ **ALWAYS** use `scripts/sync-production-schema.py` for schema changes * ✅ **ALWAYS** run `--dry-run` before `--apply` * ✅ **ALWAYS** verify changes in dev/staging before production * ✅ **ALWAYS** update documentation when adding new tables/columns ## VIOLATION CONSEQUENCES * Database schema drift between environments * Failed deployments from migration conflicts * Data loss from incorrect migrations * Production downtime from schema errors * Team confusion about database state **THIS IS A REQUIRED STANDARD. USE SCHEMA SYNC SCRIPT FOR ALL DATABASE CHANGES.** ## Reference Files See `references/sync-vs-alembic.md` for detailed comparison of sync script vs Alembic migrations. See `references/workflow-examples.md` for code examples of adding tables, columns, indexes, and handling complex migrations. Run `scripts/verify-sync-script.sh` to validate that sync script exists and is properly configured.

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 database-schema-sync-1776058945 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 database-schema-sync-1776058945 技能

通过命令行安装

skillhub install database-schema-sync-1776058945

下载 Zip 包

⬇ 下载 database-schema-sync v1.0.0

文件大小: 6.73 KB | 发布时间: 2026-4-14 09:46

v1.0.0 最新 2026-4-14 09:46
Initial release of database-schema-sync skill.

- Introduces an idempotent schema sync script approach for database migrations.
- Strongly enforces use of scripts/sync-production-schema.py instead of Alembic migrations in production.
- Provides step-by-step workflow: dry run, review output, apply, and verification.
- Outlines strict usage rules, safety checks, and integration recommendations for CI/CD pipelines.
- Includes documentation and enforcement guidelines to prevent schema drift and production errors.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部