Commit 872bbb9f authored by Kamil Trzcinski's avatar Kamil Trzcinski

Cleanup required migrations

parent daa29729
class AddActionToCiCommit < ActiveRecord::Migration
def change
add_column :ci_commits, :action, :string
end
end
class AddDurationToCiCommit < ActiveRecord::Migration
def change
add_column :ci_commits, :duration, :integer
end
end
...@@ -3,5 +3,6 @@ class AddFieldsToCiCommit < ActiveRecord::Migration ...@@ -3,5 +3,6 @@ class AddFieldsToCiCommit < ActiveRecord::Migration
add_column :ci_commits, :status, :string add_column :ci_commits, :status, :string
add_column :ci_commits, :started_at, :timestamp add_column :ci_commits, :started_at, :timestamp
add_column :ci_commits, :finished_at, :timestamp add_column :ci_commits, :finished_at, :timestamp
add_column :ci_commits, :duration, :integer
end end
end end
class UpdateCiCommit < ActiveRecord::Migration class UpdateCiCommit < ActiveRecord::Migration
# This migration can be run online, but needs to be executed for the second time after restarting Unicorn workers
# Otherwise Offline migration should be used.
def change def change
execute("UPDATE ci_commits SET status=#{status}, ref=#{ref}, tag=#{tag} WHERE status IS NULL") execute("UPDATE ci_commits SET status=#{status}, ref=#{ref}, tag=#{tag} WHERE status IS NULL")
end end
private
def status def status
builds = '(SELECT COUNT(*) FROM ci_builds WHERE ci_builds.commit_id=ci_commits.id)' builds = '(SELECT COUNT(*) FROM ci_builds WHERE ci_builds.commit_id=ci_commits.id)'
success = "(SELECT COUNT(*) FROM ci_builds WHERE ci_builds.commit_id=ci_commits.id AND status='success')" success = "(SELECT COUNT(*) FROM ci_builds WHERE ci_builds.commit_id=ci_commits.id AND status='success')"
......
...@@ -7,6 +7,8 @@ class AddCiCommitIndexes < ActiveRecord::Migration ...@@ -7,6 +7,8 @@ class AddCiCommitIndexes < ActiveRecord::Migration
add_index :ci_commits, [:status], index_options add_index :ci_commits, [:status], index_options
end end
private
def index_options def index_options
{ algorithm: :concurrently } if Gitlab::Database.postgresql? { algorithm: :concurrently } if Gitlab::Database.postgresql?
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment