From 09237b02b51ab32cb23cde2b7eb66e47d4ef4702 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 1 Nov 2021 00:09:31 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master --- config/initializers/0_postgresql_types.rb | 17 +++++++++++++++++ doc/development/adding_database_indexes.md | 13 +++++++++++++ .../project/settings/project_access_tokens.md | 4 +++- spec/initializers/0_postgresql_types_spec.rb | 16 ++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 config/initializers/0_postgresql_types.rb create mode 100644 spec/initializers/0_postgresql_types_spec.rb diff --git a/config/initializers/0_postgresql_types.rb b/config/initializers/0_postgresql_types.rb new file mode 100644 index 00000000000..79e7510ee55 --- /dev/null +++ b/config/initializers/0_postgresql_types.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +# As discussed in https://github.com/rails/rails/issues/40687, this +# patch registers a few types to silence warnings when Rails comes +# across some PostgreSQL types it does not recognize. +module PostgreSQLAdapterCustomTypes + def initialize_type_map(m = type_map) # rubocop:disable Naming/MethodParameterName + m.register_type('xid', ActiveRecord::Type::Integer.new(limit: 8)) + m.register_type('pg_node_tree', ActiveRecord::Type::String.new) + m.register_type('_aclitem', ActiveRecord::Type::String.new) + m.register_type('pg_lsn', ActiveRecord::Type::String.new) + + super + end +end + +ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(PostgreSQLAdapterCustomTypes) diff --git a/doc/development/adding_database_indexes.md b/doc/development/adding_database_indexes.md index 9ca08ab1dc2..571d2f353d4 100644 --- a/doc/development/adding_database_indexes.md +++ b/doc/development/adding_database_indexes.md @@ -312,3 +312,16 @@ def down remove_concurrent_index_by_name :ci_builds, INDEX_NAME end ``` + +## Test database index changes locally + +You must test the database index changes locally before creating a merge request. + +### Verify indexes created asynchronously + +Use the asynchronous index helpers on your local environment to test changes for creating an index: + +1. Enable the feature flags by running `Feature.enable(:database_async_index_creation)` and `Feature.enable(:database_reindexing)` in the Rails console. +1. Run `bundle exec rails db:migrate` so that it creates an entry in the `postgres_async_indexes` table. +1. Run `bundle exec rails gitlab:db:reindex` so that the index is created asynchronously. +1. To verify the index, open the PostgreSQL console using the [GDK](https://gitlab.com/gitlab-org/gitlab-development-kit/-/blob/main/doc/howto/postgresql.md) command `gdk psql` and run the command `\d ` to check that your newly created index exists. diff --git a/doc/user/project/settings/project_access_tokens.md b/doc/user/project/settings/project_access_tokens.md index cae9276eafd..6ecee215d79 100644 --- a/doc/user/project/settings/project_access_tokens.md +++ b/doc/user/project/settings/project_access_tokens.md @@ -58,7 +58,9 @@ For the bot: - The name is set to the name of the token. - The username is set to `project_{project_id}_bot` for the first access token, such as `project_123_bot`. -- The username is set to `project_{project_id}_bot{bot_count}` for further access tokens, such as `project_123_bot1`. +- The email is set to `project{project_id}_bot@example.com`, for example `project123_bot@example.com`. +- For additional access tokens in the same project, the username is set to `project_{project_id}_bot{bot_count}`, for example `project_123_bot1`. +- For additional acess tokens in the same project, the email is set to `project{project_id}_bot{bot_count}@example.com`, for example `project123_bot1@example.com` API calls made with a project access token are associated with the corresponding bot user. diff --git a/spec/initializers/0_postgresql_types_spec.rb b/spec/initializers/0_postgresql_types_spec.rb new file mode 100644 index 00000000000..76b243033d0 --- /dev/null +++ b/spec/initializers/0_postgresql_types_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'PostgreSQL registered types' do + subject(:types) { ApplicationRecord.connection.send(:type_map).keys } + + # These can be obtained via SELECT oid, typname from pg_type + it 'includes custom and standard OIDs' do + expect(types).to include(28, 194, 1034, 3220, 23, 20) + end + + it 'includes custom and standard types' do + expect(types).to include('xid', 'pg_node_tree', '_aclitem', 'pg_lsn', 'int4', 'int8') + end +end