summaryrefslogtreecommitdiff
path: root/db/migrate/20220113125401_create_security_trainings.rb
blob: 6924c7bd18909b432a6dc455e07ea7975cac56a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# frozen_string_literal: true

class CreateSecurityTrainings < Gitlab::Database::Migration[1.0]
  enable_lock_retries!

  def change
    create_table :security_trainings do |t|
      t.references :project, null: false, foreign_key: { on_delete: :cascade }
      t.references :provider, null: false, foreign_key: { to_table: :security_training_providers, on_delete: :cascade }
      t.boolean :is_primary, default: false, null: false

      t.timestamps_with_timezone null: false

      # Guarantee that there will be only one primary per project
      t.index :project_id, name: 'index_security_trainings_on_unique_project_id', unique: true, where: 'is_primary IS TRUE'
    end
  end
end