class Cardio::Migration
Attributes
migration_type[R]
old_deck_table[R]
old_tables[R]
Public Class Methods
migration_class(type)
click to toggle source
# File lib/cardio/migration.rb, line 10 def migration_class type type == :schema ? Migration::Schema : Migration::Transform end
new_for(type)
click to toggle source
# File lib/cardio/migration.rb, line 14 def new_for type migration_class(type).new end
port()
click to toggle source
# File lib/cardio/migration.rb, line 24 def port return unless connection.table_exists? old_deck_table rename_old_tables connection.execute "INSERT INTO #{table} (SELECT * from #{old_deck_table})" connection.drop_table old_deck_table end
port_all()
click to toggle source
# File lib/cardio/migration.rb, line 18 def port_all %i[schema transform].each do |type| migration_class(type).port end end
Private Class Methods
connection()
click to toggle source
# File lib/cardio/migration.rb, line 44 def connection ActiveRecord::Base.connection end
rename_old_tables()
click to toggle source
# File lib/cardio/migration.rb, line 33 def rename_old_tables old_tables.each do |old_table_name| next unless connection.table_exists? old_table_name connection.rename_table old_table_name, table end end
table()
click to toggle source
# File lib/cardio/migration.rb, line 40 def table "#{migration_type}_migrations" end
Public Instance Methods
context() { |migration_context(paths, SchemaMigration)| ... }
click to toggle source
# File lib/cardio/migration.rb, line 69 def context mode do |paths| yield ActiveRecord::MigrationContext.new(paths, ActiveRecord::SchemaMigration) end end
down()
click to toggle source
# File lib/cardio/migration.rb, line 79 def down raise ActiveRecord::IrreversibleMigration end
migration_paths()
click to toggle source
# File lib/cardio/migration.rb, line 65 def migration_paths Cardio.paths["data/#{migration_type}"].existent.to_a end
migration_type()
click to toggle source
# File lib/cardio/migration.rb, line 49 def migration_type self.class.migration_type || :schema end
mode() { |migration_paths| ... }
click to toggle source
# File lib/cardio/migration.rb, line 75 def mode with_migration_table { yield migration_paths } end
run(version=nil, verbose=true)
click to toggle source
# File lib/cardio/migration.rb, line 53 def run version=nil, verbose=true context do |mc| ActiveRecord::Migration.verbose = verbose mc.migrate version end end
version()
click to toggle source
# File lib/cardio/migration.rb, line 60 def version path = stamp_path File.exist?(path) ? File.read(path).strip : nil end
Private Instance Methods
connection()
click to toggle source
# File lib/cardio/migration.rb, line 85 def connection Cardio::Migration.connection end
table_name=(table_name)
click to toggle source
# File lib/cardio/migration.rb, line 93 def table_name= table_name ActiveRecord::Base.schema_migrations_table_name = table_name ActiveRecord::SchemaMigration.table_name = table_name ActiveRecord::SchemaMigration.reset_column_information end
with_migration_table() { || ... }
click to toggle source
# File lib/cardio/migration.rb, line 89 def with_migration_table yield end