class XMigra::Plugin

Base class for XMigra plugins.

Derive a class from this class, then call XMigra::Plugin.activate! with a block that instantiates your class.

require "xmigra/plugin"

class YearTemplatePlugin < XMigra::Plugin
  def amend_composed_sql(sql)
    sql.gsub! '[{year}]', Date.today.year.to_s
  end
end

XMigra::Plugin.activate! {YearTemplatePlugin.new}

The last call to XMigra::Plugin.activate! will determine which block will be executed to return the active plugin, so make sure to require any plugins to be aggregated before activating your own.

Attributes

active[R]

Public Class Methods

activate!(&blk) click to toggle source
# File lib/xmigra/plugin.rb, line 52
def activate!(&blk)
  @activation = blk
end
load!(name) click to toggle source
# File lib/xmigra/plugin.rb, line 32
def load!(name)
  previous_depth, @load_depth = @load_depth, (@load_depth || 0) + 1
  @activation = nil if previous_depth.nil?
  begin
    require name
  rescue ::LoadError => error
    if previous_depth.nil? && error.path == name
      raise LoadingError, "The XMigra plugin #{name.inspect} is not installed (Kernel#require failed)."
    else
      raise
    end
  ensure
    @load_depth = previous_depth
  end
  
  if previous_depth.nil? && @activation
    @active = @activation.call
  end
end
loading?() click to toggle source
# File lib/xmigra/plugin.rb, line 28
def loading?
  !!@load_depth
end

Public Instance Methods

amend_access_artifact(artifact) click to toggle source

Amend each included access artifact.

artifact - an XMigra::StoredProcedure, XMigra::Function, or XMigra::View

The default implementation does nothing.

# File lib/xmigra/plugin.rb, line 101
def amend_access_artifact(artifact)
end
amend_composed_sql(sql) click to toggle source

Amend SQL for script after all parts are combined. This method will have an opportunity to amend all of the SQL in the output script, including SQL generated by XMigra.

XMigra only calls this method one time for the entire output script prior to any transformation necessary for script transactionality (e.g. splitting the script into batches and encoding as string literals). The one exception to this is for any branch upgrade SQL, which will already be encoded in one or more string literals.

The default implementation does nothing.

# File lib/xmigra/plugin.rb, line 81
def amend_composed_sql(sql)
end
amend_index(index) click to toggle source

Amend each included index.

The default implementation does nothing.

# File lib/xmigra/plugin.rb, line 132
def amend_index(index)
end
amend_source_sql(sql) click to toggle source

Amend SQL coming from source documents. The String object passed to this method will be included in the commands to run, and any modifications made to this object will be reflected in the script. XMigra only calls this method to amend SQL read in from source files.

The default implementation does nothing.

# File lib/xmigra/plugin.rb, line 65
def amend_source_sql(sql)
end
each_additional_access_artifact(db_specifics=nil) { |artifact| ... } click to toggle source

Yields additional access artifacts to include in the logical schema.

db_specifics - A module providing methods useful for building SQL

specific to the target RDBMS.

The yielded artifact objects must respond to name, depends_on and definition_sql.

The default implementation does not yield any objects.

# File lib/xmigra/plugin.rb, line 115
def each_additional_access_artifact(db_specifics=nil) # :yields: artifact
end
each_additional_index(db_specifics=nil) { |index| ... } click to toggle source

Yields additional indexes to include in the logical schema.

db_specifics - A module providing methods useful for building SQL

specific to the target RDBMS.

The yielded index objects must respond to name and definition_sql.

The default implementation does not yield any objects.

# File lib/xmigra/plugin.rb, line 145
def each_additional_index(db_specifics=nil) # :yields: index
end
include_access_artifact?(artifact) click to toggle source

Indicate if the access artifact (stored procedure, user defined function, or view) should be included in the logical schema.

The default implementation always returns true.

# File lib/xmigra/plugin.rb, line 90
def include_access_artifact?(artifact)
  true
end
include_index?(index) click to toggle source

Indicate if the index should be included in the logical schema.

The default implementation always return true.

# File lib/xmigra/plugin.rb, line 123
def include_index?(index)
  true
end