Commit 7f45dd92 authored by Alexis Reigel's avatar Alexis Reigel

destroy all signatures and add with default value

To avoid having to implement legacy code handling for the obsolete
`verified_signature` attribute and to avoid any race conditions during
the zero-downtime-deployment we do the following:

1. Destroy all records
2. Migration: Use add_column_with_default to add the new attribute and
   update the verification_status values on records created between 1.
   and 2.
3. Deploy the new code
4. Post migration: Destroy all records

Like this we make sure that at no point there is a record with a `nil`
value for the new `verification_status` attribute.
parent ea4604e5
class AddVerificationStatusToGpgSignatures < ActiveRecord::Migration class AddVerificationStatusToGpgSignatures < ActiveRecord::Migration
DOWNTIME = false DOWNTIME = false
def change include Gitlab::Database::MigrationHelpers
add_column :gpg_signatures, :verification_status, :smallint disable_ddl_transaction!
class GpgSignature < ActiveRecord::Base
self.table_name = 'gpg_signatures'
include EachBatch
end
def up
# First we remove all signatures because we need to re-verify them all
# again anyway (because of the updated verification logic).
#
# This makes adding the column with default values faster
GpgSignature.each_batch do |relation|
relation.delete_all
end
add_column_with_default(:gpg_signatures, :verification_status, :smallint, default: 0)
end
def down
remove_column(:gpg_signatures, :verification_status)
end end
end end
...@@ -614,7 +614,7 @@ ActiveRecord::Schema.define(version: 20170830125940) do ...@@ -614,7 +614,7 @@ ActiveRecord::Schema.define(version: 20170830125940) do
t.binary "gpg_key_primary_keyid" t.binary "gpg_key_primary_keyid"
t.text "gpg_key_user_name" t.text "gpg_key_user_name"
t.text "gpg_key_user_email" t.text "gpg_key_user_email"
t.integer "verification_status", limit: 2 t.integer "verification_status", limit: 2, default: 0, null: false
end end
add_index "gpg_signatures", ["commit_sha"], name: "index_gpg_signatures_on_commit_sha", unique: true, using: :btree add_index "gpg_signatures", ["commit_sha"], name: "index_gpg_signatures_on_commit_sha", unique: true, using: :btree
......
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