From d1d05ae4f34aab350db86e03859c97e90f515520 Mon Sep 17 00:00:00 2001 From: Vladimir Shushlin Date: Thu, 6 Jun 2019 19:14:09 +0000 Subject: Add certificate valid time to pages domain table Save certificate validity time for pages domains on save Fill validity time for existing pages domains in background migration --- ...4071727_add_ssl_valid_period_to_pages_domain.rb | 16 ++++++++++ ...ill_valid_time_for_pages_domain_certificates.rb | 34 ++++++++++++++++++++++ db/schema.rb | 2 ++ 3 files changed, 52 insertions(+) create mode 100644 db/migrate/20190524071727_add_ssl_valid_period_to_pages_domain.rb create mode 100644 db/post_migrate/20190524073827_schedule_fill_valid_time_for_pages_domain_certificates.rb (limited to 'db') diff --git a/db/migrate/20190524071727_add_ssl_valid_period_to_pages_domain.rb b/db/migrate/20190524071727_add_ssl_valid_period_to_pages_domain.rb new file mode 100644 index 00000000000..18544dcb6d3 --- /dev/null +++ b/db/migrate/20190524071727_add_ssl_valid_period_to_pages_domain.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddSslValidPeriodToPagesDomain < ActiveRecord::Migration[5.1] + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + def change + add_column :pages_domains, :certificate_valid_not_before, :datetime_with_timezone + add_column :pages_domains, :certificate_valid_not_after, :datetime_with_timezone + end +end diff --git a/db/post_migrate/20190524073827_schedule_fill_valid_time_for_pages_domain_certificates.rb b/db/post_migrate/20190524073827_schedule_fill_valid_time_for_pages_domain_certificates.rb new file mode 100644 index 00000000000..1d8510e4514 --- /dev/null +++ b/db/post_migrate/20190524073827_schedule_fill_valid_time_for_pages_domain_certificates.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class ScheduleFillValidTimeForPagesDomainCertificates < ActiveRecord::Migration[5.1] + include Gitlab::Database::MigrationHelpers + + MIGRATION = 'FillValidTimeForPagesDomainCertificate' + BATCH_SIZE = 500 + BATCH_TIME = 5.minutes + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + disable_ddl_transaction! + + class PagesDomain < ActiveRecord::Base + include ::EachBatch + + self.table_name = 'pages_domains' + end + + def up + queue_background_migration_jobs_by_range_at_intervals( + PagesDomain.where.not(certificate: [nil, '']), + MIGRATION, + BATCH_TIME, + batch_size: BATCH_SIZE) + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 59e9429b819..7de5b0352f0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1597,6 +1597,8 @@ ActiveRecord::Schema.define(version: 20190530154715) do t.datetime_with_timezone "enabled_until" t.datetime_with_timezone "remove_at" t.boolean "auto_ssl_enabled", default: false, null: false + t.datetime_with_timezone "certificate_valid_not_before" + t.datetime_with_timezone "certificate_valid_not_after" t.index ["domain"], name: "index_pages_domains_on_domain", unique: true, using: :btree t.index ["project_id", "enabled_until"], name: "index_pages_domains_on_project_id_and_enabled_until", using: :btree t.index ["project_id"], name: "index_pages_domains_on_project_id", using: :btree -- cgit v1.2.3