summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2018-12-18 19:02:36 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2018-12-18 21:13:38 -0200
commit754f66113e91ba880ed92075bd06adc1509c1d8f (patch)
tree9ff0cfa691b3388c91329918e2ac8594f7c6b221 /db
parent5d68c23792e87e710877e4baf57605bcf11a6cb5 (diff)
downloadgitlab-ce-754f66113e91ba880ed92075bd06adc1509c1d8f.tar.gz
Backfill project_repositories for legacy storage projects
Adds a background migration that will ensure all projects that are on legacy storage have a row in `project_repositories`.
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20181218192239_backfill_project_repositories_for_legacy_storage_projects.rb26
-rw-r--r--db/schema.rb2
2 files changed, 27 insertions, 1 deletions
diff --git a/db/post_migrate/20181218192239_backfill_project_repositories_for_legacy_storage_projects.rb b/db/post_migrate/20181218192239_backfill_project_repositories_for_legacy_storage_projects.rb
new file mode 100644
index 00000000000..42f96750789
--- /dev/null
+++ b/db/post_migrate/20181218192239_backfill_project_repositories_for_legacy_storage_projects.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class BackfillProjectRepositoriesForLegacyStorageProjects < ActiveRecord::Migration[5.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ BATCH_SIZE = 1_000
+ DELAY_INTERVAL = 5.minutes
+ MIGRATION = 'BackfillLegacyProjectRepositories'
+
+ disable_ddl_transaction!
+
+ class Project < ActiveRecord::Base
+ include EachBatch
+
+ self.table_name = 'projects'
+ end
+
+ def up
+ queue_background_migration_jobs_by_range_at_intervals(Project, MIGRATION, DELAY_INTERVAL)
+ end
+
+ def down
+ # no-op: since there could have been existing rows before the migration do not remove anything
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 008bff49a2b..604ed1cd6b0 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20181212104941) do
+ActiveRecord::Schema.define(version: 20181218192239) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"