diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-20 03:10:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-20 03:10:55 +0300 |
commit | cf0dbcbf109a51edad3533b51f2bc76163e7305a (patch) | |
tree | 2f48a49c42fb4cef1eb6ca2f3c24ea2cc67ff14e /db | |
parent | 83d7a3922367d95a0875f9bdbdbf34a37f84e3fb (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20210106191305_rename_indexes_on_git_lab_com.rb | 57 | ||||
-rw-r--r-- | db/migrate/20210216193620_add_description_to_cluster_token.rb | 21 | ||||
-rw-r--r-- | db/schema_migrations/20210106191305 | 1 | ||||
-rw-r--r-- | db/schema_migrations/20210216193620 | 1 | ||||
-rw-r--r-- | db/structure.sql | 2 |
5 files changed, 82 insertions, 0 deletions
diff --git a/db/migrate/20210106191305_rename_indexes_on_git_lab_com.rb b/db/migrate/20210106191305_rename_indexes_on_git_lab_com.rb new file mode 100644 index 00000000000..5238192e1d1 --- /dev/null +++ b/db/migrate/20210106191305_rename_indexes_on_git_lab_com.rb @@ -0,0 +1,57 @@ +# 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 diff --git a/db/migrate/20210216193620_add_description_to_cluster_token.rb b/db/migrate/20210216193620_add_description_to_cluster_token.rb new file mode 100644 index 00000000000..67f7c6bd522 --- /dev/null +++ b/db/migrate/20210216193620_add_description_to_cluster_token.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class AddDescriptionToClusterToken < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + unless column_exists?(:cluster_agent_tokens, :description) + add_column :cluster_agent_tokens, :description, :text + end + + add_text_limit :cluster_agent_tokens, :description, 1024 + end + + def down + remove_column :cluster_agent_tokens, :description + end +end diff --git a/db/schema_migrations/20210106191305 b/db/schema_migrations/20210106191305 new file mode 100644 index 00000000000..5fd79e227e6 --- /dev/null +++ b/db/schema_migrations/20210106191305 @@ -0,0 +1 @@ +938977d6379e484a53857304c339a024c32d8b71c2175574a72314e461d67e3b
\ No newline at end of file diff --git a/db/schema_migrations/20210216193620 b/db/schema_migrations/20210216193620 new file mode 100644 index 00000000000..6c8e8d4c1c4 --- /dev/null +++ b/db/schema_migrations/20210216193620 @@ -0,0 +1 @@ +3587ba61d003385ea63ce900c1dd1c2bd1f2386abd921615b50421f1b798f553
\ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 3507cb74614..3611e0ae9cd 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -11026,6 +11026,8 @@ CREATE TABLE cluster_agent_tokens ( agent_id bigint NOT NULL, token_encrypted text NOT NULL, created_by_user_id bigint, + description text, + CONSTRAINT check_4e4ec5070a CHECK ((char_length(description) <= 1024)), CONSTRAINT check_c60daed227 CHECK ((char_length(token_encrypted) <= 255)) ); |