diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-24 12:09:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-24 12:09:32 +0300 |
commit | 4372b0ca297cb4659bfcf81d511b70004bf365af (patch) | |
tree | 54d45c5e1ee088fef1434eae19029dc83e6d6fe9 /db | |
parent | 0d312b8d370738d1dfa089b59ed21f40af1d4add (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20201117075742_change_webauthn_xid_length.rb | 18 | ||||
-rw-r--r-- | db/post_migrate/20201026185514_ensure_u2f_registrations_migrated.rb | 37 | ||||
-rw-r--r-- | db/schema_migrations/20201026185514 | 1 | ||||
-rw-r--r-- | db/schema_migrations/20201117075742 | 1 | ||||
-rw-r--r-- | db/structure.sql | 4 |
5 files changed, 59 insertions, 2 deletions
diff --git a/db/migrate/20201117075742_change_webauthn_xid_length.rb b/db/migrate/20201117075742_change_webauthn_xid_length.rb new file mode 100644 index 00000000000..2d836662e01 --- /dev/null +++ b/db/migrate/20201117075742_change_webauthn_xid_length.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class ChangeWebauthnXidLength < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_text_limit :webauthn_registrations, :credential_xid, 340, constraint_name: check_constraint_name(:webauthn_registrations, :credential_xid, 'max_length_v2') + remove_text_limit :webauthn_registrations, :credential_xid, constraint_name: check_constraint_name(:webauthn_registrations, :credential_xid, 'max_length') + end + + def down + # no-op: Danger of failling if there are records with length(credential_xid) > 255 + end +end diff --git a/db/post_migrate/20201026185514_ensure_u2f_registrations_migrated.rb b/db/post_migrate/20201026185514_ensure_u2f_registrations_migrated.rb new file mode 100644 index 00000000000..121b9fee623 --- /dev/null +++ b/db/post_migrate/20201026185514_ensure_u2f_registrations_migrated.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class EnsureU2fRegistrationsMigrated < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + BACKGROUND_MIGRATION_CLASS = 'MigrateU2fWebauthn' + BATCH_SIZE = 100 + DOWNTIME = false + + disable_ddl_transaction! + + class U2fRegistration < ActiveRecord::Base + include EachBatch + + self.table_name = 'u2f_registrations' + end + + def up + Gitlab::BackgroundMigration.steal(BACKGROUND_MIGRATION_CLASS) + + # Do a manual update in case we lost BG jobs. The expected record count should be 0 or very low. + U2fRegistration + .joins("LEFT JOIN webauthn_registrations ON webauthn_registrations.u2f_registration_id = u2f_registrations.id") + .where("webauthn_registrations.u2f_registration_id IS NULL") + .each_batch(of: BATCH_SIZE) do |batch, index| + batch.each do |record| + Gitlab::BackgroundMigration::MigrateU2fWebauthn.new.perform(record.id, record.id) + rescue => e + Gitlab::ErrorTracking.track_exception(e, u2f_registration_id: record.id) + end + end + end + + def down + # no-op (we can't "unsteal" migrations) + end +end diff --git a/db/schema_migrations/20201026185514 b/db/schema_migrations/20201026185514 new file mode 100644 index 00000000000..f6bdd06e501 --- /dev/null +++ b/db/schema_migrations/20201026185514 @@ -0,0 +1 @@ +a9ae0161c40b9c72371d6eb992bd0da8c3698e7784357faac0821e3f513e48d2
\ No newline at end of file diff --git a/db/schema_migrations/20201117075742 b/db/schema_migrations/20201117075742 new file mode 100644 index 00000000000..b3efeee7e0b --- /dev/null +++ b/db/schema_migrations/20201117075742 @@ -0,0 +1 @@ +a39bad8b213833c84370cf64188a3ce444fd8aeeff239c29f5f2f633d94ac6bb
\ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 97e669029b7..5cb98ddbd19 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -17571,8 +17571,8 @@ CREATE TABLE webauthn_registrations ( name text NOT NULL, public_key text NOT NULL, u2f_registration_id integer, - CONSTRAINT check_242f0cc65c CHECK ((char_length(credential_xid) <= 255)), - CONSTRAINT check_2f02e74321 CHECK ((char_length(name) <= 255)) + CONSTRAINT check_2f02e74321 CHECK ((char_length(name) <= 255)), + CONSTRAINT check_e54008d9ce CHECK ((char_length(credential_xid) <= 340)) ); CREATE SEQUENCE webauthn_registrations_id_seq |