{"repo":"doctolib/safe-pg-migrations","free":true,"listed":false,"github":"https://github.com/doctolib/safe-pg-migrations","clone":"git clone https://github.com/doctolib/safe-pg-migrations.git","description":"Make your PostgreSQL migrations safe","language":"Ruby","stars":523,"topics":["postgres","downtime","rails-migrations","managed-by-terraform","criticality-tier0","dodo","github-actions"],"license":"MIT","category":"databases-storage","readme_excerpt":"safe-pg-migrations ActiveRecord migrations for Postgres made safe. Requirements - Ruby 3.0+ - Rails 6.1+ - PostgreSQL 11.7+ Usage Just drop this line in your Gemfile: Note: Do not run migrations via PgBouncer connection if it is configured to use transactional or statement pooling modes. You must run migrations via a direct Postgres connection, or configure PgBouncer to use session pooling mode. Example Consider the following migration: If the users table is large, running this migration will likely cause downtime. Safe PG Migrations hooks into Active Record so that the following gets executed instead: Under the hood, Safe PG Migrations patches ActiveRecord::Migration and extends ActiveRecord::Base.connection to make potentially dangerous methods—like add reference —safe. Motivation Writing a safe migration can be daunting. Numerous articles, including ours, have been written on the topic and a few gems are trying to address the problem. Even for someone who has a pretty good command of Postgres, remembering all the subtleties of explicit locking is not a piece of cake. Active Record means developers don't have to be proficient in SQL to interact with a database. In the same way, Safe PG Migrations was created so that developers don't have to understand the ins and outs of Postgres to write a safe migration. Feature set Lock timeout Most DDL operations (e.g. adding a column, removing a column or adding a default value to a column) take an ACCESS EXCLUSIVE lock on the table th","default_branch":null,"files":null,"tree":[],"storefront":"/r/doctolib","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/doctolib/safe-pg-migrations/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}