README.md in strong_migrations-1.3.2 vs README.md in strong_migrations-1.4.0

- old
+ new

@@ -72,10 +72,11 @@ Postgres-specific checks: - [adding an index non-concurrently](#adding-an-index-non-concurrently) - [adding a reference](#adding-a-reference) - [adding a foreign key](#adding-a-foreign-key) +- [adding an exclusion constraint](#adding-an-exclusion-constraint) - [adding a json column](#adding-a-json-column) - [setting NOT NULL on an existing column](#setting-not-null-on-an-existing-column) Best practices: @@ -105,22 +106,22 @@ class User < ApplicationRecord self.ignored_columns = ["some_column"] end ``` -2. Deploy code +2. Deploy the code 3. Write a migration to remove the column (wrap in `safety_assured` block) ```ruby class RemoveSomeColumnFromUsers < ActiveRecord::Migration[7.0] def change safety_assured { remove_column :users, :some_column } end end ``` -4. Deploy and run migration +4. Deploy and run the migration 5. Remove the line added in step 1 ### Adding a column with a default value #### Bad @@ -485,9 +486,27 @@ def change validate_foreign_key :users, :orders end end ``` + +### Adding an exclusion constraint + +#### Bad + +In Postgres, adding an exclusion constraint blocks reads and writes while every row is checked. + +```ruby +class AddExclusionContraint < ActiveRecord::Migration[7.1] + def change + add_exclusion_constraint :users, "number WITH =", using: :gist + end +end +``` + +#### Good + +[Let us know](https://github.com/ankane/strong_migrations/issues/new) if you have a safe way to do this (exclusion constraints cannot be marked `NOT VALID`). ### Adding a json column #### Bad