Class: Nandi::MultiDatabase::Database

Inherits:
Object
  • Object
show all
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_LIMIT =
DEFAULT_ACCESS_EXCLUSIVE_STATEMENT_TIMEOUT
DEFAULT_ACCESS_EXCLUSIVE_LOCK_TIMEOUT_LIMIT =
DEFAULT_ACCESS_EXCLUSIVE_LOCK_TIMEOUT
DEFAULT_CONCURRENT_TIMEOUT_LIMIT =
3_600_000
DEFAULT_MIGRATION_DIRECTORY =
"db/safe_migrations"
DEFAULT_OUTPUT_DIRECTORY =
"db/migrate"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, config:) ⇒ Database

Returns a new instance of Database.



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/nandi/multi_database.rb', line 62

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(config)
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)


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

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)


41
42
43
# File 'lib/nandi/multi_database.rb', line 41

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)


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

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)


36
37
38
# File 'lib/nandi/multi_database.rb', line 36

def access_exclusive_statement_timeout_limit
  @access_exclusive_statement_timeout_limit
end

#concurrent_lock_timeout_limitInteger

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

Returns:

  • (Integer)


51
52
53
# File 'lib/nandi/multi_database.rb', line 51

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)


46
47
48
# File 'lib/nandi/multi_database.rb', line 46

def concurrent_statement_timeout_limit
  @concurrent_statement_timeout_limit
end

#defaultObject (readonly)

Returns the value of attribute default.



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

def default
  @default
end

#lockfile_nameObject

Returns the value of attribute lockfile_name.



59
60
61
# File 'lib/nandi/multi_database.rb', line 59

def lockfile_name
  @lockfile_name
end

#migration_directoryObject

Returns the value of attribute migration_directory.



59
60
61
# File 'lib/nandi/multi_database.rb', line 59

def migration_directory
  @migration_directory
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#output_directoryString

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

Returns:

  • (String)


55
56
57
# File 'lib/nandi/multi_database.rb', line 55

def output_directory
  @output_directory
end

#raw_configObject (readonly)

Returns the value of attribute raw_config.



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

def raw_config
  @raw_config
end