Class: Nandi::MultiDatabase::Database
- Inherits:
-
Object
- Object
- Nandi::MultiDatabase::Database
- Defined in:
- lib/nandi/multi_database.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_MAX =
DEFAULT_ACCESS_EXCLUSIVE_STATEMENT_TIMEOUT- DEFAULT_ACCESS_EXCLUSIVE_LOCK_TIMEOUT_MAX =
DEFAULT_ACCESS_EXCLUSIVE_LOCK_TIMEOUT- DEFAULT_CONCURRENT_LOCK_TIMEOUT_MIN =
10_000- DEFAULT_CONCURRENT_STATEMENT_TIMEOUT_MIN =
30_000- DEFAULT_MIGRATION_DIRECTORY =
"db/safe_migrations"- DEFAULT_OUTPUT_DIRECTORY =
"db/migrate"- RENAMED_KEYS =
{ access_exclusive_lock_timeout_limit: :access_exclusive_lock_timeout_max, access_exclusive_statement_timeout_limit: :access_exclusive_statement_timeout_max, concurrent_lock_timeout_limit: :concurrent_lock_timeout_min, concurrent_statement_timeout_limit: :concurrent_statement_timeout_min, }.freeze
Instance Attribute Summary collapse
-
#access_exclusive_lock_timeout ⇒ Integer
The default lock timeout for migrations that take ACCESS EXCLUSIVE locks.
-
#access_exclusive_lock_timeout_max ⇒ 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_max ⇒ Integer
The maximum lock timeout for migrations that take an ACCESS EXCLUSIVE lock and therefore block all reads and writes.
-
#concurrent_lock_timeout ⇒ Integer?
The default lock timeout for migrations that take place concurrently (eg. add_index, remove_index).
-
#concurrent_lock_timeout_min ⇒ Integer
The minimum lock timeout for migrations that take place concurrently.
-
#concurrent_statement_timeout ⇒ Integer?
The default statement timeout for migrations that take place concurrently (eg. add_index, remove_index).
-
#concurrent_statement_timeout_min ⇒ Integer
The minimum statement timeout for migrations that take place concurrently.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#lockfile_name ⇒ Object
Returns the value of attribute lockfile_name.
-
#migration_directory ⇒ Object
Returns the value of attribute migration_directory.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#output_directory ⇒ String
The directory for output files.
-
#raw_config ⇒ Object
readonly
Returns the value of attribute raw_config.
Instance Method Summary collapse
-
#initialize(name:, config:) ⇒ Database
constructor
A new instance of Database.
Constructor Details
#initialize(name:, config:) ⇒ Database
Returns a new instance of Database.
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/nandi/multi_database.rb', line 82 def initialize(name:, config:) @name = name @raw_config = config @default = @name == :primary || config[:default] == true # Paths and files @migration_directory = config[:migration_directory] || "db/#{path_prefix(name, default)}safe_migrations" @output_directory = config[:output_directory] || "db/#{path_prefix(name, default)}migrate" @lockfile_name = config[:lockfile_name] || ".#{path_prefix(name, default)}nandilock.yml" timeout_limits(normalize_config(config)) 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.
26 27 28 |
# File 'lib/nandi/multi_database.rb', line 26 def access_exclusive_lock_timeout @access_exclusive_lock_timeout end |
#access_exclusive_lock_timeout_max ⇒ Integer
The maximum statement timeout for migrations that take an ACCESS EXCLUSIVE lock and therefore block all reads and writes. Default: 1500ms.
42 43 44 |
# File 'lib/nandi/multi_database.rb', line 42 def access_exclusive_lock_timeout_max @access_exclusive_lock_timeout_max 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.
32 33 34 |
# File 'lib/nandi/multi_database.rb', line 32 def access_exclusive_statement_timeout @access_exclusive_statement_timeout end |
#access_exclusive_statement_timeout_max ⇒ Integer
The maximum lock timeout for migrations that take an ACCESS EXCLUSIVE lock and therefore block all reads and writes. Default: 5,000ms.
37 38 39 |
# File 'lib/nandi/multi_database.rb', line 37 def access_exclusive_statement_timeout_max @access_exclusive_statement_timeout_max end |
#concurrent_lock_timeout ⇒ Integer?
The default lock timeout for migrations that take place concurrently (eg. add_index, remove_index). When set, concurrent migrations will use set_lock_timeout instead of disable_lock_timeout!. Default: nil (disabled).
58 59 60 |
# File 'lib/nandi/multi_database.rb', line 58 def concurrent_lock_timeout @concurrent_lock_timeout end |
#concurrent_lock_timeout_min ⇒ Integer
The minimum lock timeout for migrations that take place concurrently. Default: 3,600,000ms (ie, 3 hours).
52 53 54 |
# File 'lib/nandi/multi_database.rb', line 52 def concurrent_lock_timeout_min @concurrent_lock_timeout_min end |
#concurrent_statement_timeout ⇒ Integer?
The default statement timeout for migrations that take place concurrently (eg. add_index, remove_index). When set, concurrent migrations will use set_statement_timeout instead of disable_statement_timeout!. Default: nil (disabled).
64 65 66 |
# File 'lib/nandi/multi_database.rb', line 64 def concurrent_statement_timeout @concurrent_statement_timeout end |
#concurrent_statement_timeout_min ⇒ Integer
The minimum statement timeout for migrations that take place concurrently. Default: 3,600,000ms (ie, 3 hours).
47 48 49 |
# File 'lib/nandi/multi_database.rb', line 47 def concurrent_statement_timeout_min @concurrent_statement_timeout_min end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
70 71 72 |
# File 'lib/nandi/multi_database.rb', line 70 def default @default end |
#lockfile_name ⇒ Object
Returns the value of attribute lockfile_name.
72 73 74 |
# File 'lib/nandi/multi_database.rb', line 72 def lockfile_name @lockfile_name end |
#migration_directory ⇒ Object
Returns the value of attribute migration_directory.
72 73 74 |
# File 'lib/nandi/multi_database.rb', line 72 def migration_directory @migration_directory end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
70 71 72 |
# File 'lib/nandi/multi_database.rb', line 70 def name @name end |
#output_directory ⇒ String
The directory for output files. Default: ‘db/migrate`
68 69 70 |
# File 'lib/nandi/multi_database.rb', line 68 def output_directory @output_directory end |
#raw_config ⇒ Object (readonly)
Returns the value of attribute raw_config.
70 71 72 |
# File 'lib/nandi/multi_database.rb', line 70 def raw_config @raw_config end |