Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
mysql_online_migrations
Advanced tools
Patch Rails migrations to enforce MySQL 5.6 online migrations
Prior to MySQL 5.6, when adding / removing / renaming indexes and columns, MySQL would lock the writes of the whole table.
MySQL 5.6 by default will try to apply the least locking possible. You however don't know what kind of locking it applies and there's situations where it can't allow writes during a migration (See Caveats).
This gem enforces LOCK=NONE
in all migration statements of Rails. Therefore, you're getting an error when MySQL cannot write during the migration so there's no surprise when rolling out in production.
Built for Rails 3.2.15+, including Rails 4.
List of requirements :
Patch Rails migrations to automatically add LOCK=NONE
when issuing ALTER
, CREATE INDEX
, CREATE UNIQUE INDEX
. DROP INDEX
statements from any methods of ActiveRecord:
add_index
, remove_index
, rename_index
add_column
, add_timestamps
remove_column
, remove_timestamps
change_column
, change_column_null
, change_column_default
Please note that it only modifies sql queries sent in Rails Migrations. This way we avoid patching all of ActiveRecord statements all the time.
In a typical Rails app, just add it to your Gemfile :
gem 'mysql_online_migrations'
Then run bundle install
You're ready for online migrations! Please read the caveats section though.
Example for environment test (your CI might not use MySQL 5.6 yet), add the following to config/environments/test.rb
:
config.active_record.mysql_online_migrations = false
Call your migration statement within with_lock
method. Example :
with_lock do
add_index :my_table, :my_field
end
The with_lock
method will be useful when hitting the caveats of LOCK=NONE
. Please read the 'Caveats' section.
To enable an 'ONLINE MIGRATION' debug statement whenever an online migration is
run, simply set the MysqlOnlineMigrations.verbose
module variable to true.
Example (in a Rails app's config/initializers/mysql_online_migrations.rb):
MysqlOnlineMigrations.verbose = true
The MySQL manual contains a list of which DDL statements can be run with LOCK=NONE
under Table 14.5 Summary of Online Status for DDL Operations. The short version is that you can not yet:
If you don't use the with_lock
method when online migration is not supported, you'll get a MySQL exception. No risk to lock the table by accident.
It's therefore highly recommended to use it in development/test/staging environment before running migrations in production.
If you have to perform such a migration without locking the table, tools such as pt-online-schema-change and LHM are viable options
FAQs
Unknown package
We found that mysql_online_migrations demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.