diff options
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20181005125926_add_index_to_uploads_store.rb | 17 | ||||
-rw-r--r-- | db/migrate/20181026143227_migrate_snippets_access_level_default_value.rb | 42 | ||||
-rw-r--r-- | db/post_migrate/20181105201455_steal_fill_store_upload.rb | 31 | ||||
-rw-r--r-- | db/schema.rb | 3 |
4 files changed, 92 insertions, 1 deletions
diff --git a/db/migrate/20181005125926_add_index_to_uploads_store.rb b/db/migrate/20181005125926_add_index_to_uploads_store.rb new file mode 100644 index 00000000000..d32ca05e980 --- /dev/null +++ b/db/migrate/20181005125926_add_index_to_uploads_store.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexToUploadsStore < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index :uploads, :store + end + + def down + remove_concurrent_index :uploads, :store + end +end diff --git a/db/migrate/20181026143227_migrate_snippets_access_level_default_value.rb b/db/migrate/20181026143227_migrate_snippets_access_level_default_value.rb new file mode 100644 index 00000000000..ede0ee27b8a --- /dev/null +++ b/db/migrate/20181026143227_migrate_snippets_access_level_default_value.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class MigrateSnippetsAccessLevelDefaultValue < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + ENABLED = 20 + + disable_ddl_transaction! + + class ProjectFeature < ActiveRecord::Base + include EachBatch + + self.table_name = 'project_features' + end + + def up + change_column_default :project_features, :snippets_access_level, ENABLED + + # On GitLab.com this will update about 28 000 rows. Since our updates are + # very small and this column is not indexed, these updates should be very + # lightweight. + ProjectFeature.where(snippets_access_level: nil).each_batch do |batch| + batch.update_all(snippets_access_level: ENABLED) + end + + # We do not need to perform this in a post-deployment migration as the + # ProjectFeature model already enforces a default value for all new rows. + change_column_null :project_features, :snippets_access_level, false + end + + def down + change_column_null :project_features, :snippets_access_level, true + change_column_default :project_features, :snippets_access_level, nil + + # We can't migrate from 20 -> NULL, as some projects may have explicitly set + # the access level to 20. + end +end diff --git a/db/post_migrate/20181105201455_steal_fill_store_upload.rb b/db/post_migrate/20181105201455_steal_fill_store_upload.rb new file mode 100644 index 00000000000..982001fedbe --- /dev/null +++ b/db/post_migrate/20181105201455_steal_fill_store_upload.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class StealFillStoreUpload < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + BATCH_SIZE = 10_000 + + disable_ddl_transaction! + + class Upload < ActiveRecord::Base + include EachBatch + + self.table_name = 'uploads' + self.inheritance_column = :_type_disabled # Disable STI + end + + def up + Gitlab::BackgroundMigration.steal('FillStoreUpload') + + Upload.where(store: nil).each_batch(of: BATCH_SIZE) do |batch| + range = batch.pluck('MIN(id)', 'MAX(id)').first + + Gitlab::BackgroundMigration::FillStoreUpload.new.perform(*range) + end + end + + def down + # noop + end +end diff --git a/db/schema.rb b/db/schema.rb index 4695d923b79..765cbf0606a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1632,7 +1632,7 @@ ActiveRecord::Schema.define(version: 20181107054254) do t.integer "merge_requests_access_level" t.integer "issues_access_level" t.integer "wiki_access_level" - t.integer "snippets_access_level" + t.integer "snippets_access_level", default: 20, null: false t.integer "builds_access_level" t.datetime "created_at" t.datetime "updated_at" @@ -2156,6 +2156,7 @@ ActiveRecord::Schema.define(version: 20181107054254) do add_index "uploads", ["checksum"], name: "index_uploads_on_checksum", using: :btree add_index "uploads", ["model_id", "model_type"], name: "index_uploads_on_model_id_and_model_type", using: :btree + add_index "uploads", ["store"], name: "index_uploads_on_store", using: :btree add_index "uploads", ["uploader", "path"], name: "index_uploads_on_uploader_and_path", using: :btree create_table "user_agent_details", force: :cascade do |t| |