Commit 07f86bf6 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'add-pages-onboarding-metadatum' into 'master'

Add onboarding_complete column to pages_metadata

See merge request gitlab-org/gitlab!73551
parents d2b2e94e 5e36289c
...@@ -1946,6 +1946,10 @@ class Project < ApplicationRecord ...@@ -1946,6 +1946,10 @@ class Project < ApplicationRecord
Gitlab.config.pages.enabled Gitlab.config.pages.enabled
end end
def pages_show_onboarding?
!(pages_metadatum&.onboarding_complete || pages_metadatum&.deployed)
end
def remove_private_deploy_keys def remove_private_deploy_keys
exclude_keys_linked_to_other_projects = <<-SQL exclude_keys_linked_to_other_projects = <<-SQL
NOT EXISTS ( NOT EXISTS (
...@@ -1961,6 +1965,10 @@ class Project < ApplicationRecord ...@@ -1961,6 +1965,10 @@ class Project < ApplicationRecord
.delete_all .delete_all
end end
def mark_pages_onboarding_complete
ensure_pages_metadatum.update!(onboarding_complete: true)
end
def mark_pages_as_deployed def mark_pages_as_deployed
ensure_pages_metadatum.update!(deployed: true) ensure_pages_metadatum.update!(deployed: true)
end end
......
# frozen_string_literal: true
class AddPagesOnboardingState < Gitlab::Database::Migration[1.0]
def up
add_column :project_pages_metadata, :onboarding_complete, :boolean, default: false, null: false
end
def down
remove_column :project_pages_metadata, :onboarding_complete
end
end
# frozen_string_literal: true
class UpdatePagesOnboardingState < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
BATCH_SIZE = 75
def up
define_batchable_model(
:project_pages_metadata
).where(
deployed: true
).each_batch(
of: BATCH_SIZE,
column: :project_id
) do |batch|
batch.update_all(onboarding_complete: true)
end
end
def down
define_batchable_model(
:project_pages_metadata
).where(
onboarding_complete: true
).each_batch(
of: BATCH_SIZE,
column: :project_id
) do |batch|
batch.update_all(onboarding_complete: false)
end
end
end
d9a9d143ff553cbad5eb32a908370133549850f10b27b30eb6a1bde686054c45
\ No newline at end of file
94dbae9bbfb2da49a0d20b674e15f457c613c8ba0612603dd8fe9ac5699160d1
\ No newline at end of file
...@@ -19304,7 +19304,8 @@ ALTER SEQUENCE project_mirror_data_id_seq OWNED BY project_mirror_data.id; ...@@ -19304,7 +19304,8 @@ ALTER SEQUENCE project_mirror_data_id_seq OWNED BY project_mirror_data.id;
CREATE TABLE project_pages_metadata ( CREATE TABLE project_pages_metadata (
project_id bigint NOT NULL, project_id bigint NOT NULL,
deployed boolean DEFAULT false NOT NULL, deployed boolean DEFAULT false NOT NULL,
pages_deployment_id bigint pages_deployment_id bigint,
onboarding_complete boolean DEFAULT false NOT NULL
); );
CREATE TABLE project_repositories ( CREATE TABLE project_repositories (
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe UpdatePagesOnboardingState do
let(:migration) { described_class.new }
let!(:namespaces) { table(:namespaces) }
let!(:projects) { table(:projects) }
let!(:project_pages_metadata) { table(:project_pages_metadata) }
let!(:namespace1) { namespaces.create!(name: 'foo', path: 'foo') }
let!(:namespace2) { namespaces.create!(name: 'bar', path: 'bar') }
let!(:project1) { projects.create!(namespace_id: namespace1.id) }
let!(:project2) { projects.create!(namespace_id: namespace2.id) }
let!(:pages_metadata1) do
project_pages_metadata.create!(
project_id: project1.id,
deployed: true,
onboarding_complete: false
)
end
let!(:pages_metadata2) do
project_pages_metadata.create!(
project_id: project2.id,
deployed: false,
onboarding_complete: false
)
end
describe '#up' do
before do
migration.up
end
it 'sets the onboarding_complete attribute to the value of deployed' do
expect(pages_metadata1.reload.onboarding_complete).to eq(true)
expect(pages_metadata2.reload.onboarding_complete).to eq(false)
end
end
describe '#down' do
before do
migration.up
migration.down
end
it 'sets all onboarding_complete attributes to false' do
expect(pages_metadata1.reload.onboarding_complete).to eq(false)
expect(pages_metadata2.reload.onboarding_complete).to eq(false)
end
end
end
...@@ -2293,6 +2293,44 @@ RSpec.describe Project, factory_default: :keep do ...@@ -2293,6 +2293,44 @@ RSpec.describe Project, factory_default: :keep do
end end
end end
describe '#pages_show_onboarding?' do
let(:project) { create(:project) }
subject { project.pages_show_onboarding? }
context "if there is no metadata" do
it { is_expected.to be_truthy }
end
context 'if onboarding is complete' do
before do
project.pages_metadatum.update_column(:onboarding_complete, true)
end
it { is_expected.to be_falsey }
end
context 'if there is metadata, but onboarding is not complete' do
before do
project.pages_metadatum.update_column(:onboarding_complete, false)
end
it { is_expected.to be_truthy }
end
# During migration, the onboarding_complete property can still be false,
# but will be updated later. To account for that case, pages_show_onboarding?
# should return false if `deployed` is true.
context "will return false if pages is deployed even if onboarding_complete is false" do
before do
project.pages_metadatum.update_column(:onboarding_complete, false)
project.pages_metadatum.update_column(:deployed, true)
end
it { is_expected.to be_falsey }
end
end
describe '#pages_deployed?' do describe '#pages_deployed?' do
let(:project) { create(:project) } let(:project) { create(:project) }
...@@ -6626,6 +6664,25 @@ RSpec.describe Project, factory_default: :keep do ...@@ -6626,6 +6664,25 @@ RSpec.describe Project, factory_default: :keep do
end end
end end
describe '#mark_pages_onboarding_complete' do
let(:project) { create(:project) }
it "creates new record and sets onboarding_complete to true if none exists yet" do
project.mark_pages_onboarding_complete
expect(project.pages_metadatum.reload.onboarding_complete).to eq(true)
end
it "overrides an existing setting" do
pages_metadatum = project.pages_metadatum
pages_metadatum.update!(onboarding_complete: false)
expect do
project.mark_pages_onboarding_complete
end.to change { pages_metadatum.reload.onboarding_complete }.from(false).to(true)
end
end
describe '#mark_pages_as_deployed' do describe '#mark_pages_as_deployed' do
let(:project) { create(:project) } let(:project) { create(:project) }
......
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