# HG changeset patch
# User Clemens Beck <cbeck@gitlab.com>
# Date 1715059468 0
#      Tue May 07 05:24:28 2024 +0000
# Node ID 2bef7ccdbf8fda4bf075da68c20b4af85c3e89f5
# Parent  96eee099b629ceffbf4be9dadeb2295ca1f2f4de
Remove PostgreSQL 13

* Remove PostgreSQL 13 builds.
* Remove unused PostgreSQL 12 build definition.
* Move PostgreSQL 14 from 'new' to 'default' build definition.
* Update minimum PostgreSQL version notice.

Closes https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/8341

Changelog: removed

diff --git a/config/patches/postgresql/no_docs.patch b/config/patches/postgresql/no_docs.patch
--- a/config/patches/postgresql/no_docs.patch
+++ b/config/patches/postgresql/no_docs.patch
@@ -5,18 +5,18 @@
 @@ -13,7 +13,7 @@ $(call recurse,all install,src config)
  docs:
  	$(MAKE) -C doc all
-
+ 
 -$(call recurse,world,doc src config contrib,all)
 +$(call recurse,world,src config contrib,all)
-
+ 
  # build src/ before contrib/
  world-contrib-recurse: world-src-recurse
 @@ -29,7 +29,7 @@ html man:
  install-docs:
  	$(MAKE) -C doc install
-
+ 
 -$(call recurse,install-world,doc src config contrib,install)
 +$(call recurse,install-world,src config contrib,install)
-
+ 
  # build src/ before contrib/
  install-world-contrib-recurse: install-world-src-recurse
diff --git a/config/patches/postgresql_new/no_docs.patch b/config/patches/postgresql_new/no_docs.patch
deleted file mode 100644
--- a/config/patches/postgresql_new/no_docs.patch
+++ /dev/null
@@ -1,22 +0,0 @@
-diff --git a/GNUmakefile.in b/GNUmakefile.in
-index 2352fc1..0191427 100644
---- a/GNUmakefile.in
-+++ b/GNUmakefile.in
-@@ -13,7 +13,7 @@ $(call recurse,all install,src config)
- docs:
- 	$(MAKE) -C doc all
- 
--$(call recurse,world,doc src config contrib,all)
-+$(call recurse,world,src config contrib,all)
- 
- # build src/ before contrib/
- world-contrib-recurse: world-src-recurse
-@@ -29,7 +29,7 @@ html man:
- install-docs:
- 	$(MAKE) -C doc install
- 
--$(call recurse,install-world,doc src config contrib,install)
-+$(call recurse,install-world,src config contrib,install)
- 
- # build src/ before contrib/
- install-world-contrib-recurse: install-world-src-recurse
diff --git a/config/patches/postgresql_old/no_docs.patch b/config/patches/postgresql_old/no_docs.patch
deleted file mode 100644
--- a/config/patches/postgresql_old/no_docs.patch
+++ /dev/null
@@ -1,22 +0,0 @@
-diff --git a/GNUmakefile.in b/GNUmakefile.in
-index 2352fc1..0191427 100644
---- a/GNUmakefile.in
-+++ b/GNUmakefile.in
-@@ -13,7 +13,7 @@ $(call recurse,all install,src config)
- docs:
- 	$(MAKE) -C doc all
-
--$(call recurse,world,doc src config contrib,all)
-+$(call recurse,world,src config contrib,all)
-
- # build src/ before contrib/
- world-contrib-recurse: world-src-recurse
-@@ -29,7 +29,7 @@ html man:
- install-docs:
- 	$(MAKE) -C doc install
-
--$(call recurse,install-world,doc src config contrib,install)
-+$(call recurse,install-world,src config contrib,install)
-
- # build src/ before contrib/
- install-world-contrib-recurse: install-world-src-recurse
diff --git a/config/software/gitlab-exporter.rb b/config/software/gitlab-exporter.rb
--- a/config/software/gitlab-exporter.rb
+++ b/config/software/gitlab-exporter.rb
@@ -23,7 +23,7 @@
 
 dependency 'ruby'
 dependency 'rubygems'
-dependency 'postgresql_new'
+dependency 'postgresql'
 
 build do
   patch source: 'add-license-file.patch'
