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 =
File.read(File.join(__dir__, "..", "..", "VERSION"))
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.
17 18 19 20 21 22 23 |
# File 'lib/capture_migration_sql.rb', line 17 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.
36 37 38 |
# File 'lib/capture_migration_sql.rb', line 36 def capture_enabled? !!Thread.current[:capture_migration_sql_enabled] end |
.capture_stream ⇒ Object
Return the strema migration SQL is being written to.
41 42 43 |
# File 'lib/capture_migration_sql.rb', line 41 def capture_stream Thread.current[:capture_migration_sql_stream] end |
.directory ⇒ Object
Return the directory set by ‘capture_sql` for storing migration SQL.
26 27 28 |
# File 'lib/capture_migration_sql.rb', line 26 def directory @sql_directory if defined?(@sql_directory) end |
.starting_with_version ⇒ Object
Return the migration version number to start capaturing SQL.
31 32 33 |
# File 'lib/capture_migration_sql.rb', line 31 def starting_with_version @starting_with_version if defined?(@starting_with_version) end |