diff options
Diffstat (limited to 'db/migrate')
9 files changed, 181 insertions, 1 deletions
diff --git a/db/migrate/20160713200638_add_repository_read_only_to_projects.rb b/db/migrate/20160713200638_add_repository_read_only_to_projects.rb new file mode 100644 index 00000000000..8ee8b55f210 --- /dev/null +++ b/db/migrate/20160713200638_add_repository_read_only_to_projects.rb @@ -0,0 +1,9 @@ +class AddRepositoryReadOnlyToProjects < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + add_column :projects, :repository_read_only, :boolean + end +end diff --git a/db/migrate/20170720122741_create_user_custom_attributes.rb b/db/migrate/20170720122741_create_user_custom_attributes.rb new file mode 100644 index 00000000000..b1c0bebc633 --- /dev/null +++ b/db/migrate/20170720122741_create_user_custom_attributes.rb @@ -0,0 +1,17 @@ +class CreateUserCustomAttributes < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + create_table :user_custom_attributes do |t| + t.timestamps_with_timezone null: false + t.references :user, null: false, foreign_key: { on_delete: :cascade } + t.string :key, null: false + t.string :value, null: false + + t.index [:user_id, :key], unique: true + t.index [:key, :value] + end + end +end diff --git a/db/migrate/20170828135939_migrate_user_external_mail_data.rb b/db/migrate/20170828135939_migrate_user_external_mail_data.rb index 592e141b7e6..f7ac87374b6 100644 --- a/db/migrate/20170828135939_migrate_user_external_mail_data.rb +++ b/db/migrate/20170828135939_migrate_user_external_mail_data.rb @@ -33,7 +33,7 @@ class MigrateUserExternalMailData < ActiveRecord::Migration SELECT true FROM user_synced_attributes_metadata WHERE user_id = users.id - AND provider = users.email_provider + AND (provider = users.email_provider OR (provider IS NULL AND users.email_provider IS NULL)) ) AND id BETWEEN #{start_id} AND #{end_id} EOF diff --git a/db/migrate/20170912113435_clean_stages_statuses_migration.rb b/db/migrate/20170912113435_clean_stages_statuses_migration.rb new file mode 100644 index 00000000000..fc091d7894e --- /dev/null +++ b/db/migrate/20170912113435_clean_stages_statuses_migration.rb @@ -0,0 +1,26 @@ +class CleanStagesStatusesMigration < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + class Stage < ActiveRecord::Base + include ::EachBatch + self.table_name = 'ci_stages' + end + + def up + Gitlab::BackgroundMigration.steal('MigrateStageStatus') + + Stage.where('status IS NULL').each_batch(of: 50) do |batch| + range = batch.pluck('MIN(id)', 'MAX(id)').first + + Gitlab::BackgroundMigration::MigrateStageStatus.new.perform(*range) + end + end + + def down + # noop + end +end diff --git a/db/migrate/20170918222253_reorganize_deployments_indexes.rb b/db/migrate/20170918222253_reorganize_deployments_indexes.rb new file mode 100644 index 00000000000..139427ed2b9 --- /dev/null +++ b/db/migrate/20170918222253_reorganize_deployments_indexes.rb @@ -0,0 +1,28 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class ReorganizeDeploymentsIndexes < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_index_if_not_exists :deployments, [:environment_id, :iid, :project_id] + remove_index_if_exists :deployments, [:project_id, :environment_id, :iid] + end + + def down + add_index_if_not_exists :deployments, [:project_id, :environment_id, :iid] + remove_index_if_exists :deployments, [:environment_id, :iid, :project_id] + end + + def add_index_if_not_exists(table, columns) + add_concurrent_index(table, columns) unless index_exists?(table, columns) + end + + def remove_index_if_exists(table, columns) + remove_concurrent_index(table, columns) if index_exists?(table, columns) + end +end diff --git a/db/migrate/20170918223303_add_deployments_index_for_last_deployment.rb b/db/migrate/20170918223303_add_deployments_index_for_last_deployment.rb new file mode 100644 index 00000000000..b91efb86d98 --- /dev/null +++ b/db/migrate/20170918223303_add_deployments_index_for_last_deployment.rb @@ -0,0 +1,21 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddDeploymentsIndexForLastDeployment < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + disable_ddl_transaction! + + TO_INDEX = [:deployments, %i[environment_id id]].freeze + + def up + add_concurrent_index(*TO_INDEX) + end + + def down + remove_concurrent_index(*TO_INDEX) + end +end diff --git a/db/migrate/20170919211300_remove_temporary_ci_builds_index.rb b/db/migrate/20170919211300_remove_temporary_ci_builds_index.rb new file mode 100644 index 00000000000..b2009b282e9 --- /dev/null +++ b/db/migrate/20170919211300_remove_temporary_ci_builds_index.rb @@ -0,0 +1,27 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class RemoveTemporaryCiBuildsIndex < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + # To use create/remove index concurrently + disable_ddl_transaction! + + def up + return unless index_exists?(:ci_builds, :id, name: 'index_for_ci_builds_retried_migration') + remove_concurrent_index(:ci_builds, :id, name: "index_for_ci_builds_retried_migration") + end + + def down + # this was a temporary index for a migration that was never + # present previously so this probably shouldn't be here but it's + # easier to test the drop if we have a way to create it. + add_concurrent_index("ci_builds", ["id"], + name: "index_for_ci_builds_retried_migration", + where: "(retried IS NULL)", + using: :btree) + end +end diff --git a/db/migrate/20170921115009_add_project_repository_storage_index.rb b/db/migrate/20170921115009_add_project_repository_storage_index.rb new file mode 100644 index 00000000000..1c5a8fd65e1 --- /dev/null +++ b/db/migrate/20170921115009_add_project_repository_storage_index.rb @@ -0,0 +1,19 @@ +class AddProjectRepositoryStorageIndex < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index(*index_spec) unless index_exists?(*index_spec) + end + + def down + remove_concurrent_index(*index_spec) if index_exists?(*index_spec) + end + + def index_spec + [:projects, :repository_storage] + end +end diff --git a/db/migrate/20170928100231_add_composite_index_on_merge_requests_merge_commit_sha.rb b/db/migrate/20170928100231_add_composite_index_on_merge_requests_merge_commit_sha.rb new file mode 100644 index 00000000000..9f02daf04c1 --- /dev/null +++ b/db/migrate/20170928100231_add_composite_index_on_merge_requests_merge_commit_sha.rb @@ -0,0 +1,33 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddCompositeIndexOnMergeRequestsMergeCommitSha < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + # The default index name is too long for PostgreSQL and would thus be + # truncated. + INDEX_NAME = 'index_merge_requests_on_tp_id_and_merge_commit_sha_and_id' + + COLUMNS = [:target_project_id, :merge_commit_sha, :id] + + disable_ddl_transaction! + + def up + return if index_is_present? + + add_concurrent_index(:merge_requests, COLUMNS, name: INDEX_NAME) + end + + def down + return unless index_is_present? + + remove_concurrent_index(:merge_requests, COLUMNS, name: INDEX_NAME) + end + + def index_is_present? + index_exists?(:merge_requests, COLUMNS, name: INDEX_NAME) + end +end |