Class: GDK::PostgresqlUpgrader
- Inherits:
-
Object
- Object
- GDK::PostgresqlUpgrader
- Extended by:
- Forwardable
- Defined in:
- lib/gdk/postgresql_upgrader.rb
Constant Summary collapse
- POSTGRESQL_VERSIONS =
%w[14 13 12 11 10 9.6].freeze
Instance Method Summary collapse
- #bin_path(version = target_version) ⇒ Object
- #bin_path_or_fallback ⇒ Object
-
#initialize(target_version = GDK::Postgresql.target_version_major) ⇒ PostgresqlUpgrader
constructor
A new instance of PostgresqlUpgrader.
- #upgrade! ⇒ Object
Constructor Details
#initialize(target_version = GDK::Postgresql.target_version_major) ⇒ PostgresqlUpgrader
Returns a new instance of PostgresqlUpgrader.
18 19 20 |
# File 'lib/gdk/postgresql_upgrader.rb', line 18 def initialize(target_version = GDK::Postgresql.target_version_major) @target_version = target_version end |
Instance Method Details
#bin_path(version = target_version) ⇒ Object
72 73 74 75 76 |
# File 'lib/gdk/postgresql_upgrader.rb', line 72 def bin_path(version = target_version) raise "Invalid PostgreSQL version #{version}" unless available_versions.key?(version) available_versions[version] end |
#bin_path_or_fallback ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gdk/postgresql_upgrader.rb', line 56 def bin_path_or_fallback dir = begin bin_path rescue StandardError # Fallback to whatever pg_config is in the PATH pg_config_discover end unless dir GDK::Output.warn 'Unable to determine PostgreSQL bin directory. Using fallback.' return nil end dir end |
#upgrade! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gdk/postgresql_upgrader.rb', line 22 def upgrade! check! success = true unless upgrade_needed?(target_version) GDK::Output.success "'#{current_data_dir}' is already compatible with PostgreSQL #{target_version}." return end begin gdk_stop init_db_in_target_path pgvector_setup rename_current_data_dir pg_upgrade promote_new_db gdk_reconfigure pg_replica_upgrade('replica') pg_replica_upgrade('replica_2') rescue StandardError => e success = false GDK::Output.error("An error occurred: #{e}", e) GDK::Output.warn 'Rolling back..' rename_current_data_dir_back end if success GDK::Output.success "Upgraded '#{current_data_dir}' from PostgreSQL #{current_version} to #{target_version}." else GDK::Output.warn "Upgrade failed. Rolled back to the original PostgreSQL #{current_version}." end end |