Commit 93d61065 authored by Mitchell Nielsen's avatar Mitchell Nielsen Committed by Douglas Barbosa Alexandre

Parameterize PG deprecation notice in admin UI

parent 2ff70c48
---
title: Parameterize PG deprecation notice
merge_request: 35271
author:
type: changed
......@@ -5,22 +5,43 @@ module Gitlab
module ExternalDatabaseChecker
extend self
# DB is considered deprecated if it is below version 11
def db_version_deprecated?
Gitlab::Database.version.to_f < 11
end
def check
return [] unless db_version_deprecated?
notices = []
unless Gitlab::Database.postgresql_minimum_supported_version?
notices <<
{
type: 'warning',
message: _('You are using PostgreSQL %{pg_version_current}, but PostgreSQL ' \
'%{pg_version_minimum} is required for this version of GitLab. ' \
'Please upgrade your environment to a supported PostgreSQL version, ' \
'see %{pg_requirements_url} for details.') % {
pg_version_current: Gitlab::Database.version,
pg_version_minimum: Gitlab::Database::MINIMUM_POSTGRES_VERSION,
pg_requirements_url: '<a href="https://docs.gitlab.com/ee/install/requirements.html#database">database requirements</a>'
}
}
end
if Gitlab::Database.postgresql_upcoming_deprecation?
upcoming_deprecation = Gitlab::Database::UPCOMING_POSTGRES_VERSION_DETAILS
notices <<
{
type: 'warning',
message: _('Note that PostgreSQL %{pg_version_upcoming} will become the minimum required ' \
'version in GitLab %{gl_version_upcoming} (%{gl_version_upcoming_date}). Please ' \
'consider upgrading your environment to a supported PostgreSQL version soon, ' \
'see <a href="%{pg_version_upcoming_url}">the related epic</a> for details.') % {
pg_version_upcoming: upcoming_deprecation[:pg_version_minimum],
gl_version_upcoming: upcoming_deprecation[:gl_version],
gl_version_upcoming_date: upcoming_deprecation[:gl_version_date],
pg_version_upcoming_url: upcoming_deprecation[:url]
}
}
end
[
{
type: 'warning',
message: _('Note that PostgreSQL 11 will become the minimum required PostgreSQL version in GitLab 13.0 (May 2020). '\
'PostgreSQL 9.6 and PostgreSQL 10 will no longer be supported in GitLab 13.0. '\
'Please consider upgrading your PostgreSQL version (%{db_version}) soon.') % { db_version: Gitlab::Database.version.to_s }
}
]
notices
end
end
end
......
......@@ -4,8 +4,20 @@ module Gitlab
module Database
include Gitlab::Metrics::Methods
# Minimum PostgreSQL version requirement per documentation:
# https://docs.gitlab.com/ee/install/requirements.html#postgresql-requirements
MINIMUM_POSTGRES_VERSION = 11
# Upcoming PostgreSQL version requirements
# Allows a soft warning about an upcoming minimum version requirement
# so administrators can prepare to upgrade
UPCOMING_POSTGRES_VERSION_DETAILS = {
gl_version: '13.6.0',
gl_version_date: 'November 2020',
pg_version_minimum: 12,
url: 'https://gitlab.com/groups/gitlab-org/-/epics/2374'
}.freeze
# https://www.postgresql.org/docs/9.2/static/datatype-numeric.html
MAX_INT_VALUE = 2147483647
......@@ -103,6 +115,10 @@ module Gitlab
version.to_f >= MINIMUM_POSTGRES_VERSION
end
def self.postgresql_upcoming_deprecation?
version.to_f < UPCOMING_POSTGRES_VERSION_DETAILS[:pg_version_minimum]
end
def self.check_postgres_version_and_print_warning
return if Gitlab::Database.postgresql_minimum_supported_version?
return if Gitlab::Runtime.rails_runner?
......
......@@ -15762,7 +15762,7 @@ msgstr ""
msgid "Note parameters are invalid: %{errors}"
msgstr ""
msgid "Note that PostgreSQL 11 will become the minimum required PostgreSQL version in GitLab 13.0 (May 2020). PostgreSQL 9.6 and PostgreSQL 10 will no longer be supported in GitLab 13.0. Please consider upgrading your PostgreSQL version (%{db_version}) soon."
msgid "Note that PostgreSQL %{pg_version_upcoming} will become the minimum required version in GitLab %{gl_version_upcoming} (%{gl_version_upcoming_date}). Please consider upgrading your environment to a supported PostgreSQL version soon, see <a href=\"%{pg_version_upcoming_url}\">the related epic</a> for details."
msgstr ""
msgid "Note that this invitation was sent to %{mail_to_invite_email}, but you are signed in as %{link_to_current_user} with email %{mail_to_current_user}."
......@@ -26563,6 +26563,9 @@ msgstr ""
msgid "You are trying to upload something other than an image. Please upload a .png, .jpg, .jpeg, .gif, .bmp, .tiff or .ico."
msgstr ""
msgid "You are using PostgreSQL %{pg_version_current}, but PostgreSQL %{pg_version_minimum} is required for this version of GitLab. Please upgrade your environment to a supported PostgreSQL version, see %{pg_requirements_url} for details."
msgstr ""
msgid "You can %{linkStart}view the blob%{linkEnd} instead."
msgstr ""
......
......@@ -6,51 +6,54 @@ RSpec.describe Gitlab::ConfigChecker::ExternalDatabaseChecker do
describe '#check' do
subject { described_class.check }
context 'database version is not deprecated' do
let_it_be(:deprecation_warning) { "Please upgrade" }
let_it_be(:upcoming_deprecation_warning) { "Please consider upgrading" }
context 'when database meets minimum version and there is no upcoming deprecation' do
before do
allow(described_class).to receive(:db_version_deprecated?).and_return(false)
allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(true)
allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(false)
end
it { is_expected.to be_empty }
end
context 'database version is deprecated' do
context 'when database does not meet minimum version and there is no upcoming deprecation' do
before do
allow(described_class).to receive(:db_version_deprecated?).and_return(true)
end
let(:notice_deprecated_database) do
{
type: 'warning',
message: _('Note that PostgreSQL 11 will become the minimum required PostgreSQL version in GitLab 13.0 (May 2020). '\
'PostgreSQL 9.6 and PostgreSQL 10 will no longer be supported in GitLab 13.0. '\
'Please consider upgrading your PostgreSQL version (%{db_version}) soon.') % { db_version: Gitlab::Database.version.to_s }
}
allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(false)
allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(false)
end
it 'reports deprecated database notices' do
is_expected.to contain_exactly(notice_deprecated_database)
it 'only returns notice about deprecated database version' do
is_expected.to include(a_hash_including(message: include(deprecation_warning)))
is_expected.not_to include(a_hash_including(message: include(upcoming_deprecation_warning)))
end
end
end
describe '#db_version_deprecated' do
subject { described_class.db_version_deprecated? }
context 'database version is not deprecated' do
context 'when database meets minimum version and there is an upcoming deprecation' do
before do
allow(Gitlab::Database).to receive(:version).and_return(11)
allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(true)
allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(true)
end
it { is_expected.to be false }
it 'only returns notice about an upcoming deprecation' do
is_expected.to include(a_hash_including(message: include(upcoming_deprecation_warning)))
is_expected.not_to include(a_hash_including(message: include(deprecation_warning)))
end
end
context 'database version is deprecated' do
context 'when database does not meet minimum version and there is an upcoming deprecation' do
before do
allow(Gitlab::Database).to receive(:version).and_return(10)
allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(false)
allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(true)
end
it { is_expected.to be true }
it 'returns notice about deprecated database version and an upcoming deprecation' do
is_expected.to include(
a_hash_including(message: include(deprecation_warning)),
a_hash_including(message: include(upcoming_deprecation_warning))
)
end
end
end
end
......@@ -90,28 +90,42 @@ RSpec.describe Gitlab::Database do
end
describe '.postgresql_minimum_supported_version?' do
it 'returns false when using PostgreSQL 9.5' do
allow(described_class).to receive(:version).and_return('9.5')
it 'returns false when using PostgreSQL 10' do
allow(described_class).to receive(:version).and_return('10')
expect(described_class.postgresql_minimum_supported_version?).to eq(false)
end
it 'returns false when using PostgreSQL 9.6' do
allow(described_class).to receive(:version).and_return('9.6')
it 'returns true when using PostgreSQL 11' do
allow(described_class).to receive(:version).and_return('11')
expect(described_class.postgresql_minimum_supported_version?).to eq(false)
expect(described_class.postgresql_minimum_supported_version?).to eq(true)
end
it 'returns false when using PostgreSQL 10' do
allow(described_class).to receive(:version).and_return('10')
it 'returns true when using PostgreSQL 12' do
allow(described_class).to receive(:version).and_return('12')
expect(described_class.postgresql_minimum_supported_version?).to eq(false)
expect(described_class.postgresql_minimum_supported_version?).to eq(true)
end
end
it 'returns true when using PostgreSQL 11 or newer' do
allow(described_class).to receive(:version).and_return('11.0')
describe '.postgresql_upcoming_deprecation?' do
it 'returns true when database version is lower than the upcoming minimum' do
allow(described_class).to receive(:version).and_return('11')
expect(described_class.postgresql_minimum_supported_version?).to eq(true)
expect(described_class.postgresql_upcoming_deprecation?).to eq(true)
end
it 'returns false when database version equals the upcoming minimum' do
allow(described_class).to receive(:version).and_return('12')
expect(described_class.postgresql_upcoming_deprecation?).to eq(false)
end
it 'returns false when database version is greater the upcoming minimum' do
allow(described_class).to receive(:version).and_return('13')
expect(described_class.postgresql_upcoming_deprecation?).to eq(false)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment