{"id":13879099,"url":"https://github.com/gocardless/activerecord-safer_migrations","last_synced_at":"2025-04-04T09:08:31.502Z","repository":{"id":36200338,"uuid":"40504566","full_name":"gocardless/activerecord-safer_migrations","owner":"gocardless","description":"Safer ActiveRecord migrations for Postgres","archived":false,"fork":false,"pushed_at":"2024-08-21T11:15:07.000Z","size":93,"stargazers_count":117,"open_issues_count":4,"forks_count":9,"subscribers_count":86,"default_branch":"master","last_synced_at":"2025-03-28T08:05:12.442Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gocardless.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-10T20:29:10.000Z","updated_at":"2024-10-19T14:54:49.000Z","dependencies_parsed_at":"2024-06-21T05:47:10.365Z","dependency_job_id":"811753aa-8ff3-4dcf-9994-1832abc1a419","html_url":"https://github.com/gocardless/activerecord-safer_migrations","commit_stats":{"total_commits":65,"total_committers":13,"mean_commits":5.0,"dds":0.7692307692307692,"last_synced_commit":"e847925af6bc8d9abd33ad9e3f9bf222a5928378"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocardless%2Factiverecord-safer_migrations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocardless%2Factiverecord-safer_migrations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocardless%2Factiverecord-safer_migrations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gocardless%2Factiverecord-safer_migrations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gocardless","download_url":"https://codeload.github.com/gocardless/activerecord-safer_migrations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247149501,"owners_count":20891954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T08:02:09.797Z","updated_at":"2025-04-04T09:08:31.481Z","avatar_url":"https://github.com/gocardless.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"## ActiveRecord safer migration helpers\n\n\u003e Looking for Rails 4.0 or Ruby 2.0 support? Please check out the [1.x tree](https://github.com/gocardless/activerecord-safer_migrations/tree/v1.0.0).\n\n*Note: this library only supports PostgreSQL 9.3+. If you're interested in adding support for other databases, we're open to pull requests!*\n\nPostgres holds ACCESS EXCLUSIVE locks for [almost all][pg-alter-table] DDL\noperations. ACCESS EXCLUSIVE locks conflict with all other table-level locks,\nwhich can cause issues in several situations. For instance:\n\n1. If the lock is held for a long time, all other access to the table will be\n   blocked, which can result in downtime.\n2. Even if the lock is only held briefly, it will block all other access to the\n   table while it is in the lock queue, as it conflicts with all other locks.\n   The lock can't be acquired until all other queries ahead of it have finished,\n   so having to wait on long-running queries can also result in downtime.\n   See [here][blog-post] for more details.\n\nBoth these issues can be avoided by setting timeouts on the migration connection -\n`statement_timeout` and `lock_timeout` respectively.\n\nOnce this gem is loaded, all migrations will automatically have a\n`lock_timeout` and a `statement_timeout` set. The initial `lock_timeout`\ndefault is 750ms, and the initial `statement_timeout` default is 1500ms. Both\ndefaults can be easily changed (e.g. in a Rails initializer).\n\n```ruby\nActiveRecord::SaferMigrations.default_lock_timeout = 1000\nActiveRecord::SaferMigrations.default_statement_timeout = 2000\n```\n\nTo explicitly set timeouts for a given migration, use the `set_lock_timeout` and\n`set_statement_timeout` class methods in the migration.\n\n```ruby\nclass LockTest \u003c ActiveRecord::Migration\n  set_lock_timeout(250)\n  set_statement_timeout(750)\n\n  def change\n    create_table :lock_test\n  end\nend\n```\n\nTo disable timeouts for a migration, use the `disable_lock_timeout!` and\n`disable_statement_timeout!` class methods. Note that this is [extremely\ndangerous][blog-post] if you're doing any schema alterations in your migration.\n\n```ruby\nclass LockTest \u003c ActiveRecord::Migration\n  # Only do this if you really know what you're doing!\n  disable_lock_timeout!\n  disable_statement_timeout!\n\n  def change\n    create_table :lock_test\n  end\nend\n```\n\n### Use with PgBouncer\n\nThis gem sets session-level settings on Postgres connections. If you're using\nPgBouncer in transaction pooling mode, using session-level settings is\ndangerous, as you can't guarantee which connection will receive the setting.\nFor this reason, this gem is incompatible with transaction-pooling and should\nonly be used if migrations are run on connections that support session-level\nfeatures.\n\n[blog-post]: https://gocardless.com/blog/zero-downtime-postgres-migrations-the-hard-parts/\n[pg-alter-table]: http://www.postgresql.org/docs/9.4/static/sql-altertable.html\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgocardless%2Factiverecord-safer_migrations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgocardless%2Factiverecord-safer_migrations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgocardless%2Factiverecord-safer_migrations/lists"}