{"repo":"bdurand/capture_migration_sql","free":true,"listed":false,"github":"https://github.com/bdurand/capture_migration_sql","clone":"git clone https://github.com/bdurand/capture_migration_sql.git","description":"Capture SQL generated by ActiveRecord migrations.","language":"Ruby","stars":18,"topics":["sql","database","rails","activerecord","migrations"],"license":"MIT","category":"databases-storage","readme_excerpt":"Capture Migration SQL This gem adds the ability to capture and persist the SQL statements executed by migrations. There are a couple of reasons why you may want to do this. 1. Having a list of SQL changes in a migration can allow a more thorough review of database changes during a code review. The Ruby schema directives in Rails are nice for simple tables and for documentation purposes, but if you need to tune your database for performance or data integrity, seeing the raw SQL can give you a better idea of exactly what each change involves. 2. Not everyone gets to run database migrations in production. If you have a DBA who needs to approve and run all changes for security and performance reasons, you'll probably need to give them the individual SQL changes. This gem logs all those changes for you in a consistent place so you don't have to hunt for them in your development logs or reverse engineer them from the Ruby code. Usage Add this to a file in config/initializers in your Rails application: This will log each migration to a file in the db/migration sql directory. You can also specify a different directory by passing the path the the capture method. Additionally, you can specify a first migration to start with. This will avoid generating files for all previous versions. Within a migration, you can enable and disable capturing SQL within a block: You should disable SQL logging in migration logic that generate queries to clean up or move data that may result in different re","default_branch":null,"files":null,"tree":[],"storefront":"/r/bdurand","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/bdurand/capture_migration_sql/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."}