File: migration_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (34 lines) | stat: -rw-r--r-- 1,263 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Migrations Validation', feature_category: :database do
  using RSpec::Parameterized::TableSyntax

  # The range describes the timestamps that given migration helper can be used
  let(:all_migration_classes) do
    {
      2023_10_10_02_15_00.. => Gitlab::Database::Migration[2.2],
      2022_12_01_02_15_00..2023_11_01_02_15_00 => Gitlab::Database::Migration[2.1],
      2022_01_26_21_06_58..2023_01_11_12_45_12 => Gitlab::Database::Migration[2.0],
      2021_09_01_15_33_24..2022_04_25_12_06_03 => Gitlab::Database::Migration[1.0],
      2021_05_31_05_39_16..2021_09_01_15_33_24 => ActiveRecord::Migration[6.1],
      ..2021_05_31_05_39_16 => ActiveRecord::Migration[6.0]
    }
  end

  where(:migration) do
    Gitlab::Database.database_base_models.flat_map do |_, model|
      model.connection.migration_context.migrations
    end.uniq
  end

  with_them do
    let(:migration_instance) { migration.send(:migration) }
    let(:allowed_migration_classes) { all_migration_classes.select { |r, _| r.include?(migration.version) }.values }

    it 'uses one of the allowed migration classes' do
      expect(allowed_migration_classes).to include(be > migration_instance.class)
    end
  end
end