Skip to content

Commit

Permalink
Delegate to anonymous subclass of AR::SchemaMigration
Browse files Browse the repository at this point in the history
  • Loading branch information
defsprite authored and ilyakatz committed Oct 24, 2022
1 parent bc28405 commit 9dda061
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/data_migrate/data_schema_migration.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
module DataMigrate
class DataSchemaMigration < ::ActiveRecord::SchemaMigration

class DataSchemaMigration
class << self
def table_name
ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix
end
delegate :table_name, :primary_key, :create_table, :normalized_versions, :create, :create!, :table_exists?, :where, to: :instance

def primary_key
"version"
def instance
@instance ||= Class.new(::ActiveRecord::SchemaMigration) do
define_singleton_method(:table_name) { ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix }
define_singleton_method(:primary_key) { "version" }
end
end
end
end
end

0 comments on commit 9dda061

Please sign in to comment.