Class: Cassie::Schema::CassandraMigrations::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/cassie/schema/cassandra_migrations/importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_path = nil) ⇒ Importer

Returns a new instance of Importer.



21
22
23
24
25
26
27
28
# File 'lib/cassie/schema/cassandra_migrations/importer.rb', line 21

def initialize(source_path=nil)
  @source           = source_path || default_source_path
  @final_version    = Cassie::Schema::Version.new("0.0.1.0", "Remove cassandra_migrations schema")
  @migration_files  = find_migration_files
  @imported_paths   = []
  @before_each      = Proc.new{}
  @after_each       = Proc.new{}
end

Instance Attribute Details

#after_eachObject

A callback fired after importing each migration



19
20
21
# File 'lib/cassie/schema/cassandra_migrations/importer.rb', line 19

def after_each
  @after_each
end

#before_eachObject

A callback fired before importing each migration



17
18
19
# File 'lib/cassie/schema/cassandra_migrations/importer.rb', line 17

def before_each
  @before_each
end

#final_versionObject

The version the schema will rest at after importing. Defaults to 0.1.0 with a description of Remove cassandra_migrations schema



11
12
13
# File 'lib/cassie/schema/cassandra_migrations/importer.rb', line 11

def final_version
  @final_version
end

#imported_pathsObject

The newly imported Cassie migration files



15
16
17
# File 'lib/cassie/schema/cassandra_migrations/importer.rb', line 15

def imported_paths
  @imported_paths
end

#migration_filesObject

The migration files to be imported



13
14
15
# File 'lib/cassie/schema/cassandra_migrations/importer.rb', line 13

def migration_files
  @migration_files
end

#sourceObject

The source directory containing the cassandra_migrations files. Defaults to db/cassandra_migrate



8
9
10
# File 'lib/cassie/schema/cassandra_migrations/importer.rb', line 8

def source
  @source
end

Instance Method Details

#importObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cassie/schema/cassandra_migrations/importer.rb', line 30

def import
  new_version = initial_version
  new_version.executor = "cassandra_migrations"

  migration_files.each do |old_migration_file|
    before_each.call(old_migration_file)
    new_version.id = Cassandra::TimeUuid::Generator.new.now
    new_version.description = old_migration_file.description.humanize
    writer = VersionWriter.new(new_version)
    # new_version will automatically find
    # the new cassie::schema::migration
    # that is built from the old file
    writer.migration_contents = old_migration_file.build_migration_class(new_version)

    self.imported_paths << writer.write

    Cassie::Schema.record_version(new_version, false)
    after_each.call(new_version)

    new_version = new_version.next
  end
end