You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

寻求类Laravel的标准SQL数据库Schema迁移工具(支持缺失执行、回滚)

Open-Source SQL Migration Tools for Your Laravel-like Workflow

Awesome question—let’s break down some open-source tools that check all your boxes for a SQL-first migration system similar to Laravel’s Schema, but using plain standard SQL:

Flyway Community Edition

  • SQL-first design: Built around plain SQL files with numeric version prefixes (e.g., V1__create_users_table.sql, V2__add_email_to_users.sql). No proprietary syntax—just your standard database SQL.
  • Execution logic: Scans your migration directory in strict version order, checks its flyway_schema_history table to see which migrations haven’t been run yet, and executes only those missing ones. Exactly the behavior you’re looking for.
  • Rollback support: Community Edition lets you define undo scripts using a U prefix (e.g., U2__remove_email_from_users.sql). Run the rollback command, and it’ll execute the corresponding undo SQL for the version you target.
  • FOSS status: 100% open-source and free for most use cases; paid tiers add enterprise features but aren’t required for your needs.

Liquibase

  • Flexible SQL support: While it offers XML/YAML/JSON migration formats, it fully embraces plain SQL files. You can use numeric version tags or timestamps as prefixes to order your migrations.
  • Tracking system: Maintains a databasechangelog table that logs every applied migration. When you run Liquibase, it automatically detects which SQL files haven’t been executed and runs them in sequence.
  • Rollback capabilities: Super flexible here—you can roll back to a specific version, undo the last migration, or even roll back using custom tags. For SQL migrations, you can include rollback SQL directly in the same file or create separate undo files.
  • FOSS status: The core version is open-source and free; paid tiers add extra features like advanced rollbacks and team collaboration tools, but the free version covers everything you need.

Phinx

  • PHP-based but SQL-friendly: Even though it’s built for PHP (like Laravel), you can write pure SQL migrations using .sql files (e.g., 20240520123000_create_posts_table.sql). No need to use PHP classes if you don’t want to.
  • Versioned execution: Uses numeric timestamps or sequential numbers as prefixes, scans your migration folder, and runs any migrations not recorded in its phinxlog table.
  • Rollback support: Lets you roll back one migration at a time or to a specific version. For SQL migrations, you can define rollback SQL in separate undo files or within the migration structure.
  • FOSS status: Open-source and free, with a workflow that feels familiar if you’re used to Laravel’s migrations—just with pure SQL instead of PHP Schema builders.

Quick Tips

  • All three tools work with major databases (MySQL, PostgreSQL, SQLite, etc.), just like Laravel’s Schema system.
  • You can easily integrate any of them into your CI/CD pipeline using their command-line tools or build system plugins (Maven, Gradle, Composer, etc.).

内容的提问来源于stack exchange,提问作者Matthew Lenz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:17:03