module XMigra::DeclarativeMigration::ChainSupport

Public Instance Methods

check_declaratives_current!() click to toggle source
# File lib/xmigra/declarative_migration.rb, line 72
def check_declaratives_current!
  unless unimplemented_declaratives.empty?
    raise(
      MissingImplementationError,
      "Declaratives without migration implementing current state:\n" +
      unimplemented_declaratives.collect {|df| "    #{df.basename('.yaml')}\n"}.join("")
    )
  end
  
  questionable_migrations = latest_declarative_implementations.values.select {|m| m.questionable?}
  unless questionable_migrations.empty?
    raise(
      QuestionableImplementationError,
      "Implementing migrations with questionable SQL:\n" +
      questionable_migrations.collect {|m| "    #{m.file_path}\n"}.join("")
    )
  end
  
  questionable_migrations = latest_declarative_implementations.values.each do |m|
    next unless m.management_migration?
    raise(
      QuestionableImplementationError,
      "#{m.file_path} cannot execute SQL for a declarative #{m.goal}"
    ) unless m.sql.nil? || m.sql.empty?
  end
end
latest_declarative_implementations() click to toggle source
# File lib/xmigra/declarative_migration.rb, line 32
def latest_declarative_implementations
  @latest_declarative_implementations ||= Hash.new do |h, file_path|
    ext_path = Pathname(file_path).expand_path
    if h.has_key? ext_path
      next h[ext_path]
    end
    raise Error, (
      "Unexpected file path '#{file_path}', known file paths:" +
      h.keys.collect {|kp| "    #{kp}\n"}.join('')
    )
  end.tap do |files|
    each do |migration|
      # Skip non-declarative migrations
      next unless migration.is_a? DeclarativeMigration
      if (
        [:renunciation, :destruction].include?(migration.goal) &&
        migration.declarative_status == :missing
      )
        files.delete(migration.declarative_file_path)
      else
        files[migration.declarative_file_path] = migration
      end
    end
    
    Dir.glob(Pathname(path).join(SUBDIR, '*.yaml').to_s) do |decl_file|
      decl_file_path = Pathname(decl_file).expand_path
      next if files.has_key?(decl_file_path)
      files[decl_file_path] = DeclarativeMigration::Missing
    end
    
    files.freeze
  end
end
unimplemented_declaratives() click to toggle source
# File lib/xmigra/declarative_migration.rb, line 66
def unimplemented_declaratives
  @unimplemented_declaratives ||= latest_declarative_implementations.reject do |file_path, migration|
    [:equal, :older].include? migration.declarative_status
  end.keys
end