Class: Cardio::Migration

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

Overview

Base class for both schema and transform card migrations, which are found in <mod>/data/schema and <mod>/data/transform respectively

Direct Known Subclasses

Schema, Transform

Defined Under Namespace

Modules: Assumption, Port, Stamp Classes: Schema, Transform

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Port

port, port_all

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.



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

def migration_type
  @migration_type
end

.old_deck_tableObject (readonly)

Returns the value of attribute old_deck_table.



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

def old_deck_table
  @old_deck_table
end

.old_tablesObject (readonly)

Returns the value of attribute old_tables.



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

def old_tables
  @old_tables
end

Class Method Details

.migration_class(type) ⇒ Object



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

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

.new_for(type) ⇒ Object



18
19
20
# File 'lib/cardio/migration.rb', line 18

def new_for type
  migration_class(type).new
end

Instance Method Details

#contextObject



49
50
51
52
53
54
# File 'lib/cardio/migration.rb', line 49

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

#downObject

Raises:

  • (ActiveRecord::IrreversibleMigration)


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

def down
  raise ActiveRecord::IrreversibleMigration
end

#migration_pathsObject



45
46
47
# File 'lib/cardio/migration.rb', line 45

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

#migration_typeObject



29
30
31
# File 'lib/cardio/migration.rb', line 29

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

#modeObject



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

def mode
  with_migration_table { yield migration_paths }
end

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



33
34
35
36
37
38
# File 'lib/cardio/migration.rb', line 33

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

#versionObject



40
41
42
43
# File 'lib/cardio/migration.rb', line 40

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