Commit c7e4cc68 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'limit-db-deprecation-notice-window' into 'master'

Limit database deprecation notice window

Closes #227292

See merge request gitlab-org/gitlab!37009
parents e7683932 72820bbd
---
title: Limit database deprecation notice window
merge_request: 37009
author:
type: changed
......@@ -23,7 +23,7 @@ module Gitlab
}
end
if Gitlab::Database.postgresql_upcoming_deprecation?
if Gitlab::Database.postgresql_upcoming_deprecation? && Gitlab::Database.within_deprecation_notice_window?
upcoming_deprecation = Gitlab::Database::UPCOMING_POSTGRES_VERSION_DETAILS
notices <<
......
......@@ -13,11 +13,15 @@ module Gitlab
# so administrators can prepare to upgrade
UPCOMING_POSTGRES_VERSION_DETAILS = {
gl_version: '13.6.0',
gl_version_date: 'November 2020',
gl_version_date: 'November 22, 2020',
pg_version_minimum: 12,
url: 'https://gitlab.com/groups/gitlab-org/-/epics/2374'
}.freeze
# Specifies the maximum number of days in advance to display a notice
# regarding an upcoming PostgreSQL version deprecation.
DEPRECATION_WINDOW_DAYS = 90
# https://www.postgresql.org/docs/9.2/static/datatype-numeric.html
MAX_INT_VALUE = 2147483647
......@@ -119,6 +123,18 @@ module Gitlab
version.to_f < UPCOMING_POSTGRES_VERSION_DETAILS[:pg_version_minimum]
end
def self.days_until_deprecation
(
Date.parse(UPCOMING_POSTGRES_VERSION_DETAILS[:gl_version_date]) -
Date.today
).to_i
end
private_class_method :days_until_deprecation
def self.within_deprecation_notice_window?
days_until_deprecation <= DEPRECATION_WINDOW_DAYS
end
def self.check_postgres_version_and_print_warning
return if Gitlab::Database.postgresql_minimum_supported_version?
return if Gitlab::Runtime.rails_runner?
......
......@@ -36,18 +36,37 @@ RSpec.describe Gitlab::ConfigChecker::ExternalDatabaseChecker do
allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(true)
end
context 'inside the deprecation notice window' do
before do
allow(Gitlab::Database).to receive(:within_deprecation_notice_window?).and_return(true)
end
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 'outside the deprecation notice window' do
before do
allow(Gitlab::Database).to receive(:within_deprecation_notice_window?).and_return(false)
end
it { is_expected.to be_empty }
end
end
context 'when database does not meet minimum version and there is an upcoming deprecation' do
before do
allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(false)
allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(true)
end
context 'inside the deprecation notice window' do
before do
allow(Gitlab::Database).to receive(:within_deprecation_notice_window?).and_return(true)
end
it 'returns notice about deprecated database version and an upcoming deprecation' do
is_expected.to include(
a_hash_including(message: include(deprecation_warning)),
......@@ -55,5 +74,17 @@ RSpec.describe Gitlab::ConfigChecker::ExternalDatabaseChecker do
)
end
end
context 'outside the deprecation notice window' do
before do
allow(Gitlab::Database).to receive(:within_deprecation_notice_window?).and_return(false)
end
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
end
end
......@@ -129,6 +129,26 @@ RSpec.describe Gitlab::Database do
end
end
describe '.within_deprecation_notice_window?' do
using RSpec::Parameterized::TableSyntax
where(:case_name, :days, :result) do
'outside window' | Gitlab::Database::DEPRECATION_WINDOW_DAYS + 1 | false
'equal to window' | Gitlab::Database::DEPRECATION_WINDOW_DAYS | true
'within window' | Gitlab::Database::DEPRECATION_WINDOW_DAYS - 1 | true
end
with_them do
it "returns #{params[:result]} when #{params[:case_name]}" do
allow(Date)
.to receive(:today)
.and_return Date.parse(Gitlab::Database::UPCOMING_POSTGRES_VERSION_DETAILS[:gl_version_date]) - days
expect(described_class.within_deprecation_notice_window?).to eq(result)
end
end
end
describe '.check_postgres_version_and_print_warning' do
subject { described_class.check_postgres_version_and_print_warning }
......
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