diff options
Diffstat (limited to 'db')
3 files changed, 47 insertions, 6 deletions
diff --git a/db/post_migrate/20210809123658_orphaned_invite_tokens_cleanup.rb b/db/post_migrate/20210809123658_orphaned_invite_tokens_cleanup.rb index f774db73eaa..ddbafaf32a9 100644 --- a/db/post_migrate/20210809123658_orphaned_invite_tokens_cleanup.rb +++ b/db/post_migrate/20210809123658_orphaned_invite_tokens_cleanup.rb @@ -6,15 +6,12 @@ class OrphanedInviteTokensCleanup < ActiveRecord::Migration[6.1] disable_ddl_transaction! TMP_INDEX_NAME = 'tmp_idx_orphaned_invite_tokens' - QUERY_CONDITION = "invite_token IS NOT NULL and invite_accepted_at IS NOT NULL and invite_accepted_at < created_at" def up - membership = define_batchable_model('members') + add_concurrent_index('members', :id, where: query_condition, name: TMP_INDEX_NAME) - add_concurrent_index('members', :id, where: QUERY_CONDITION, name: TMP_INDEX_NAME) - - membership.where(QUERY_CONDITION).pluck(:id).each_slice(10) do |group| - membership.where(id: group).where(QUERY_CONDITION).update_all(invite_token: nil) + membership.where(query_condition).pluck(:id).each_slice(10) do |group| + membership.where(id: group).where(query_condition).update_all(invite_token: nil) end remove_concurrent_index_by_name('members', TMP_INDEX_NAME) @@ -25,4 +22,30 @@ class OrphanedInviteTokensCleanup < ActiveRecord::Migration[6.1] # This migration is irreversible end + + private + + def membership + @membership ||= define_batchable_model('members') + end + + # We need to ensure we're comparing timestamp with time zones across + # the board since that is an immutable comparison. Some database + # schemas have a mix of timestamp without time zones and and timestamp + # with time zones: https://gitlab.com/groups/gitlab-org/-/epics/2473 + def query_condition + "invite_token IS NOT NULL and invite_accepted_at IS NOT NULL and #{timestamptz("invite_accepted_at")} < #{timestamptz("created_at")}" + end + + def timestamptz(name) + if column_type(name) == "timestamp without time zone" + "TIMEZONE('UTC', #{name})" + else + name + end + end + + def column_type(name) + membership.columns_hash[name].sql_type + end end diff --git a/db/post_migrate/20210819183128_reset_severity_levels_to_new_default.rb b/db/post_migrate/20210819183128_reset_severity_levels_to_new_default.rb new file mode 100644 index 00000000000..cdfd92ac0d7 --- /dev/null +++ b/db/post_migrate/20210819183128_reset_severity_levels_to_new_default.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class ResetSeverityLevelsToNewDefault < ActiveRecord::Migration[6.1] + ALL_SEVERITY_LEVELS = 6 # ::Enums::Vulnerability::SEVERITY_LEVELS.count + + def up + execute(<<~SQL.squish) + UPDATE approval_project_rules + SET severity_levels = '{unknown, high, critical}' + WHERE array_length(severity_levels, 1) = #{ALL_SEVERITY_LEVELS}; + SQL + end + + def down + # no-op + end +end diff --git a/db/schema_migrations/20210819183128 b/db/schema_migrations/20210819183128 new file mode 100644 index 00000000000..84b8b3780e3 --- /dev/null +++ b/db/schema_migrations/20210819183128 @@ -0,0 +1 @@ +d57791945f0d21da90a5b1d75db9add6c7e916ad3c13df2522c7d71d572baa47
\ No newline at end of file |