Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c9aa9b5e
Commit
c9aa9b5e
authored
Jan 06, 2021
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adjust indexes on GitLab.com
Relates to
https://gitlab.com/gitlab-org/gitlab/-/issues/296760
parent
f31d1e81
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
0 deletions
+63
-0
changelogs/unreleased/ab-index-rename.yml
changelogs/unreleased/ab-index-rename.yml
+5
-0
db/migrate/20210106191305_rename_indexes_on_git_lab_com.rb
db/migrate/20210106191305_rename_indexes_on_git_lab_com.rb
+57
-0
db/schema_migrations/20210106191305
db/schema_migrations/20210106191305
+1
-0
No files found.
changelogs/unreleased/ab-index-rename.yml
0 → 100644
View file @
c9aa9b5e
---
title
:
Rename indexes to remove inconsistencies
merge_request
:
51011
author
:
type
:
other
db/migrate/20210106191305_rename_indexes_on_git_lab_com.rb
0 → 100644
View file @
c9aa9b5e
# frozen_string_literal: true
# This migration aligns an existing database schema with what we actually expect
# and fixes inconsistencies with index names and similar issues.
#
# This is intended for GitLab.com, but can be run on any instance.
class
RenameIndexesOnGitLabCom
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
rename_index_if_exists
:ldap_group_links
,
'ldap_groups_pkey'
,
'ldap_group_links_pkey'
# Removes unique constraint, add unique index instead
replace_unique_constraint_with_index
:emails
,
:email
,
'emails_email_key'
,
'index_emails_on_email'
replace_unique_constraint_with_index
:users
,
:confirmation_token
,
'users_confirmation_token_key'
,
'index_users_on_confirmation_token'
replace_unique_constraint_with_index
:users
,
:reset_password_token
,
'users_reset_password_token_key'
,
'index_users_on_reset_password_token'
replace_unique_constraint_with_index
:users
,
:email
,
'users_email_key'
,
'index_users_on_email'
upgrade_to_primary_key
(
:schema_migrations
,
:version
,
'schema_migrations_version_key'
,
'schema_migrations_pkey'
)
end
def
down
# no-op
end
private
def
replace_unique_constraint_with_index
(
table
,
columns
,
old_name
,
new_name
)
return
unless
index_exists_by_name?
(
table
,
old_name
)
add_concurrent_index
table
,
columns
,
unique:
true
,
name:
new_name
execute
"ALTER TABLE
#{
quote_table_name
(
table
)
}
DROP CONSTRAINT
#{
quote_table_name
(
old_name
)
}
"
end
def
rename_index_if_exists
(
table
,
old_name
,
new_name
)
return
unless
index_exists_by_name?
(
table
,
old_name
)
return
if
index_exists_by_name?
(
table
,
new_name
)
with_lock_retries
do
rename_index
table
,
old_name
,
new_name
end
end
def
upgrade_to_primary_key
(
table
,
column
,
old_name
,
new_name
)
return
unless
index_exists_by_name?
(
table
,
old_name
)
return
if
index_exists_by_name?
(
table
,
new_name
)
return
if
primary_key
(
table
)
execute
"ALTER TABLE
#{
quote_table_name
(
table
)
}
ADD CONSTRAINT
#{
new_name
}
PRIMARY KEY (
#{
column
}
)"
execute
"ALTER TABLE
#{
quote_table_name
(
table
)
}
DROP CONSTRAINT
#{
old_name
}
"
end
end
db/schema_migrations/20210106191305
0 → 100644
View file @
c9aa9b5e
938977d6379e484a53857304c339a024c32d8b71c2175574a72314e461d67e3b
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment