Class: ActivePostgres::Components::Core

Inherits:
Base
  • Object
show all
Defined in:
lib/active_postgres/components/core.rb

Instance Attribute Summary

Attributes inherited from Base

#config, #secrets, #ssh_executor

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from ActivePostgres::Components::Base

Instance Method Details

#create_application_usersObject

Public method to create application users - called after repmgr setup This is done after repmgr to avoid being wiped by cluster recreation



45
46
47
48
49
50
# File 'lib/active_postgres/components/core.rb', line 45

def create_application_users
  return unless config.app_user && config.app_database

  puts "\nšŸ“ Creating application users and databases..."
  create_app_user_and_database(config.primary_host)
end

#installObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_postgres/components/core.rb', line 4

def install
  puts 'Installing PostgreSQL core...'

  # Install on primary
  install_on_host(config.primary_host, is_primary: true)

  # NOTE: App user creation moved to after repmgr setup to avoid being wiped
  # See: create_application_user_and_database method called from deployment flow

  # Install on standbys
  config.standby_hosts.each do |host|
    if config.component_enabled?(:repmgr)
      # Check if cluster already exists (config update vs fresh install)
      if cluster_exists?(host)
        # Existing cluster - just update configs
        update_configs_on_host(host)
      else
        # Fresh install - only install packages, repmgr will clone the cluster
        install_packages_only(host)
      end
    else
      install_on_host(host, is_primary: false)
    end
  end
end

#install_packages_only(host) ⇒ Object



52
53
54
55
# File 'lib/active_postgres/components/core.rb', line 52

def install_packages_only(host)
  puts "  Installing packages on #{host} (cluster will be created by repmgr)..."
  ssh_executor.install_postgres(host, config.version)
end

#restartObject



34
35
36
37
38
39
40
41
# File 'lib/active_postgres/components/core.rb', line 34

def restart
  puts 'Restarting PostgreSQL...'

  # Restart on all hosts
  config.all_hosts.each do |host|
    ssh_executor.restart_postgres(host, config.version)
  end
end

#uninstallObject



30
31
32
# File 'lib/active_postgres/components/core.rb', line 30

def uninstall
  puts 'Uninstalling PostgreSQL is not recommended and must be done manually.'
end