Explicitly model dependencies for database migrations

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

This is a follow-up to #333257 (comment 600319933).

In order to prevent migration failures from unsatisfied migration dependencies, we want to add explicit dependencies to database migrations.

Please see #333257 (comment 600319933) for background and an example for migration dependencies. Today, those are implicit and we rely on certain upgrade paths being followed.

The proposal here is: Add explicit dependencies to a database migration (optional - only if needed)

Example:

class SwapPartitionedWebHookLogs < ActiveRecord::Migration[6.0]
  include Gitlab::Database::PartitioningMigrationHelpers

  DOWNTIME = false

  dependent_on 20210326121537

  # may be multiple versions here: 
  dependent_on 1, 2, 3, 4

  def up
    replace_with_partitioned_table :web_hook_logs
  end

  def down
    rollback_replace_with_partitioned_table :web_hook_logs
  end
end

In order to enforce dependency checking, we can patch/extend the rake db:migrate task executing migrations. It would fail/abort the migration process if a dependency isn't met and error out with a helpful message.

cc @gitlab-org/database-team

Edited by 🤖 GitLab Bot 🤖