Class: Nandi::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/nandi/config.rb

Constant Summary collapse

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.

1_500
DEFAULT_ACCESS_EXCLUSIVE_LOCK_TIMEOUT =
5_000
DEFAULT_ACCESS_EXCLUSIVE_STATEMENT_TIMEOUT_LIMIT =
DEFAULT_ACCESS_EXCLUSIVE_STATEMENT_TIMEOUT
DEFAULT_ACCESS_EXCLUSIVE_LOCK_TIMEOUT_LIMIT =
DEFAULT_ACCESS_EXCLUSIVE_LOCK_TIMEOUT
DEFAULT_LOCKFILE_DIRECTORY =
File.join(Dir.pwd, "db")
DEFAULT_CONCURRENT_TIMEOUT_LIMIT =
3_600_000
DEFAULT_COMPILE_FILES =
"all"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(renderer: Renderers::ActiveRecord) ⇒ Config

Returns a new instance of Config.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# 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

Instance Attribute Details

#access_exclusive_lock_timeoutInteger

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.

Returns:

  • (Integer)


31
32
33
# File 'lib/nandi/config.rb', line 31

def access_exclusive_lock_timeout
  @access_exclusive_lock_timeout
end

#access_exclusive_lock_timeout_limitInteger

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

Returns:

  • (Integer)


47
48
49
# File 'lib/nandi/config.rb', line 47

def access_exclusive_lock_timeout_limit
  @access_exclusive_lock_timeout_limit
end

#access_exclusive_statement_timeoutInteger

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.

Returns:

  • (Integer)


37
38
39
# File 'lib/nandi/config.rb', line 37

def access_exclusive_statement_timeout
  @access_exclusive_statement_timeout
end

#access_exclusive_statement_timeout_limitInteger

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

Returns:

  • (Integer)


42
43
44
# File 'lib/nandi/config.rb', line 42

def access_exclusive_statement_timeout_limit
  @access_exclusive_statement_timeout_limit
end

#compile_filesString

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’

Returns:

  • (String)


74
75
76
# File 'lib/nandi/config.rb', line 74

def compile_files
  @compile_files
end

#concurrent_lock_timeout_limitInteger

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

Returns:

  • (Integer)


57
58
59
# File 'lib/nandi/config.rb', line 57

def concurrent_lock_timeout_limit
  @concurrent_lock_timeout_limit
end

#concurrent_statement_timeout_limitInteger

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

Returns:

  • (Integer)


52
53
54
# File 'lib/nandi/config.rb', line 52

def concurrent_statement_timeout_limit
  @concurrent_statement_timeout_limit
end

#custom_methodsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



82
83
84
# File 'lib/nandi/config.rb', line 82

def custom_methods
  @custom_methods
end

#lockfile_directoryObject



122
123
124
# File 'lib/nandi/config.rb', line 122

def lockfile_directory
  @lockfile_directory ||= Pathname.new(@lockfile_directory)
end

#migration_directoryString

The directory for Nandi migrations. Default: ‘db/safe_migrations`

Returns:

  • (String)


61
62
63
# File 'lib/nandi/config.rb', line 61

def migration_directory
  @migration_directory
end

#output_directoryString

The directory for output files. Default: ‘db/migrate`

Returns:

  • (String)


65
66
67
# File 'lib/nandi/config.rb', line 65

def output_directory
  @output_directory
end

#post_processorObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



82
83
84
# File 'lib/nandi/config.rb', line 82

def post_processor
  @post_processor
end

#rendererClass

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

Returns:

  • (Class)


25
26
27
# File 'lib/nandi/config.rb', line 25

def renderer
  @renderer
end

Instance Method Details

#post_process {|migration| ... } ⇒ Object

Register a block to be called on output, for example a code formatter. Whatever is returned will be written to the output file.

Yield Parameters:

  • migration (string)

    The text of a compiled migration.



105
106
107
# File 'lib/nandi/config.rb', line 105

def post_process(&block)
  @post_processor = block
end

#register_method(name, klass) ⇒ Object

Register a custom DDL method.

Parameters:

  • name (Symbol)

    The name of the method to create. This will be monkey-patched into Nandi::Migration.

  • 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.



118
119
120
# File 'lib/nandi/config.rb', line 118

def register_method(name, klass)
  custom_methods[name] = klass
end