diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /doc/development/database/migrations_for_multiple_databases.md | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'doc/development/database/migrations_for_multiple_databases.md')
-rw-r--r-- | doc/development/database/migrations_for_multiple_databases.md | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/doc/development/database/migrations_for_multiple_databases.md b/doc/development/database/migrations_for_multiple_databases.md index b4d2656121b..bc0ef654336 100644 --- a/doc/development/database/migrations_for_multiple_databases.md +++ b/doc/development/database/migrations_for_multiple_databases.md @@ -58,7 +58,7 @@ Example migration adding a concurrent index that is treated as change of the str that is executed on all configured databases. ```ruby -class AddUserIdAndStateIndexToMergeRequestReviewers < Gitlab::Database::Migration[2.0] +class AddUserIdAndStateIndexToMergeRequestReviewers < Gitlab::Database::Migration[2.1] disable_ddl_transaction! INDEX_NAME = 'index_on_merge_request_reviewers_user_id_and_state' @@ -75,16 +75,24 @@ end #### Example: Add a new table to store in a single database -1. Define the [GitLab Schema](multiple_databases.md#gitlab-schema) of the table in [`lib/gitlab/database/gitlab_schemas.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/database/gitlab_schemas.yml): +1. Add the table to the [database dictionary](database_dictionary.md) in [`db/docs/`](https://gitlab.com/gitlab-org/gitlab/-/tree/master/db/docs): ```yaml - ssh_signatures: :gitlab_main + table_name: ssh_signatures + description: Description example + introduced_by_url: Merge request link + milestone: Milestone example + feature_categories: + - Feature category example + classes: + - Class example + gitlab_schema: gitlab_main ``` 1. Create the table in a schema migration: ```ruby - class CreateSshSignatures < Gitlab::Database::Migration[2.0] + class CreateSshSignatures < Gitlab::Database::Migration[2.1] def change create_table :ssh_signatures do |t| t.timestamps_with_timezone null: false @@ -125,7 +133,7 @@ Example migration updating `archived` column of `projects` that is executed only for the database containing `gitlab_main` schema. ```ruby -class UpdateProjectsArchivedState < Gitlab::Database::Migration[2.0] +class UpdateProjectsArchivedState < Gitlab::Database::Migration[2.1] disable_ddl_transaction! restrict_gitlab_migration gitlab_schema: :gitlab_main @@ -157,7 +165,7 @@ databases. For example, running migration in context of `ci:` and reading featur from `main:`, as no established connection to another database is present. ```ruby -class UpdateProjectsArchivedState < Gitlab::Database::Migration[2.0] +class UpdateProjectsArchivedState < Gitlab::Database::Migration[2.1] disable_ddl_transaction! restrict_gitlab_migration gitlab_schema: :gitlab_main @@ -195,7 +203,7 @@ that is marked in `lib/gitlab/database/gitlab_schemas.yml` as `gitlab_shared`. This migration is executed across all configured databases. ```ruby -class DeleteAllLooseForeignKeyRecords < Gitlab::Database::Migration[2.0] +class DeleteAllLooseForeignKeyRecords < Gitlab::Database::Migration[2.1] disable_ddl_transaction! def up @@ -211,13 +219,13 @@ end #### Example: run DML `gitlab_shared` only on the database containing the given `gitlab_schema` Example migration updating `loose_foreign_keys_deleted_records` table -that is marked in `lib/gitlab/database/gitlab_schemas.yml` as `gitlab_shared`. +that is marked in `db/docs/loose_foreign_keys_deleted_records.yml` as `gitlab_shared`. This migration since it configures restriction on `gitlab_ci` is executed only in context of database containing `gitlab_ci` schema. ```ruby -class DeleteCiBuildsLooseForeignKeyRecords < Gitlab::Database::Migration[2.0] +class DeleteCiBuildsLooseForeignKeyRecords < Gitlab::Database::Migration[2.1] disable_ddl_transaction! restrict_gitlab_migration gitlab_schema: :gitlab_ci @@ -261,7 +269,7 @@ the `database_tasks: false` set. `gitlab:db:validate_config` always runs before ## Validation Validation in a nutshell uses [`pg_query`](https://github.com/pganalyze/pg_query) to analyze -each query and classify tables with information from [`gitlab_schema.yml`](multiple_databases.md#gitlab-schema). +each query and classify tables with information from [`db/docs/`](database_dictionary.md). The migration is skipped if the specified `gitlab_schema` is outside of a list of schemas managed by a given database connection (`Gitlab::Database::gitlab_schemas_for_connection`). @@ -279,7 +287,7 @@ as part of the migration run and prevent the migration from being completed. ### Exception 1: migration running in DDL mode does DML select ```ruby -class UpdateProjectsArchivedState < Gitlab::Database::Migration[2.0] +class UpdateProjectsArchivedState < Gitlab::Database::Migration[2.1] disable_ddl_transaction! # Missing: @@ -310,7 +318,7 @@ running in **DDL** mode, but the executed payload appears to be reading data fro ### Exception 2: migration running in DML mode changes the structure ```ruby -class AddUserIdAndStateIndexToMergeRequestReviewers < Gitlab::Database::Migration[2.0] +class AddUserIdAndStateIndexToMergeRequestReviewers < Gitlab::Database::Migration[2.1] disable_ddl_transaction! # restrict_gitlab_migration if defined indicates DML, it should be removed @@ -341,7 +349,7 @@ but the executed payload appears to be doing structure changes (DDL). ### Exception 3: migration running in DML mode accesses data from a table in another schema ```ruby -class UpdateProjectsArchivedState < Gitlab::Database::Migration[2.0] +class UpdateProjectsArchivedState < Gitlab::Database::Migration[2.1] disable_ddl_transaction! # Since it modifies `projects` it should use `gitlab_main` @@ -372,7 +380,7 @@ data in `gitlab_main`. ### Exception 4: mixing DDL and DML mode ```ruby -class UpdateProjectsArchivedState < Gitlab::Database::Migration[2.0] +class UpdateProjectsArchivedState < Gitlab::Database::Migration[2.1] disable_ddl_transaction! # This migration is invalid regardless of specification @@ -435,4 +443,4 @@ tables in any database, just like any ordinary Sidekiq worker can. ## How to determine `gitlab_schema` for a given table -See [GitLab Schema](multiple_databases.md#gitlab-schema). +See [database dictionary](database_dictionary.md). |