百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
Z

zero_downtime_migrations

> 后端框架
开源

使用 ActiveRecord 3+ 和 PostgreSQL 实现零停机迁移

557 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

使用 ActiveRecord 3+ 和 PostgreSQL 实现零停机迁移

zero_downtime_migrations

Zero downtime migrations with ActiveRecord 3+ and PostgreSQL.

Catch problematic migrations at development/test time! Heavily inspired by these similar projects:

  • https://github.com/ankane/strong_migrations
  • https://github.com/foobarfighter/safe-migrations

Installation

Simply add this gem to the project Gemfile.

ruby
gem "zero_downtime_migrations"

Usage

This gem will automatically raise exceptions when potential database locking migrations are detected.

It checks for common things like:

  • Adding a column with a default
  • Adding a non-concurrent index
  • Mixing data changes with index or schema migrations
  • Performing data or schema migrations with the DDL transaction disabled
  • Using each instead of find_each to loop thru ActiveRecord objects

These exceptions display clear instructions of how to perform the same operation the "zero downtime way".

Validations

Adding a column with a default

Bad

This can take a long time with significant database size or traffic and lock your table!

ruby
class AddPublishedToPosts = ?", 1.day.ago).update_all(published: true)
  end
end

Enforcements can be globally disabled by setting ENV["SAFETY_ASSURED"] when running migrations.

bash
SAFETY_ASSURED=1 bundle exec rake db:migrate --trace

These enforcements are automatically disabled by default for the following scenarios:

  • The database schema is being loaded with rake db:schema:load instead of db:migrate
  • The current migration is a reverse (down) migration
  • The current migration is named RollupMigrations

Testing

bash
bundle exec rspec

Contributing

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so we don't break it in a future version unintentionally.
  • Commit, do not mess with the version or history.
  • Open a pull request. Bonus points for topic branches.

Authors

  • Sean Huber

License

MIT - Copyright © 2016 LendingHome

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyactiverecorddatabasemigrationspostgres

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架