diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-18 00:56:05 -0200 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-19 14:58:27 -0200 |
commit | 771d3fc3cbaa2b473c87d23fc1c067fb9bad6206 (patch) | |
tree | b7a2e209ca9d5521d0e09152ec6b0858ebac1324 /db | |
parent | d009d38ed6ab5459f596194ce808c304e6379161 (diff) | |
download | gitlab-ce-771d3fc3cbaa2b473c87d23fc1c067fb9bad6206.tar.gz |
Split migration to create label priorities
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20161014173530_create_label_priorities.rb | 32 | ||||
-rw-r--r-- | db/migrate/20161018024215_migrate_labels_priority.rb | 36 | ||||
-rw-r--r-- | db/migrate/20161018024550_remove_priority_from_labels.rb | 17 | ||||
-rw-r--r-- | db/schema.rb | 2 |
4 files changed, 55 insertions, 32 deletions
diff --git a/db/migrate/20161014173530_create_label_priorities.rb b/db/migrate/20161014173530_create_label_priorities.rb index f9d94ebdc70..2c22841c28a 100644 --- a/db/migrate/20161014173530_create_label_priorities.rb +++ b/db/migrate/20161014173530_create_label_priorities.rb @@ -2,7 +2,7 @@ class CreateLabelPriorities < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers DOWNTIME = true - DOWNTIME_REASON = 'Prioritezed labels will not work as expected until this migration is complete.' + DOWNTIME_REASON = 'This migration adds foreign keys' disable_ddl_transaction! @@ -15,41 +15,11 @@ class CreateLabelPriorities < ActiveRecord::Migration t.timestamps null: false end - execute <<-EOF.strip_heredoc - INSERT INTO label_priorities (project_id, label_id, priority, created_at, updated_at) - SELECT labels.project_id, labels.id, labels.priority, NOW(), NOW() - FROM labels - WHERE labels.project_id IS NOT NULL - AND labels.priority IS NOT NULL; - EOF - add_concurrent_index :label_priorities, [:project_id, :label_id], unique: true add_concurrent_index :label_priorities, :priority - - remove_column :labels, :priority end def down - add_column :labels, :priority, :integer - - if Gitlab::Database.mysql? - execute <<-EOF.strip_heredoc - UPDATE labels - INNER JOIN label_priorities ON labels.id = label_priorities.label_id AND labels.project_id = label_priorities.project_id - SET labels.priority = label_priorities.priority; - EOF - else - execute <<-EOF.strip_heredoc - UPDATE labels - SET priority = label_priorities.priority - FROM label_priorities - WHERE labels.id = label_priorities.label_id - AND labels.project_id = label_priorities.project_id; - EOF - end - - add_concurrent_index :labels, :priority - drop_table :label_priorities end end diff --git a/db/migrate/20161018024215_migrate_labels_priority.rb b/db/migrate/20161018024215_migrate_labels_priority.rb new file mode 100644 index 00000000000..22bec2382f4 --- /dev/null +++ b/db/migrate/20161018024215_migrate_labels_priority.rb @@ -0,0 +1,36 @@ +class MigrateLabelsPriority < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = true + DOWNTIME_REASON = 'Prioritized labels will not work as expected until this migration is complete.' + + disable_ddl_transaction! + + def up + execute <<-EOF.strip_heredoc + INSERT INTO label_priorities (project_id, label_id, priority, created_at, updated_at) + SELECT labels.project_id, labels.id, labels.priority, NOW(), NOW() + FROM labels + WHERE labels.project_id IS NOT NULL + AND labels.priority IS NOT NULL; + EOF + end + + def down + if Gitlab::Database.mysql? + execute <<-EOF.strip_heredoc + UPDATE labels + INNER JOIN label_priorities ON labels.id = label_priorities.label_id AND labels.project_id = label_priorities.project_id + SET labels.priority = label_priorities.priority; + EOF + else + execute <<-EOF.strip_heredoc + UPDATE labels + SET priority = label_priorities.priority + FROM label_priorities + WHERE labels.id = label_priorities.label_id + AND labels.project_id = label_priorities.project_id; + EOF + end + end +end diff --git a/db/migrate/20161018024550_remove_priority_from_labels.rb b/db/migrate/20161018024550_remove_priority_from_labels.rb new file mode 100644 index 00000000000..b7416cca664 --- /dev/null +++ b/db/migrate/20161018024550_remove_priority_from_labels.rb @@ -0,0 +1,17 @@ +class RemovePriorityFromLabels < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = true + DOWNTIME_REASON = 'This migration removes an existing column' + + disable_ddl_transaction! + + def up + remove_column :labels, :priority, :integer, index: true + end + + def down + add_column :labels, :priority, :integer + add_concurrent_index :labels, :priority + end +end diff --git a/db/schema.rb b/db/schema.rb index f9353290abf..65f55aa109b 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: 20161017125927) do +ActiveRecord::Schema.define(version: 20161018024550) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |