diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-19 13:21:01 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-07-19 13:21:01 +0200 |
commit | 98f5c00e7ac860c7ac78b8245b171f2f27681563 (patch) | |
tree | a416e87601f76ba04f1401bc03df23dfb0759449 /db | |
parent | a6d1e92d98e71098c5a32999294bcdce6c7a092d (diff) | |
parent | 2ddcb1f1a6b68f67e6e50283b4ab0c8df29f6b43 (diff) | |
download | gitlab-ce-98f5c00e7ac860c7ac78b8245b171f2f27681563.tar.gz |
Merge branch 'master' into backstage/gb/build-stage-id-ref-bg-migration-cleanupbackstage/gb/build-stage-id-ref-bg-migration-cleanup
* master: (59 commits)
Resolve "Clarify k8s service keys"
Add Portuguese Brazil translations of Commits Page & Pipeline Charts
Add Japanese Translation to i18n
Update Prometheus gem to version that explicitly calls `munmap`
Simplify width for dropdown-menu on mobile
Update CHANGELOG.md for 9.3.7
Remove developer documentation about not describing symbols
Incorporate Gitaly's Commits#between RPC
Adapt to new Gitaly commit message format
Remove transitions on nav link hover
Provide option to trigger build only for official CE and EE repos in .com
Fix queries duration sorting in Performance Bar
Rename Project nav items
Add structured logging for Rails processes
Disable Rails logging in CI test environments
Fix download artifacts button alignment
Update avatar border to be opaque for better stacking
Fixed typos
Fix typos
Fix external issue trackers redirect
...
Conflicts:
db/schema.rb
Diffstat (limited to 'db')
5 files changed, 167 insertions, 1 deletions
diff --git a/db/migrate/20170713104829_add_foreign_key_to_merge_requests.rb b/db/migrate/20170713104829_add_foreign_key_to_merge_requests.rb new file mode 100644 index 00000000000..c25d4fd5986 --- /dev/null +++ b/db/migrate/20170713104829_add_foreign_key_to_merge_requests.rb @@ -0,0 +1,45 @@ +class AddForeignKeyToMergeRequests < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + class MergeRequest < ActiveRecord::Base + self.table_name = 'merge_requests' + include ::EachBatch + end + + def up + scope = <<-SQL.strip_heredoc + head_pipeline_id IS NOT NULL + AND NOT EXISTS ( + SELECT 1 FROM ci_pipelines + WHERE ci_pipelines.id = merge_requests.head_pipeline_id + ) + SQL + + MergeRequest.where(scope).each_batch(of: 1000) do |merge_requests| + merge_requests.update_all(head_pipeline_id: nil) + end + + unless foreign_key_exists?(:merge_requests, :head_pipeline_id) + add_concurrent_foreign_key(:merge_requests, :ci_pipelines, + column: :head_pipeline_id, on_delete: :nullify) + end + end + + def down + if foreign_key_exists?(:merge_requests, :head_pipeline_id) + remove_foreign_key(:merge_requests, column: :head_pipeline_id) + end + end + + private + + def foreign_key_exists?(table, column) + foreign_keys(table).any? do |key| + key.options[:column] == column.to_s + end + end +end diff --git a/db/migrate/20170717074009_move_system_upload_folder.rb b/db/migrate/20170717074009_move_system_upload_folder.rb new file mode 100644 index 00000000000..cce31794115 --- /dev/null +++ b/db/migrate/20170717074009_move_system_upload_folder.rb @@ -0,0 +1,60 @@ +class MoveSystemUploadFolder < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + disable_ddl_transaction! + + DOWNTIME = false + + def up + unless file_storage? + say 'Using object storage, no need to move.' + return + end + + unless File.directory?(old_directory) + say "#{old_directory} doesn't exist, no need to move it." + return + end + + FileUtils.mkdir_p(File.join(base_directory, '-')) + + say "Moving #{old_directory} -> #{new_directory}" + FileUtils.mv(old_directory, new_directory) + FileUtils.ln_s(new_directory, old_directory) + end + + def down + unless file_storage? + say 'Using object storage, no need to move.' + return + end + + unless File.directory?(new_directory) + say "#{new_directory} doesn't exist, no need to move it." + return + end + + if File.symlink?(old_directory) + say "Removing #{old_directory} -> #{new_directory} symlink" + FileUtils.rm(old_directory) + end + + say "Moving #{new_directory} -> #{old_directory}" + FileUtils.mv(new_directory, old_directory) + end + + def new_directory + File.join(base_directory, '-', 'system') + end + + def old_directory + File.join(base_directory, 'system') + end + + def base_directory + File.join(Rails.root, 'public', 'uploads') + end + + def file_storage? + CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File + end +end diff --git a/db/post_migrate/20170717111152_cleanup_move_system_upload_folder_symlink.rb b/db/post_migrate/20170717111152_cleanup_move_system_upload_folder_symlink.rb new file mode 100644 index 00000000000..26b99b61424 --- /dev/null +++ b/db/post_migrate/20170717111152_cleanup_move_system_upload_folder_symlink.rb @@ -0,0 +1,40 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class CleanupMoveSystemUploadFolderSymlink < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + if File.symlink?(old_directory) + say "Removing #{old_directory} -> #{new_directory} symlink" + FileUtils.rm(old_directory) + else + say "Symlink #{old_directory} non existant, nothing to do." + end + end + + def down + if File.directory?(new_directory) + say "Symlinking #{old_directory} -> #{new_directory}" + FileUtils.ln_s(new_directory, old_directory) + else + say "#{new_directory} doesn't exist, skipping." + end + end + + def new_directory + File.join(base_directory, '-', 'system') + end + + def old_directory + File.join(base_directory, 'system') + end + + def base_directory + File.join(Rails.root, 'public', 'uploads') + end +end diff --git a/db/post_migrate/20170717150329_enqueue_migrate_system_uploads_to_new_folder.rb b/db/post_migrate/20170717150329_enqueue_migrate_system_uploads_to_new_folder.rb new file mode 100644 index 00000000000..87069dce006 --- /dev/null +++ b/db/post_migrate/20170717150329_enqueue_migrate_system_uploads_to_new_folder.rb @@ -0,0 +1,20 @@ +class EnqueueMigrateSystemUploadsToNewFolder < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + OLD_FOLDER = 'uploads/system/' + NEW_FOLDER = 'uploads/-/system/' + + disable_ddl_transaction! + + def up + BackgroundMigrationWorker.perform_async('MigrateSystemUploadsToNewFolder', + [OLD_FOLDER, NEW_FOLDER]) + end + + def down + BackgroundMigrationWorker.perform_async('MigrateSystemUploadsToNewFolder', + [NEW_FOLDER, OLD_FOLDER]) + end +end diff --git a/db/schema.rb b/db/schema.rb index 623f22289ba..284b2068166 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170710083355) do +ActiveRecord::Schema.define(version: 20170717150329) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -1615,6 +1615,7 @@ ActiveRecord::Schema.define(version: 20170710083355) do add_foreign_key "merge_request_diffs", "merge_requests", name: "fk_8483f3258f", on_delete: :cascade add_foreign_key "merge_request_metrics", "ci_pipelines", column: "pipeline_id", on_delete: :cascade add_foreign_key "merge_request_metrics", "merge_requests", on_delete: :cascade + add_foreign_key "merge_requests", "ci_pipelines", column: "head_pipeline_id", name: "fk_fd82eae0b9", on_delete: :nullify add_foreign_key "merge_requests", "projects", column: "target_project_id", name: "fk_a6963e8447", on_delete: :cascade add_foreign_key "merge_requests_closing_issues", "issues", on_delete: :cascade add_foreign_key "merge_requests_closing_issues", "merge_requests", on_delete: :cascade |