Commit 7ad73258 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'ali/add-type-to-pages-domains' into 'master'

Update PagesDomains data model for serverless domains

See merge request gitlab-org/gitlab!23943
parents 581d89bc 4818b04b
......@@ -6,7 +6,8 @@ class PagesDomain < ApplicationRecord
SSL_RENEWAL_THRESHOLD = 30.days.freeze
enum certificate_source: { user_provided: 0, gitlab_provided: 1 }, _prefix: :certificate
enum domain_type: { instance: 0, group: 1, project: 2 }, _prefix: :domain_type
enum scope: { instance: 0, group: 1, project: 2 }, _prefix: :scope
enum usage: { pages: 0, serverless: 1 }, _prefix: :usage
belongs_to :project
has_many :acme_orders, class_name: "PagesDomainAcmeOrder"
......@@ -26,8 +27,9 @@ class PagesDomain < ApplicationRecord
validate :validate_intermediates, if: ->(domain) { domain.certificate.present? && domain.certificate_changed? }
default_value_for(:auto_ssl_enabled, allow_nil: false) { ::Gitlab::LetsEncrypt.enabled? }
default_value_for :domain_type, allow_nil: false, value: :project
default_value_for :scope, allow_nil: false, value: :project
default_value_for :wildcard, allow_nil: false, value: false
default_value_for :usage, allow_nil: false, value: :pages
attr_encrypted :key,
mode: :per_attribute_iv_and_salt,
......@@ -220,7 +222,7 @@ class PagesDomain < ApplicationRecord
# rubocop: disable CodeReuse/ServiceClass
def update_daemon
return if domain_type_instance?
return if usage_serverless?
::Projects::UpdatePagesConfigurationService.new(project).execute
end
......
---
title: Update PagesDomains data model for serverless domains
merge_request: 23943
author:
type: changed
# frozen_string_literal: true
class AddUsageToPagesDomains < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
PAGES_USAGE = 0
disable_ddl_transaction!
def up
add_column_with_default :pages_domains, :usage, :integer, limit: 2, default: PAGES_USAGE, allow_null: false # rubocop:disable Migration/AddColumnWithDefault
end
def down
remove_column :pages_domains, :usage
end
end
# frozen_string_literal: true
class UpdateIndexesOfPagesDomainsAddUsageDomainWildcardRemoveDomain < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :pages_domains, :usage
add_concurrent_index :pages_domains, [:domain, :wildcard], unique: true
remove_concurrent_index :pages_domains, :domain
end
def down
remove_concurrent_index :pages_domains, :usage
remove_concurrent_index :pages_domains, [:domain, :wildcard]
add_concurrent_index :pages_domains, :domain, unique: true
end
end
# frozen_string_literal: true
class RenamePagesDomainsDomainTypeToScope < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
rename_column_concurrently :pages_domains, :domain_type, :scope
end
def down
undo_rename_column_concurrently :pages_domains, :domain_type, :scope
end
end
# frozen_string_literal: true
class CleanupRenamePagesDomainsDomainTypeToScope < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
cleanup_concurrent_column_rename :pages_domains, :domain_type, :scope
end
def down
undo_cleanup_concurrent_column_rename :pages_domains, :domain_type, :scope
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_01_27_090233) do
ActiveRecord::Schema.define(version: 2020_01_29_035708) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
......@@ -3018,13 +3018,15 @@ ActiveRecord::Schema.define(version: 2020_01_27_090233) do
t.datetime_with_timezone "certificate_valid_not_after"
t.integer "certificate_source", limit: 2, default: 0, null: false
t.boolean "wildcard", default: false, null: false
t.integer "domain_type", limit: 2, default: 2, null: false
t.integer "usage", limit: 2, default: 0, null: false
t.integer "scope", limit: 2, default: 2, null: false
t.index ["certificate_source", "certificate_valid_not_after"], name: "index_pages_domains_need_auto_ssl_renewal", where: "(auto_ssl_enabled = true)"
t.index ["domain"], name: "index_pages_domains_on_domain", unique: true
t.index ["domain_type"], name: "index_pages_domains_on_domain_type"
t.index ["domain", "wildcard"], name: "index_pages_domains_on_domain_and_wildcard", unique: true
t.index ["project_id", "enabled_until"], name: "index_pages_domains_on_project_id_and_enabled_until"
t.index ["project_id"], name: "index_pages_domains_on_project_id"
t.index ["remove_at"], name: "index_pages_domains_on_remove_at"
t.index ["scope"], name: "index_pages_domains_on_scope"
t.index ["usage"], name: "index_pages_domains_on_usage"
t.index ["verified_at", "enabled_until"], name: "index_pages_domains_on_verified_at_and_enabled_until"
t.index ["verified_at"], name: "index_pages_domains_on_verified_at"
t.index ["wildcard"], name: "index_pages_domains_on_wildcard"
......
......@@ -377,7 +377,8 @@ x6zG6WoibsbsJMj70nwseUnPTBQNDP+j61RJjC/r
trait :instance_serverless do
wildcard { true }
domain_type { :instance }
scope { :instance }
usage { :serverless }
end
end
end
......@@ -180,8 +180,12 @@ describe PagesDomain do
expect(subject.wildcard).to eq(false)
end
it 'defaults domain_type to project' do
expect(subject.domain_type).to eq('project')
it 'defaults scope to project' do
expect(subject.scope).to eq('project')
end
it 'defaults usage to pages' do
expect(subject.usage).to eq('pages')
end
end
......@@ -315,11 +319,11 @@ describe PagesDomain do
end
describe '#update_daemon' do
context 'when domain_type is instance' do
it 'does nothing' do
context 'when usage is serverless' do
it 'does not call the UpdatePagesConfigurationService' do
expect(Projects::UpdatePagesConfigurationService).not_to receive(:new)
create(:pages_domain, domain_type: :instance)
create(:pages_domain, usage: :serverless)
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