Commit 5f25bbd2 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'parameterize-pg-deprecation-notice' into 'master'

Parameterize PG deprecation notice in admin UI

Closes omnibus-gitlab#5097

See merge request gitlab-org/gitlab!35271
parents f509b553 93d61065
---
title: Parameterize PG deprecation notice
merge_request: 35271
author:
type: changed
...@@ -5,22 +5,43 @@ module Gitlab ...@@ -5,22 +5,43 @@ module Gitlab
module ExternalDatabaseChecker module ExternalDatabaseChecker
extend self 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 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
[ notices
{
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 }
}
]
end end
end end
end end
......
...@@ -4,8 +4,20 @@ module Gitlab ...@@ -4,8 +4,20 @@ module Gitlab
module Database module Database
include Gitlab::Metrics::Methods include Gitlab::Metrics::Methods
# Minimum PostgreSQL version requirement per documentation:
# https://docs.gitlab.com/ee/install/requirements.html#postgresql-requirements
MINIMUM_POSTGRES_VERSION = 11 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 # https://www.postgresql.org/docs/9.2/static/datatype-numeric.html
MAX_INT_VALUE = 2147483647 MAX_INT_VALUE = 2147483647
...@@ -103,6 +115,10 @@ module Gitlab ...@@ -103,6 +115,10 @@ module Gitlab
version.to_f >= MINIMUM_POSTGRES_VERSION version.to_f >= MINIMUM_POSTGRES_VERSION
end 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 def self.check_postgres_version_and_print_warning
return if Gitlab::Database.postgresql_minimum_supported_version? return if Gitlab::Database.postgresql_minimum_supported_version?
return if Gitlab::Runtime.rails_runner? return if Gitlab::Runtime.rails_runner?
......
...@@ -15820,7 +15820,7 @@ msgstr "" ...@@ -15820,7 +15820,7 @@ msgstr ""
msgid "Note parameters are invalid: %{errors}" msgid "Note parameters are invalid: %{errors}"
msgstr "" 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 "" 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}." 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}."
...@@ -26651,6 +26651,9 @@ msgstr "" ...@@ -26651,6 +26651,9 @@ msgstr ""
msgid "You are trying to upload something other than an image. Please upload a .png, .jpg, .jpeg, .gif, .bmp, .tiff or .ico." msgid "You are trying to upload something other than an image. Please upload a .png, .jpg, .jpeg, .gif, .bmp, .tiff or .ico."
msgstr "" 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." msgid "You can %{linkStart}view the blob%{linkEnd} instead."
msgstr "" msgstr ""
......
...@@ -6,51 +6,54 @@ RSpec.describe Gitlab::ConfigChecker::ExternalDatabaseChecker do ...@@ -6,51 +6,54 @@ RSpec.describe Gitlab::ConfigChecker::ExternalDatabaseChecker do
describe '#check' do describe '#check' do
subject { described_class.check } 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 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 end
it { is_expected.to be_empty } it { is_expected.to be_empty }
end end
context 'database version is deprecated' do context 'when database does not meet minimum version and there is no upcoming deprecation' do
before do before do
allow(described_class).to receive(:db_version_deprecated?).and_return(true) allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(false)
end allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(false)
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 }
}
end end
it 'reports deprecated database notices' do it 'only returns notice about deprecated database version' do
is_expected.to contain_exactly(notice_deprecated_database) 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 end
end
describe '#db_version_deprecated' do context 'when database meets minimum version and there is an upcoming deprecation' do
subject { described_class.db_version_deprecated? }
context 'database version is not deprecated' do
before 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 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 end
context 'database version is deprecated' do context 'when database does not meet minimum version and there is an upcoming deprecation' do
before 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 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 end
end end
...@@ -90,28 +90,42 @@ RSpec.describe Gitlab::Database do ...@@ -90,28 +90,42 @@ RSpec.describe Gitlab::Database do
end end
describe '.postgresql_minimum_supported_version?' do describe '.postgresql_minimum_supported_version?' do
it 'returns false when using PostgreSQL 9.5' do it 'returns false when using PostgreSQL 10' do
allow(described_class).to receive(:version).and_return('9.5') allow(described_class).to receive(:version).and_return('10')
expect(described_class.postgresql_minimum_supported_version?).to eq(false) expect(described_class.postgresql_minimum_supported_version?).to eq(false)
end end
it 'returns false when using PostgreSQL 9.6' do it 'returns true when using PostgreSQL 11' do
allow(described_class).to receive(:version).and_return('9.6') 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 end
it 'returns false when using PostgreSQL 10' do it 'returns true when using PostgreSQL 12' do
allow(described_class).to receive(:version).and_return('10') 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
end
it 'returns true when using PostgreSQL 11 or newer' do describe '.postgresql_upcoming_deprecation?' do
allow(described_class).to receive(:version).and_return('11.0') 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
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