diff --git a/config/software/gitlab-rails.rb b/config/software/gitlab-rails.rb
--- a/config/software/gitlab-rails.rb
+++ b/config/software/gitlab-rails.rb
@@ -48,7 +48,6 @@
 dependency 'rsync'
 dependency 'libicu'
 dependency 'postgresql'
-dependency 'postgresql_new'
 dependency 'python-docutils'
 dependency 'krb5'
 dependency 'registry'
diff --git a/config/software/postgresql.rb b/config/software/postgresql.rb
--- a/config/software/postgresql.rb
+++ b/config/software/postgresql.rb
@@ -16,7 +16,7 @@
 #
 
 name 'postgresql'
-default_version '13.14'
+default_version '14.11'
 
 license 'PostgreSQL'
 license_file 'COPYRIGHT'
@@ -30,11 +30,11 @@
 dependency 'libossp-uuid'
 dependency 'config_guess'
 
-version '13.14' do
-  source sha256: 'b8df078551898960bd500dc5d38a177e9905376df81fe7f2b660a1407fa6a5ed'
+version '14.11' do
+  source sha256: 'a670bd7dce22dcad4297b261136b3b1d4a09a6f541719562aa14ca63bf2968a8'
 end
 
-major_version = '13'
+major_version = '14'
 
 source url: "https://ftp.postgresql.org/pub/source/v#{version}/postgresql-#{version}.tar.bz2"
 
@@ -58,6 +58,19 @@
 
   make "world -j #{workers}", env: env
   make 'install-world', env: env
+
+  libpq = 'libpq.so.5'
+  link "#{prefix}/lib/#{libpq}", "#{install_dir}/embedded/lib/#{libpq}"
+
+  # NOTE: There are several dependencies which require these files in these
+  # locations and have dependency on `postgresql_new`. So when this block is
+  # changed to be in the `postgresql` software definition for default PG
+  # version changes, change those dependencies to `postgresql`.
+  block 'link bin files' do
+    Dir.glob("#{prefix}/bin/*").each do |bin_file|
+      link bin_file, "#{install_dir}/embedded/bin/#{File.basename(bin_file)}"
+    end
+  end
 end
 
 # exclude headers and static libraries from package
diff --git a/config/software/postgresql_new.rb b/config/software/postgresql_new.rb
deleted file mode 100644
--- a/config/software/postgresql_new.rb
+++ /dev/null
@@ -1,80 +0,0 @@
-#
-# Copyright 2012-2014 Chef Software, Inc.
-# Copyright:: Copyright (c) 2016 GitLab Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-name 'postgresql_new'
-default_version '14.11'
-
-license 'PostgreSQL'
-license_file 'COPYRIGHT'
-
-skip_transitive_dependency_licensing true
-
-dependency 'zlib'
-dependency 'openssl' unless Build::Check.use_system_ssl?
-dependency 'libedit'
-dependency 'ncurses'
-dependency 'libossp-uuid'
-dependency 'config_guess'
-
-version '14.11' do
-  source sha256: 'a670bd7dce22dcad4297b261136b3b1d4a09a6f541719562aa14ca63bf2968a8'
-end
-
-major_version = '14'
-libpq = 'libpq.so.5'
-
-source url: "https://ftp.postgresql.org/pub/source/v#{version}/postgresql-#{version}.tar.bz2"
-
-relative_path "postgresql-#{version}"
-
-build do
-  env = with_standard_compiler_flags(with_embedded_path)
-
-  env['CFLAGS'] << ' -fno-omit-frame-pointer'
-
-  prefix = "#{install_dir}/embedded/postgresql/#{major_version}"
-  update_config_guess(target: 'config')
-
-  patch source: 'no_docs.patch', target: 'GNUmakefile.in'
-
-  command './configure' \
-          " --prefix=#{prefix}" \
-          ' --with-libedit-preferred' \
-          ' --with-openssl' \
-          ' --with-uuid=ossp', env: env
-
-  make "world -j #{workers}", env: env
-  make 'install-world', env: env
-
-  link "#{prefix}/lib/#{libpq}", "#{install_dir}/embedded/lib/#{libpq}"
-
-  # NOTE: There are several dependencies which require these files in these
-  # locations and have dependency on `postgresql_new`. So when this block is
-  # changed to be in the `postgresql` software definition for default PG
-  # version changes, change those dependencies to `postgresql`.
-  block 'link bin files' do
-    Dir.glob("#{prefix}/bin/*").each do |bin_file|
-      link bin_file, "#{install_dir}/embedded/bin/#{File.basename(bin_file)}"
-    end
-  end
-end
-
-# exclude headers and static libraries from package
-project.exclude "embedded/postgresql/#{major_version}/include"
-project.exclude "embedded/postgresql/#{major_version}/lib/*.a"
-project.exclude "embedded/postgresql/#{major_version}/lib/pgxs"
-project.exclude "embedded/postgresql/#{major_version}/lib/pkgconfig"
diff --git a/config/software/postgresql_old.rb b/config/software/postgresql_old.rb
deleted file mode 100644
--- a/config/software/postgresql_old.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-#
-# Copyright 2012-2014 Chef Software, Inc.
-# Copyright:: Copyright (c) 2016 GitLab Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-name 'postgresql_old'
-default_version '12.14'
-
-license 'PostgreSQL'
-license_file 'COPYRIGHT'
-
-skip_transitive_dependency_licensing true
-
-dependency 'zlib'
-dependency 'openssl' unless Build::Check.use_system_ssl?
-dependency 'libedit'
-dependency 'ncurses'
-dependency 'libossp-uuid'
-dependency 'config_guess'
-
-version '12.14' do
-  source sha256: '785610237d382c842d356e347138e58c06ffeae240e6cc0b52ac5ebcc30d043e'
-end
-
-major_version = '12'
-
-source url: "https://ftp.postgresql.org/pub/source/v#{version}/postgresql-#{version}.tar.bz2"
-
-relative_path "postgresql-#{version}"
-
-build do
-  env = with_standard_compiler_flags(with_embedded_path)
-
-  env['CFLAGS'] << ' -fno-omit-frame-pointer'
-
-  prefix = "#{install_dir}/embedded/postgresql/#{major_version}"
-  update_config_guess(target: 'config')
-
-  patch source: 'no_docs.patch', target: 'GNUmakefile.in'
-
-  command './configure' \
-          " --prefix=#{prefix}" \
-          ' --with-libedit-preferred' \
-          ' --with-openssl' \
-          ' --with-uuid=ossp', env: env
-
-  make "world -j #{workers}", env: env
-  make 'install-world', env: env
-end
-
-# exclude headers and static libraries from package
-project.exclude "embedded/postgresql/#{major_version}/include"
-project.exclude "embedded/postgresql/#{major_version}/lib/*.a"
-project.exclude "embedded/postgresql/#{major_version}/lib/pgxs"
-project.exclude "embedded/postgresql/#{major_version}/lib/pkgconfig"
diff --git a/config/software/psycopg2.rb b/config/software/psycopg2.rb
--- a/config/software/psycopg2.rb
+++ b/config/software/psycopg2.rb
@@ -27,7 +27,7 @@
 source git: version.remote
 
 dependency 'python3'
-dependency 'postgresql_new'
+dependency 'postgresql'
 
 pg_major_version = '14'
 
diff --git a/config/templates/package-scripts/preinst.erb b/config/templates/package-scripts/preinst.erb
--- a/config/templates/package-scripts/preinst.erb
+++ b/config/templates/package-scripts/preinst.erb
@@ -60,7 +60,7 @@
 }
 
 pg_check() {
-  PG_MIN_VERSION=13
+  PG_MIN_VERSION=14
 
   # Fetch the currently running version from the database
   # If this doesn't work, assume this isn't a database node
diff --git a/docker/assets/wrapper b/docker/assets/wrapper
--- a/docker/assets/wrapper
+++ b/docker/assets/wrapper
@@ -152,7 +152,7 @@
 
 # This must be false when the opt-in PostgreSQL version is the default for pg-upgrade,
 # otherwise it must be true.
-ATTEMPT_AUTO_PG_UPGRADE='true'
+ATTEMPT_AUTO_PG_UPGRADE='false'
 
 # Make sure PostgreSQL is at the latest version.
 # If it fails, print a message with a workaround and exit
diff --git a/files/gitlab-cookbooks/gitlab/recipes/database_migrations.rb b/files/gitlab-cookbooks/gitlab/recipes/database_migrations.rb
--- a/files/gitlab-cookbooks/gitlab/recipes/database_migrations.rb
+++ b/files/gitlab-cookbooks/gitlab/recipes/database_migrations.rb
@@ -35,10 +35,10 @@
 ruby_block "check remote PG version" do
   block do
     remote_db_version = GitlabRailsEnvHelper.db_version
-    if remote_db_version && remote_db_version.to_f < 13
+    if remote_db_version && remote_db_version.to_f < 14
       LoggingHelper.warning(%q(
-        Note that PostgreSQL 13 is the minimum required PostgreSQL version in GitLab 16.0.
-        Support for PostgreSQL 12 has been removed.
+        Note that PostgreSQL 14 is the minimum required PostgreSQL version in GitLab 17.0.
+        Support for PostgreSQL 13 has been removed.
         To upgrade, please see: https://docs.gitlab.com/omnibus/settings/database.html#upgrade-packaged-postgresql-server
       ))
     end
diff --git a/files/gitlab-cookbooks/postgresql/recipes/bin.rb b/files/gitlab-cookbooks/postgresql/recipes/bin.rb
--- a/files/gitlab-cookbooks/postgresql/recipes/bin.rb
+++ b/files/gitlab-cookbooks/postgresql/recipes/bin.rb
@@ -40,7 +40,7 @@
 ruby_block 'check_postgresql_version_is_deprecated' do
   block do
     LoggingHelper.warning(%q(
-      Note that PostgreSQL 13 is the minimum required PostgreSQL version in GitLab 16.0.
+      Note that PostgreSQL 14 is the minimum required PostgreSQL version in GitLab 17.0.
       To upgrade, please see: https://docs.gitlab.com/omnibus/settings/database.html#upgrade-packaged-postgresql-server
     ))
   end
diff --git a/files/gitlab-ctl-commands/pg-upgrade.rb b/files/gitlab-ctl-commands/pg-upgrade.rb
--- a/files/gitlab-ctl-commands/pg-upgrade.rb
+++ b/files/gitlab-ctl-commands/pg-upgrade.rb
@@ -747,7 +747,7 @@
 end
 
 def default_version
-  PGVersion.parse(version_from_manifest('postgresql_new')) || PGVersion.parse(version_from_manifest('postgresql'))
+  PGVersion.parse(version_from_manifest('postgresql'))
 end
 
 def new_version
diff --git a/files/gitlab-ctl-commands/upgrade.rb b/files/gitlab-ctl-commands/upgrade.rb
--- a/files/gitlab-ctl-commands/upgrade.rb
+++ b/files/gitlab-ctl-commands/upgrade.rb
@@ -344,7 +344,7 @@
 def attempt_auto_pg_upgrade?
   # This must return false when the opt-in PostgreSQL version is the default for pg-upgrade,
   # otherwise it must be true.
-  true
+  false
 end
 
 def recommend_pg_upgrade?
diff --git a/spec/chef/cookbooks/gitlab/recipes/database_migrations_spec.rb b/spec/chef/cookbooks/gitlab/recipes/database_migrations_spec.rb
--- a/spec/chef/cookbooks/gitlab/recipes/database_migrations_spec.rb
+++ b/spec/chef/cookbooks/gitlab/recipes/database_migrations_spec.rb
@@ -37,14 +37,14 @@
       before { stub_gitlab_rb(postgresql: { enable: false }) }
 
       it 'warns about outdated databases' do
-        allow(GitlabRailsEnvHelper).to receive(:db_version).and_return(12)
+        allow(GitlabRailsEnvHelper).to receive(:db_version).and_return(13)
 
         expect(migration_block).to notify('ruby_block[check remote PG version]').to(:run)
         expect(chef_run.ruby_block('check remote PG version').should_skip?(:run)).to be_falsey
 
         chef_run.ruby_block('check remote PG version').block.call
 
-        expect_logged_warning(/Support for PostgreSQL 12 has been removed/)
+        expect_logged_warning(/Support for PostgreSQL 13 has been removed/)
       end
     end