PitchHut
Log in / Sign up
strong_migrations
5 views
Ensure safe migrations, protect your data.
Pitch

Strong Migrations helps developers prevent potentially dangerous database migrations during development. By detecting risky operations and guiding users to safer alternatives, it enhances the reliability of your PostgreSQL, MySQL, and MariaDB migrations. Trusted by Instacart, it’s an essential tool for anyone looking to maintain data integrity while making necessary changes.

Description

Strong Migrations is a powerful library designed to help developers catch unsafe migrations during development, ensuring that your database schema changes are safe and effective.

Key Features:

  • Detects Potentially Dangerous Operations: Strong Migrations analyzes your migrations to identify operations that may lead to long locks or application errors.
  • Prevention by Default: It blocks risky migrations from running automatically, allowing developers to focus on safer database modifications.
  • Guidance on Safer Practices: The gem provides tailored instructions for performing migrations safely, helping developers make informed decisions.

Supported Databases:

Strong Migrations is compatible with PostgreSQL, MySQL, and MariaDB, making it versatile for various projects.

Battle-Tested:

This gem has been rigorously tested at Instacart, proving its reliability in production environments.

How It Works:

When you attempt a potentially dangerous migration, Strong Migrations will intervene and present you with a clear error message:

=== Dangerous operation detected #strong_migrations ===
...

Common Checks Include:

  • Removing a column
  • Changing the type or renaming a column
  • Creating tables with the force option
  • Adding auto-incrementing and stored generated columns
  • Executing raw SQL statements
  • And much more!

Best Practices:

The gem encourages developers to follow best practices by recommending alternative strategies for common migration pitfalls. For instance, it illustrates how to safely remove a column by ignoring it in Active Record before performing the migration:

class User < ApplicationRecord
  self.ignored_columns += ["some_column"]
end

class RemoveSomeColumnFromUsers < ActiveRecord::Migration[8.0]
  def change
    safety_assured { remove_column :users, :some_column }
  end
end

Custom Checks and Configurations:

Strong Migrations allows developers to add custom checks, create initializer settings to assure safe migration development, and provide tailored messaging for specific migration scenarios. You can also implement migration timeouts to ensure that migrations don’t lock your application unnecessarily.

Conclusion:

By integrating Strong Migrations into your development workflow, you can enhance the safety and reliability of your database schema changes, minimizing downtime and potential errors. Strong Migrations is essential for developers looking to implement robust database practices.