diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-28 18:08:35 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-28 18:08:35 +0000 |
commit | 6315ed9630fb1c6ade3114beb762cd1568d79219 (patch) | |
tree | 2a5d31936d09c14420c8f4c8bd752e268f0eb19f /lib/gitlab/database | |
parent | fedf978f9aa1909ed7bb3fad767ad120a1c6bd7b (diff) | |
download | gitlab-ce-6315ed9630fb1c6ade3114beb762cd1568d79219.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/database')
-rw-r--r-- | lib/gitlab/database/migration_helpers.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index 5077143e15e..b53e01e6ff2 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -1119,6 +1119,20 @@ into similar problems in the future (e.g. when new tables are created). SQL end + # Note this should only be used with very small tables + def backfill_iids(table) + sql = <<-END + UPDATE #{table} + SET iid = #{table}_with_calculated_iid.iid_num + FROM ( + SELECT id, ROW_NUMBER() OVER (PARTITION BY project_id ORDER BY id ASC) AS iid_num FROM #{table} + ) AS #{table}_with_calculated_iid + WHERE #{table}.id = #{table}_with_calculated_iid.id + END + + execute(sql) + end + private def tables_match?(target_table, foreign_key_table) |