Class: Nandi::Config
- Inherits:
-
Object
- Object
- Nandi::Config
- 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
-
#access_exclusive_lock_timeout ⇒ Integer
The default lock timeout for migrations that take ACCESS EXCLUSIVE locks.
-
#access_exclusive_lock_timeout_limit ⇒ Integer
The maximum statement timeout for migrations that take an ACCESS EXCLUSIVE lock and therefore block all reads and writes.
-
#access_exclusive_statement_timeout ⇒ Integer
The default statement timeout for migrations that take ACCESS EXCLUSIVE locks.
-
#access_exclusive_statement_timeout_limit ⇒ Integer
The maximum lock timeout for migrations that take an ACCESS EXCLUSIVE lock and therefore block all reads and writes.
-
#compile_files ⇒ String
The files to compile when the compile generator is run.
-
#concurrent_lock_timeout_limit ⇒ Integer
The minimum lock timeout for migrations that take place concurrently.
-
#concurrent_statement_timeout_limit ⇒ Integer
The minimum statement timeout for migrations that take place concurrently.
- #custom_methods ⇒ Object readonly private
- #lockfile_directory ⇒ Object
-
#migration_directory ⇒ String
The directory for Nandi migrations.
-
#output_directory ⇒ String
The directory for output files.
- #post_processor ⇒ Object readonly private
-
#renderer ⇒ Class
The rendering backend used to produce output.
Instance Method Summary collapse
-
#initialize(renderer: Renderers::ActiveRecord) ⇒ Config
constructor
A new instance of Config.
-
#post_process {|migration| ... } ⇒ Object
Register a block to be called on output, for example a code formatter.
-
#register_method(name, klass) ⇒ Object
Register a custom DDL method.
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_timeout ⇒ Integer
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.
31 32 33 |
# File 'lib/nandi/config.rb', line 31 def access_exclusive_lock_timeout @access_exclusive_lock_timeout end |
#access_exclusive_lock_timeout_limit ⇒ Integer
The maximum statement timeout for migrations that take an ACCESS EXCLUSIVE lock and therefore block all reads and writes. Default: 1500ms.
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_timeout ⇒ Integer
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.
37 38 39 |
# File 'lib/nandi/config.rb', line 37 def access_exclusive_statement_timeout @access_exclusive_statement_timeout end |
#access_exclusive_statement_timeout_limit ⇒ Integer
The maximum lock timeout for migrations that take an ACCESS EXCLUSIVE lock and therefore block all reads and writes. Default: 5,000ms.
42 43 44 |
# File 'lib/nandi/config.rb', line 42 def access_exclusive_statement_timeout_limit @access_exclusive_statement_timeout_limit end |
#compile_files ⇒ String
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’
74 75 76 |
# File 'lib/nandi/config.rb', line 74 def compile_files @compile_files end |
#concurrent_lock_timeout_limit ⇒ Integer
The minimum lock timeout for migrations that take place concurrently. Default: 3,600,000ms (ie, 3 hours).
57 58 59 |
# File 'lib/nandi/config.rb', line 57 def concurrent_lock_timeout_limit @concurrent_lock_timeout_limit end |
#concurrent_statement_timeout_limit ⇒ Integer
The minimum statement timeout for migrations that take place concurrently. Default: 3,600,000ms (ie, 3 hours).
52 53 54 |
# File 'lib/nandi/config.rb', line 52 def concurrent_statement_timeout_limit @concurrent_statement_timeout_limit end |
#custom_methods ⇒ Object (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_directory ⇒ Object
122 123 124 |
# File 'lib/nandi/config.rb', line 122 def lockfile_directory @lockfile_directory ||= Pathname.new(@lockfile_directory) end |
#migration_directory ⇒ String
The directory for Nandi migrations. Default: ‘db/safe_migrations`
61 62 63 |
# File 'lib/nandi/config.rb', line 61 def migration_directory @migration_directory end |
#output_directory ⇒ String
The directory for output files. Default: ‘db/migrate`
65 66 67 |
# File 'lib/nandi/config.rb', line 65 def output_directory @output_directory end |
#post_processor ⇒ Object (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 |
#renderer ⇒ Class
The rendering backend used to produce output. The only supported option at current is Nandi::Renderers::ActiveRecord, which produces ActiveRecord migrations.
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.
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.
118 119 120 |
# File 'lib/nandi/config.rb', line 118 def register_method(name, klass) custom_methods[name] = klass end |