Fix build stages reference migration

This commit is contained in:
Grzegorz Bizon 2017-06-21 10:32:45 +02:00
parent 4b0b2f1525
commit 6b9608e13e
5 changed files with 39 additions and 5 deletions

View File

@ -7,15 +7,11 @@ class AddStageIdToCiBuilds < ActiveRecord::Migration
def up
add_column :ci_builds, :stage_id, :integer
add_concurrent_foreign_key :ci_builds, :ci_stages, column: :stage_id, on_delete: :cascade
add_concurrent_index :ci_builds, :stage_id
end
def down
remove_foreign_key :ci_builds, column: :stage_id
remove_concurrent_index :ci_builds, :stage_id
remove_column :ci_builds, :stage_id, :integer
end
end

View File

@ -0,0 +1,17 @@
class RemoveStageIdIndexFromBuilds < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
if index_exists?(:ci_builds, :stage_id)
remove_concurrent_index(:ci_builds, :stage_id)
end
end
def down
# noop
end
end

View File

@ -3,6 +3,8 @@ class MigrateBuildStageReference < ActiveRecord::Migration
DOWNTIME = false
disable_ddl_transaction!
def up
disable_statement_timeout

View File

@ -0,0 +1,19 @@
class AddStageIdIndexToBuilds < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
unless index_exists?(:ci_builds, :stage_id)
add_concurrent_index(:ci_builds, :stage_id)
end
end
def down
if index_exists?(:ci_builds, :stage_id)
remove_concurrent_index(:ci_builds, :stage_id)
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170614115405) do
ActiveRecord::Schema.define(version: 20170621102400) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"