Class: XMigra::NewIndexAdder

Inherits:
SchemaManipulator show all
Defined in:
lib/xmigra/new_index_adder.rb

Constant Summary

Constants inherited from SchemaManipulator

SchemaManipulator::ACCESS_SUBDIR, SchemaManipulator::DBINFO_FILE, SchemaManipulator::INDEXES_SUBDIR, SchemaManipulator::PERMISSIONS_FILE, SchemaManipulator::PLUGIN_KEY, SchemaManipulator::STRUCTURE_SUBDIR, SchemaManipulator::VERINC_FILE

Instance Attribute Summary

Attributes inherited from SchemaManipulator

#path, #plugin

Instance Method Summary collapse

Methods inherited from SchemaManipulator

#branch_upgrade_file, #load_plugin!

Constructor Details

#initialize(path) ⇒ NewIndexAdder

Returns a new instance of NewIndexAdder.



6
7
8
# File 'lib/xmigra/new_index_adder.rb', line 6

def initialize(path)
  super(path)
end

Instance Method Details

#add_index(name) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/xmigra/new_index_adder.rb', line 10

def add_index(name)
  indexes_dir = @path.join(INDEXES_SUBDIR)
  FileUtils.mkdir_p(indexes_dir) unless indexes_dir.exist?
  
  new_fpath = indexes_dir.join(name + '.yaml')
  raise(XMigra::Error, "Index \"#{new_fpath.basename}\" already exists") if new_fpath.exist?
  
  index_creation_template = begin
    index_template_sql
  rescue NameError
    ''
  end
  new_data = {
    'sql'=>index_creation_template.dup.extend(LiteralYamlStyle),
  }
  
  File.open(new_fpath, "w") do |f|
    $xmigra_yamler.dump(new_data, f)
  end
  
  return new_fpath
end