Class: Cardio::Migration

Inherits:
Object
  • Object
show all
Includes:
Assumption, Stamp
Defined in:
lib/cardio/migration.rb,
lib/cardio/migration/stamp.rb,
lib/cardio/migration/schema.rb,
lib/cardio/migration/transform.rb,
lib/cardio/migration/assumption.rb

Direct Known Subclasses

Schema, Transform

Defined Under Namespace

Modules: Assumption, Stamp Classes: Schema, Transform

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Stamp

#stamp

Methods included from Assumption

#assume_current, #assume_migrated_upto_version

Class Attribute Details

.migration_typeObject (readonly)

Returns the value of attribute migration_type.



9
10
11
# File 'lib/cardio/migration.rb', line 9

def migration_type
  @migration_type
end

.old_deck_tableObject (readonly)

Returns the value of attribute old_deck_table.



9
10
11
# File 'lib/cardio/migration.rb', line 9

def old_deck_table
  @old_deck_table
end

.old_tablesObject (readonly)

Returns the value of attribute old_tables.



9
10
11
# File 'lib/cardio/migration.rb', line 9

def old_tables
  @old_tables
end

Class Method Details

.migration_class(type) ⇒ Object



11
12
13
# File 'lib/cardio/migration.rb', line 11

def migration_class type
  type == :schema ? Migration::Schema : Migration::Transform
end

.new_for(type) ⇒ Object



15
16
17
# File 'lib/cardio/migration.rb', line 15

def new_for type
  migration_class(type).new
end

.portObject



25
26
27
28
29
30
# File 'lib/cardio/migration.rb', line 25

def port
  return unless connection.table_exists? old_deck_table
  rename_old_tables
  connection.execute "INSERT INTO #{table} (#{select_nonduplicate_versions})"
  connection.drop_table old_deck_table
end

.port_allObject



19
20
21
22
23
# File 'lib/cardio/migration.rb', line 19

def port_all
  %i[schema transform].each do |type|
    migration_class(type).port
  end
end

Instance Method Details

#contextObject



75
76
77
78
79
# File 'lib/cardio/migration.rb', line 75

def context
  mode do |paths|
    yield ActiveRecord::MigrationContext.new(paths, ActiveRecord::SchemaMigration)
  end
end

#downObject

Raises:

  • (ActiveRecord::IrreversibleMigration)


85
86
87
# File 'lib/cardio/migration.rb', line 85

def down
  raise ActiveRecord::IrreversibleMigration
end

#migration_pathsObject



71
72
73
# File 'lib/cardio/migration.rb', line 71

def migration_paths
  Cardio.paths["data/#{migration_type}"].existent.to_a
end

#migration_typeObject



55
56
57
# File 'lib/cardio/migration.rb', line 55

def migration_type
  self.class.migration_type || :schema
end

#modeObject



81
82
83
# File 'lib/cardio/migration.rb', line 81

def mode
  with_migration_table { yield migration_paths }
end

#run(version = nil, verbose = true) ⇒ Object



59
60
61
62
63
64
# File 'lib/cardio/migration.rb', line 59

def run version=nil, verbose=true
  context do |mc|
    ActiveRecord::Migration.verbose = verbose
    mc.migrate version
  end
end

#versionObject



66
67
68
69
# File 'lib/cardio/migration.rb', line 66

def version
  path = stamp_path
  File.exist?(path) ? File.read(path).strip : nil
end