class Nandi::Config

Constants

DEFAULT_ACCESS_EXCLUSIVE_LOCK_TIMEOUT
DEFAULT_ACCESS_EXCLUSIVE_LOCK_TIMEOUT_LIMIT
DEFAULT_ACCESS_EXCLUSIVE_STATEMENT_TIMEOUT

Most DDL changes take a very strict lock, but execute very quickly. For these the statement timeout should be very tight, so that if there's an unexpected delay the query queue does not back up.

DEFAULT_ACCESS_EXCLUSIVE_STATEMENT_TIMEOUT_LIMIT
DEFAULT_COMPILE_FILES
DEFAULT_CONCURRENT_TIMEOUT_LIMIT
DEFAULT_LOCKFILE_DIRECTORY

Attributes

access_exclusive_lock_timeout[RW]

The default lock timeout for migrations that take ACCESS EXCLUSIVE locks. Can be overridden by way of the `set_lock_timeout` class method in a given migration. Default: 1500ms. @return [Integer]

access_exclusive_lock_timeout_limit[RW]

The maximum statement timeout for migrations that take an ACCESS EXCLUSIVE lock and therefore block all reads and writes. Default: 1500ms. @return [Integer]

access_exclusive_statement_timeout[RW]

The default statement timeout for migrations that take ACCESS EXCLUSIVE locks. Can be overridden by way of the `set_statement_timeout` class method in a given migration. Default: 1500ms. @return [Integer]

access_exclusive_statement_timeout_limit[RW]

The maximum lock timeout for migrations that take an ACCESS EXCLUSIVE lock and therefore block all reads and writes. Default: 5,000ms. @return [Integer]

compile_files[RW]

The files to compile when the compile generator is run. Default: `all` May be one of the following:

  • 'all' compiles all files

  • 'git-diff' only files changed since last commit

  • a full or partial version timestamp, eg '20190101010101', '20190101'

  • a timestamp range , eg '>=20190101010101'

@return [String]

concurrent_lock_timeout_limit[RW]

The minimum lock timeout for migrations that take place concurrently. Default: 3,600,000ms (ie, 3 hours). @return [Integer]

concurrent_statement_timeout_limit[RW]

The minimum statement timeout for migrations that take place concurrently. Default: 3,600,000ms (ie, 3 hours). @return [Integer]

custom_methods[R]

@api private

lockfile_directory[W]

Directory where .nandilock.yml will be stored Defaults to project root @return [String]

migration_directory[RW]

The directory for Nandi migrations. Default: `db/safe_migrations` @return [String]

output_directory[RW]

The directory for output files. Default: `db/migrate` @return [String]

post_processor[R]

@api private

renderer[RW]

The rendering backend used to produce output. The only supported option at current is Nandi::Renderers::ActiveRecord, which produces ActiveRecord migrations. @return [Class]

Public Class Methods

new(renderer: Renderers::ActiveRecord) click to toggle source
# File lib/nandi/config.rb, line 84
def initialize(renderer: Renderers::ActiveRecord)
  @renderer = renderer
  @access_exclusive_statement_timeout = DEFAULT_ACCESS_EXCLUSIVE_STATEMENT_TIMEOUT
  @concurrent_lock_timeout_limit =
    @concurrent_statement_timeout_limit =
      DEFAULT_CONCURRENT_TIMEOUT_LIMIT
  @custom_methods = {}
  @access_exclusive_lock_timeout =
    DEFAULT_ACCESS_EXCLUSIVE_LOCK_TIMEOUT
  @access_exclusive_statement_timeout =
    DEFAULT_ACCESS_EXCLUSIVE_STATEMENT_TIMEOUT
  @access_exclusive_statement_timeout_limit =
    DEFAULT_ACCESS_EXCLUSIVE_STATEMENT_TIMEOUT_LIMIT
  @access_exclusive_lock_timeout_limit = DEFAULT_ACCESS_EXCLUSIVE_LOCK_TIMEOUT_LIMIT
  @compile_files = DEFAULT_COMPILE_FILES
  @lockfile_directory = DEFAULT_LOCKFILE_DIRECTORY
end

Public Instance Methods

lockfile_directory() click to toggle source
# File lib/nandi/config.rb, line 122
def lockfile_directory
  @lockfile_directory ||= Pathname.new(@lockfile_directory)
end
post_process(&block) click to toggle source

Register a block to be called on output, for example a code formatter. Whatever is returned will be written to the output file. @yieldparam migration [string] The text of a compiled migration.

# File lib/nandi/config.rb, line 105
def post_process(&block)
  @post_processor = block
end
register_method(name, klass) click to toggle source

Register a custom DDL method. @param name [Symbol] The name of the method to create. This will be monkey-patched

into Nandi::Migration.

@param klass [Class] The class to initialise with the arguments to the

method. It should define a `template` instance method which will return a
subclass of Cell::ViewModel from the Cells templating library and a
`procedure` method that returns the name of the method. It may optionally
define a `mixins` method, which will return an array of `Module`s to be
mixed into any migration that uses this method.
# File lib/nandi/config.rb, line 118
def register_method(name, klass)
  custom_methods[name] = klass
end