Module: CaptureMigrationSql
- Defined in:
- lib/capture_migration_sql/sql_subscriber.rb,
lib/capture_migration_sql.rb,
lib/capture_migration_sql/version.rb,
lib/capture_migration_sql/migration_extension.rb
Overview
Extension methods for ActiveRecord::Migration class.
Defined Under Namespace
Modules: MigrationExtension Classes: SqlSubscriber
Constant Summary collapse
- VERSION =
"1.0.1"
Class Method Summary collapse
-
.capture(directory: nil, starting_with: 0) ⇒ Object
Call this method in an initializer to invoke dumping the SQL executed during migrations in to a file.
-
.capture_enabled? ⇒ Boolean
Return true if capturing SQL is enabled for migrations.
-
.capture_stream ⇒ Object
Return the strema migration SQL is being written to.
-
.directory ⇒ Object
Return the directory set by ‘capture_sql` for storing migration SQL.
-
.starting_with_version ⇒ Object
Return the migration version number to start capaturing SQL.
Class Method Details
.capture(directory: nil, starting_with: 0) ⇒ Object
Call this method in an initializer to invoke dumping the SQL executed during migrations in to a file.
The ‘directory` argument indicates the directory where the files should be stored. If the directory is not specified, the files will be stored in `db/migration_sql/`.
The ‘starting_with` argument can be used to specify which migration you wish to start capturing SQL with. This can be useful if you are adding this gem to an existing project with a history of migrations that you don’t want to go back and edit.
18 19 20 21 22 23 24 |
# File 'lib/capture_migration_sql.rb', line 18 def capture(directory: nil, starting_with: 0) unless ::ActiveRecord::Migration.include?(MigrationExtension) ::ActiveRecord::Migration.prepend(MigrationExtension) end @sql_directory = (directory || Rails.root + "db" + "migration_sql") @starting_with_version = starting_with.to_i end |
.capture_enabled? ⇒ Boolean
Return true if capturing SQL is enabled for migrations.
37 38 39 |
# File 'lib/capture_migration_sql.rb', line 37 def capture_enabled? !!Thread.current[:capture_migration_sql_enabled] end |
.capture_stream ⇒ Object
Return the strema migration SQL is being written to.
42 43 44 |
# File 'lib/capture_migration_sql.rb', line 42 def capture_stream Thread.current[:capture_migration_sql_stream] end |
.directory ⇒ Object
Return the directory set by ‘capture_sql` for storing migration SQL.
27 28 29 |
# File 'lib/capture_migration_sql.rb', line 27 def directory @sql_directory if defined?(@sql_directory) end |
.starting_with_version ⇒ Object
Return the migration version number to start capaturing SQL.
32 33 34 |
# File 'lib/capture_migration_sql.rb', line 32 def starting_with_version @starting_with_version if defined?(@starting_with_version) end |