Class: Kanal::Plugins::ActiveRecord::Overriden::VersionSuffixMigrationContext
- Inherits:
-
ActiveRecord::MigrationContext
- Object
- ActiveRecord::MigrationContext
- Kanal::Plugins::ActiveRecord::Overriden::VersionSuffixMigrationContext
- Defined in:
- lib/kanal/plugins/active_record/overriden/version_suffix_migration_context.rb
Overview
NOTE: NOT USED. CONSERVATED DUE TO THE USELESS WAY OF NAMED MIGRATIONS IF PLUGIN WILL BE USED WITH RAILS (I suspect it will be common case scenario, because it’s not enough to create bots, it will be very often coupled with Rails for: admin, analytics, bot + websites stack, with registration in both places, etc)
Will not spend more time on this feature, if someone still wants to utilize named migrations here - you are welcome, please fire up a PR, we will look into it
Thanks to the craftsmanship in Redmine repository I was able to learn how it creates named migration versions. And now we can create our own strategy alike
Instance Method Summary collapse
- #get_all_versions ⇒ Object
-
#initialize(version_suffix, migration_paths, schema_migration = ::ActiveRecord::SchemaMigration) ⇒ VersionSuffixMigrationContext
constructor
Overriden constructor to save version suffix.
- #migrations ⇒ Object
- #up(target_version = nil, &block) ⇒ Object
Constructor Details
#initialize(version_suffix, migration_paths, schema_migration = ::ActiveRecord::SchemaMigration) ⇒ VersionSuffixMigrationContext
Overriden constructor to save version suffix
32 33 34 35 |
# File 'lib/kanal/plugins/active_record/overriden/version_suffix_migration_context.rb', line 32 def initialize(version_suffix, migration_paths, schema_migration = ::ActiveRecord::SchemaMigration) @version_suffix = version_suffix super(migration_paths, schema_migration) end |
Instance Method Details
#get_all_versions ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/kanal/plugins/active_record/overriden/version_suffix_migration_context.rb', line 63 def get_all_versions if schema_migration.table_exists? schema_migration.all_versions.filter do |v| v.include? @version_suffix end.map do |v| Integer(v.sub!(@version_suffix, ""), 10) end else [] end end |
#migrations ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/kanal/plugins/active_record/overriden/version_suffix_migration_context.rb', line 53 def migrations lst = super lst.map do |migration_proxy| migration_proxy.version = "#{migration_proxy.version}_#{@version_suffix}" migration_proxy end end |
#up(target_version = nil, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/kanal/plugins/active_record/overriden/version_suffix_migration_context.rb', line 37 def up(target_version = nil, &block) selected_migrations = if block_given? migrations.select(&block) else migrations end Kanal::Plugins::ActiveRecord::Overriden::VersionSuffixMigrator.new( :up, selected_migrations, schema_migration, target_version, version_suffix: @version_suffix ).migrate end |