Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-08-30 16:38:16 +0300
committerYorick Peterse <yorickpeterse@gmail.com>2017-09-06 17:40:31 +0300
commit235b105c917c16ab14a79ba13280aff4fd9f1cf9 (patch)
tree27bfe7e1ff2e4caacbdc4450e510164771b66c19 /db/post_migrate
parent1632ffa6ad16738994122f0e84f331d50f220879 (diff)
Finish migration to the new events setup
This finishes the procedure for migrating events from the old format into the new format. Code no longer uses the old setup and the database tables used during the migration process are swapped, with the old table being dropped. While the database migration can be reversed this will 1) take a lot of time as data has to be coped around 2) won't restore data in the "events.data" column as we have no way of restoring this. Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/37241
Diffstat (limited to 'db/post_migrate')
-rw-r--r--db/post_migrate/20170830150306_drop_events_for_migration_table.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/db/post_migrate/20170830150306_drop_events_for_migration_table.rb b/db/post_migrate/20170830150306_drop_events_for_migration_table.rb
new file mode 100644
index 00000000000..763ee9a810d
--- /dev/null
+++ b/db/post_migrate/20170830150306_drop_events_for_migration_table.rb
@@ -0,0 +1,48 @@
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class DropEventsForMigrationTable < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ class Event < ActiveRecord::Base
+ include EachBatch
+ end
+
+ def up
+ transaction do
+ drop_table :events_for_migration
+ end
+ end
+
+ # rubocop: disable Migration/Datetime
+ def down
+ create_table :events_for_migration do |t|
+ t.string :target_type, index: true
+ t.integer :target_id, index: true
+ t.string :title
+ t.text :data
+ t.integer :project_id
+ t.datetime :created_at, index: true
+ t.datetime :updated_at
+ t.integer :action, index: true
+ t.integer :author_id, index: true
+
+ t.index [:project_id, :id]
+ end
+
+ Event.all.each_batch do |relation|
+ start_id, stop_id = relation.pluck('MIN(id), MAX(id)').first
+
+ execute <<-EOF.strip_heredoc
+ INSERT INTO events_for_migration (target_type, target_id, project_id, created_at, updated_at, action, author_id)
+ SELECT target_type, target_id, project_id, created_at, updated_at, action, author_id
+ FROM events
+ WHERE id BETWEEN #{start_id} AND #{stop_id}
+ EOF
+ end
+ end
+end