Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20221114142602_drop_experiment_subjects_table.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f7c10192afb92211e567fa51017d1d1ad8027fc8 (plain)
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
# frozen_string_literal: true

class DropExperimentSubjectsTable < Gitlab::Database::Migration[2.0]
  def up
    drop_table :experiment_subjects, if_exists: true
  end

  def down
    unless table_exists?(:experiment_subjects)
      create_table :experiment_subjects do |t|
        t.bigint :experiment_id, null: false
        t.bigint :user_id
        t.bigint :project_id
        t.integer :variant, limit: 2, null: false, default: 0
        t.timestamps_with_timezone null: false
        t.datetime_with_timezone :converted_at
        t.jsonb :context, null: false, default: {}
        t.bigint :namespace_id

        t.index :experiment_id
        t.index :namespace_id
        t.index :project_id
        t.index :user_id
      end
    end

    # Require exactly one of user_id, group_id, or project_id to be NOT NULL
    execute <<-SQL
      ALTER TABLE experiment_subjects ADD CONSTRAINT check_f6411bc4b5 CHECK (num_nonnulls(user_id, namespace_id, project_id) = 1);
    SQL
  end
end