Commit 35cfaf5e authored by Michał Zając's avatar Michał Zając Committed by Dallas Reedy
parent 2c913614
......@@ -6,14 +6,13 @@ class CreateExperimentSubjects < ActiveRecord::Migration[6.0]
def up
create_table :experiment_subjects do |t|
t.references :experiment, index: true, foreign_key: { on_delete: :cascade }, null: false
t.bigint :user_id, index: true
t.bigint :group_id, index: true
t.bigint :project_id, index: true
t.integer :variant, limit: 2, null: false, default: 0
t.timestamps_with_timezone null: false
end
add_reference :experiment_subjects, :user, index: true, foreign_key: { on_delete: :cascade }
add_reference :experiment_subjects, :group, index: true, foreign_key: { to_table: :namespaces, on_delete: :cascade }
add_reference :experiment_subjects, :project, index: true, foreign_key: { on_delete: :cascade }
# Require at least one of user_id, group_id, or project_id to be NOT NULL
execute <<-SQL
ALTER TABLE experiment_subjects ADD CONSTRAINT chk_at_least_one_subject CHECK (NOT ROW(user_id, group_id, project_id) IS NULL);
......
# frozen_string_literal: true
class AddForeignKeyToExperimentSubjectsOnUser < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
DOWNTIME = false
def up
add_concurrent_foreign_key :experiment_subjects, :users, column: :user_id, on_delete: :cascade
end
def down
with_lock_retries do
remove_foreign_key :experiment_subjects, column: :user_id
end
end
end
# frozen_string_literal: true
class AddForeignKeyToExperimentSubjectsOnGroup < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
DOWNTIME = false
def up
add_concurrent_foreign_key :experiment_subjects, :namespaces, column: :group_id, on_delete: :cascade
end
def down
with_lock_retries do
remove_foreign_key :experiment_subjects, column: :group_id
end
end
end
# frozen_string_literal: true
class AddForeignKeyToExperimentSubjectsOnProject < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
DOWNTIME = false
def up
add_concurrent_foreign_key :experiment_subjects, :projects, column: :project_id, on_delete: :cascade
end
def down
with_lock_retries do
remove_foreign_key :experiment_subjects, column: :project_id
end
end
end
4340d0f6d3b660b336fdc3166a4960865c79e90f505b1173bab4e0d11c1199b3
\ No newline at end of file
8180908c5e577757b3f518d312cbf0ba77c65b39fa55dde487036541f49114a1
\ No newline at end of file
c228aa5c16e63af7520dd1bd90cefb1f74ec2371af3b0e839938d8c628f70e8a
\ No newline at end of file
......@@ -12141,12 +12141,12 @@ ALTER SEQUENCE evidences_id_seq OWNED BY evidences.id;
CREATE TABLE experiment_subjects (
id bigint NOT NULL,
experiment_id bigint NOT NULL,
variant smallint DEFAULT 0 NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
user_id bigint,
group_id bigint,
project_id bigint,
variant smallint DEFAULT 0 NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
CONSTRAINT chk_at_least_one_subject CHECK ((NOT (ROW(user_id, group_id, project_id) IS NULL)))
);
......@@ -23396,6 +23396,9 @@ ALTER TABLE ONLY packages_package_files
ALTER TABLE ONLY ci_builds
ADD CONSTRAINT fk_87f4cefcda FOREIGN KEY (upstream_pipeline_id) REFERENCES ci_pipelines(id) ON DELETE CASCADE;
ALTER TABLE ONLY experiment_subjects
ADD CONSTRAINT fk_88489af1b1 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY vulnerabilities
ADD CONSTRAINT fk_88b4d546ef FOREIGN KEY (start_date_sourcing_milestone_id) REFERENCES milestones(id) ON DELETE SET NULL;
......@@ -23582,6 +23585,9 @@ ALTER TABLE ONLY issues
ALTER TABLE ONLY issue_links
ADD CONSTRAINT fk_c900194ff2 FOREIGN KEY (source_id) REFERENCES issues(id) ON DELETE CASCADE;
ALTER TABLE ONLY experiment_subjects
ADD CONSTRAINT fk_ccc28f8ceb FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY todos
ADD CONSTRAINT fk_ccf0373936 FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE;
......@@ -23642,6 +23648,9 @@ ALTER TABLE ONLY analytics_devops_adoption_segment_selections
ALTER TABLE ONLY issues
ADD CONSTRAINT fk_df75a7c8b8 FOREIGN KEY (promoted_to_epic_id) REFERENCES epics(id) ON DELETE SET NULL;
ALTER TABLE ONLY experiment_subjects
ADD CONSTRAINT fk_dfc3e211d4 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_resources
ADD CONSTRAINT fk_e169a8e3d5 FOREIGN KEY (build_id) REFERENCES ci_builds(id) ON DELETE SET NULL;
......@@ -24488,9 +24497,6 @@ ALTER TABLE ONLY ci_runner_namespaces
ALTER TABLE ONLY software_license_policies
ADD CONSTRAINT fk_rails_87b2247ce5 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY experiment_subjects
ADD CONSTRAINT fk_rails_88489af1b1 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY protected_environment_deploy_access_levels
ADD CONSTRAINT fk_rails_898a13b650 FOREIGN KEY (protected_environment_id) REFERENCES protected_environments(id) ON DELETE CASCADE;
......@@ -24863,9 +24869,6 @@ ALTER TABLE ONLY operations_strategies_user_lists
ALTER TABLE ONLY issue_tracker_data
ADD CONSTRAINT fk_rails_ccc0840427 FOREIGN KEY (service_id) REFERENCES services(id) ON DELETE CASCADE;
ALTER TABLE ONLY experiment_subjects
ADD CONSTRAINT fk_rails_ccc28f8ceb FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY resource_milestone_events
ADD CONSTRAINT fk_rails_cedf8cce4d FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL;
......@@ -24932,9 +24935,6 @@ ALTER TABLE ONLY vulnerability_feedback
ALTER TABLE ONLY analytics_cycle_analytics_group_stages
ADD CONSTRAINT fk_rails_dfb37c880d FOREIGN KEY (end_event_label_id) REFERENCES labels(id) ON DELETE CASCADE;
ALTER TABLE ONLY experiment_subjects
ADD CONSTRAINT fk_rails_dfc3e211d4 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY label_priorities
ADD CONSTRAINT fk_rails_e161058b0f FOREIGN KEY (label_id) REFERENCES labels(id) ON DELETE CASCADE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment