Class: Gitlab::Database::DatabaseConnectionInfo

Inherits:
Struct
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/database/database_connection_info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDatabaseConnectionInfo

Returns a new instance of DatabaseConnectionInfo.



19
20
21
22
23
24
25
26
27
# File 'lib/gitlab/database/database_connection_info.rb', line 19

def initialize(*)
  super
  self.name = name.to_sym
  self.gitlab_schemas = gitlab_schemas.map(&:to_sym)
  self.klass = klass.constantize
  self.lock_gitlab_schemas = (lock_gitlab_schemas || []).map(&:to_sym)
  self.fallback_database = fallback_database&.to_sym
  self.db_dir = Rails.root.join(db_dir || 'db')
end

Instance Attribute Details

#db_dirObject

Returns the value of attribute db_dir

Returns:

  • (Object)

    the current value of db_dir



5
6
7
# File 'lib/gitlab/database/database_connection_info.rb', line 5

def db_dir
  @db_dir
end

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



5
6
7
# File 'lib/gitlab/database/database_connection_info.rb', line 5

def description
  @description
end

#fallback_databaseObject

Returns the value of attribute fallback_database

Returns:

  • (Object)

    the current value of fallback_database



5
6
7
# File 'lib/gitlab/database/database_connection_info.rb', line 5

def fallback_database
  @fallback_database
end

#file_pathObject

Returns the value of attribute file_path

Returns:

  • (Object)

    the current value of file_path



5
6
7
# File 'lib/gitlab/database/database_connection_info.rb', line 5

def file_path
  @file_path
end

#gitlab_schemasObject

Returns the value of attribute gitlab_schemas

Returns:

  • (Object)

    the current value of gitlab_schemas



5
6
7
# File 'lib/gitlab/database/database_connection_info.rb', line 5

def gitlab_schemas
  @gitlab_schemas
end

#klassObject

Returns the value of attribute klass

Returns:

  • (Object)

    the current value of klass



5
6
7
# File 'lib/gitlab/database/database_connection_info.rb', line 5

def klass
  @klass
end

#lock_gitlab_schemasObject

Returns the value of attribute lock_gitlab_schemas

Returns:

  • (Object)

    the current value of lock_gitlab_schemas



5
6
7
# File 'lib/gitlab/database/database_connection_info.rb', line 5

def lock_gitlab_schemas
  @lock_gitlab_schemas
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



5
6
7
# File 'lib/gitlab/database/database_connection_info.rb', line 5

def name
  @name
end

#uses_load_balancingObject

Returns the value of attribute uses_load_balancing

Returns:

  • (Object)

    the current value of uses_load_balancing



5
6
7
# File 'lib/gitlab/database/database_connection_info.rb', line 5

def uses_load_balancing
  @uses_load_balancing
end

Class Method Details

.load_file(yaml_file) ⇒ Object



29
30
31
32
# File 'lib/gitlab/database/database_connection_info.rb', line 29

def self.load_file(yaml_file)
  content = YAML.load_file(yaml_file)
  new(**content.deep_symbolize_keys.merge(file_path: yaml_file))
end

Instance Method Details

#connection_class_or_fallback(all_databases) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/gitlab/database/database_connection_info.rb', line 51

def connection_class_or_fallback(all_databases)
  if connection_class
    connection_class
  elsif fallback_database
    all_databases.fetch(fallback_database)
      .connection_class_or_fallback(all_databases)
  end
end

#db_docs_dirObject



68
69
70
# File 'lib/gitlab/database/database_connection_info.rb', line 68

def db_docs_dir
  db_dir.join('docs')
end

#has_gitlab_shared?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/gitlab/database/database_connection_info.rb', line 60

def has_gitlab_shared?
  gitlab_schemas.include?(:gitlab_shared)
end

#uses_load_balancing?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/gitlab/database/database_connection_info.rb', line 64

def uses_load_balancing?
  !!uses_load_balancing
end