summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20190617154954_add_root_id_to_namespace.rb11
-rw-r--r--db/migrate/20190617181054_schedule_populate_namespace_root_id.rb32
-rw-r--r--db/schema.rb3
3 files changed, 45 insertions, 1 deletions
diff --git a/db/migrate/20190617154954_add_root_id_to_namespace.rb b/db/migrate/20190617154954_add_root_id_to_namespace.rb
new file mode 100644
index 00000000000..db9bfa7fd8b
--- /dev/null
+++ b/db/migrate/20190617154954_add_root_id_to_namespace.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class AddRootIdToNamespace < ActiveRecord::Migration[5.1]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ def change
+ add_column :namespaces, :root_id, :integer
+ end
+end
diff --git a/db/migrate/20190617181054_schedule_populate_namespace_root_id.rb b/db/migrate/20190617181054_schedule_populate_namespace_root_id.rb
new file mode 100644
index 00000000000..09e28cbe01c
--- /dev/null
+++ b/db/migrate/20190617181054_schedule_populate_namespace_root_id.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+class SchedulePopulateNamespaceRootId < ActiveRecord::Migration[5.1]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ BATCH_SIZE = 10_000
+ MIGRATION = 'PopulateNamespaceRootIdColumn'
+ DELAY_INTERVAL = 10.minutes.to_i
+
+ disable_ddl_transaction!
+
+ class Namespace < ActiveRecord::Base
+ self.table_name = 'namespaces'
+
+ include EachBatch
+ end
+
+ def up
+ say 'Scheduling `PopulateNamespaceRootIdColumn` jobs'
+
+ # We currently have ~4_600_000 namespace records on GitLab.com
+ # This means, the migration will schedule ~460 jobs (10k each) within a 10 minutes gap.
+ # so this should take ~153 hours to complete (assuming 30k namespaces per hour)
+ queue_background_migration_jobs_by_range_at_intervals(
+ Namespace,
+ MIGRATION,
+ DELAY_INTERVAL,
+ batch_size: BATCH_SIZE
+ )
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 7a7319c132e..b534877e30c 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: 20190613030606) do
+ActiveRecord::Schema.define(version: 20190617181054) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -2098,6 +2098,7 @@ ActiveRecord::Schema.define(version: 20190613030606) do
t.integer "extra_shared_runners_minutes_limit"
t.string "ldap_sync_status", default: "ready", null: false
t.boolean "membership_lock", default: false
+ t.integer "root_id"
t.index ["created_at"], name: "index_namespaces_on_created_at", using: :btree
t.index ["custom_project_templates_group_id", "type"], name: "index_namespaces_on_custom_project_templates_group_id_and_type", where: "(custom_project_templates_group_id IS NOT NULL)", using: :btree
t.index ["file_template_project_id"], name: "index_namespaces_on_file_template_project_id", using: :btree