Commit 1530f68c authored by Kamil Trzcinski's avatar Kamil Trzcinski

WIP

parent e1b7fced
...@@ -30,7 +30,6 @@ module Ci ...@@ -30,7 +30,6 @@ module Ci
LAZY_ATTRIBUTES = ['trace'] LAZY_ATTRIBUTES = ['trace']
belongs_to :commit, class_name: 'Ci::Commit' belongs_to :commit, class_name: 'Ci::Commit'
belongs_to :project, class_name: 'Ci::Project'
belongs_to :runner, class_name: 'Ci::Runner' belongs_to :runner, class_name: 'Ci::Runner'
belongs_to :trigger_request, class_name: 'Ci::TriggerRequest' belongs_to :trigger_request, class_name: 'Ci::TriggerRequest'
...@@ -137,7 +136,7 @@ module Ci ...@@ -137,7 +136,7 @@ module Ci
state :canceled, value: 'canceled' state :canceled, value: 'canceled'
end end
delegate :sha, :short_sha, :before_sha, :ref, delegate :sha, :short_sha, :before_sha, :ref, :project,
to: :commit, prefix: false to: :commit, prefix: false
def trace_html def trace_html
......
...@@ -19,7 +19,7 @@ module Ci ...@@ -19,7 +19,7 @@ module Ci
class Commit < ActiveRecord::Base class Commit < ActiveRecord::Base
extend Ci::Model extend Ci::Model
belongs_to :project, class_name: 'Ci::Project' belongs_to :gl_project, class_name: '::Project', foreign_key: :gl_project_id
has_many :builds, dependent: :destroy, class_name: 'Ci::Build' has_many :builds, dependent: :destroy, class_name: 'Ci::Build'
has_many :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest' has_many :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest'
...@@ -32,6 +32,10 @@ module Ci ...@@ -32,6 +32,10 @@ module Ci
sha[0...8] sha[0...8]
end end
def project
@project ||= gl_project.gitlab_ci_project
end
def to_param def to_param
sha sha
end end
......
...@@ -33,7 +33,7 @@ module Ci ...@@ -33,7 +33,7 @@ module Ci
belongs_to :gl_project, class_name: '::Project', foreign_key: :gitlab_id belongs_to :gl_project, class_name: '::Project', foreign_key: :gitlab_id
has_many :commits, ->() { order('CASE WHEN ci_commits.committed_at IS NULL THEN 0 ELSE 1 END', :committed_at, :id) }, dependent: :destroy, class_name: 'Ci::Commit' has_many :commits, through: :gl_project, class_name: 'Ci::Commit', foreign_key: :gl_project_id
has_many :builds, through: :commits, dependent: :destroy, class_name: 'Ci::Build' has_many :builds, through: :commits, dependent: :destroy, class_name: 'Ci::Build'
has_many :runner_projects, dependent: :destroy, class_name: 'Ci::RunnerProject' has_many :runner_projects, dependent: :destroy, class_name: 'Ci::RunnerProject'
has_many :runners, through: :runner_projects, class_name: 'Ci::Runner' has_many :runners, through: :runner_projects, class_name: 'Ci::Runner'
...@@ -41,7 +41,7 @@ module Ci ...@@ -41,7 +41,7 @@ module Ci
has_many :events, dependent: :destroy, class_name: 'Ci::Event' has_many :events, dependent: :destroy, class_name: 'Ci::Event'
has_many :variables, dependent: :destroy, class_name: 'Ci::Variable' has_many :variables, dependent: :destroy, class_name: 'Ci::Variable'
has_many :triggers, dependent: :destroy, class_name: 'Ci::Trigger' has_many :triggers, dependent: :destroy, class_name: 'Ci::Trigger'
has_one :last_commit, -> { order 'ci_commits.created_at DESC' }, class_name: 'Ci::Commit' has_one :last_commit, through: :gl_project, class_name: 'Ci::Commit'
# Project services # Project services
has_many :services, dependent: :destroy, class_name: 'Ci::Service' has_many :services, dependent: :destroy, class_name: 'Ci::Service'
......
...@@ -118,6 +118,8 @@ class Project < ActiveRecord::Base ...@@ -118,6 +118,8 @@ class Project < ActiveRecord::Base
has_many :deploy_keys, through: :deploy_keys_projects has_many :deploy_keys, through: :deploy_keys_projects
has_many :users_star_projects, dependent: :destroy has_many :users_star_projects, dependent: :destroy
has_many :starrers, through: :users_star_projects, source: :user has_many :starrers, through: :users_star_projects, source: :user
has_many :commits, ->() { order('CASE WHEN ci_commits.committed_at IS NULL THEN 0 ELSE 1 END', :committed_at, :id) }, dependent: :destroy, class_name: 'Ci::Commit', foreign_key: :gl_project_id
has_one :last_commit, -> { order 'ci_commits.created_at DESC' }, class_name: 'Ci::Commit', foreign_key: :gl_project_id
has_one :import_data, dependent: :destroy, class_name: "ProjectImportData" has_one :import_data, dependent: :destroy, class_name: "ProjectImportData"
has_one :gitlab_ci_project, dependent: :destroy, class_name: "Ci::Project", foreign_key: :gitlab_id has_one :gitlab_ci_project, dependent: :destroy, class_name: "Ci::Project", foreign_key: :gitlab_id
......
class AddProjectIdToCiTables < ActiveRecord::Migration
def up
add_column :ci_builds, :gl_project_id, :integer
add_column :ci_commits, :gl_project_id, :integer
add_column :ci_events, :gl_project_id, :integer
add_column :ci_runner_projects, :gl_project_id, :integer
add_column :ci_services, :gl_project_id, :integer
add_column :ci_triggers, :gl_project_id, :integer
add_column :ci_variables, :gl_project_id, :integer
add_column :ci_web_hooks, :gl_project_id, :integer
end
end
class MigrateProjectIdForCiTables < ActiveRecord::Migration
TABLES = %w(ci_builds ci_commits ci_events ci_runner_projects
ci_services ci_triggers ci_variables ci_web_hooks)
def up
TABLES.each do |table|
execute(
"UPDATE #{table} " +
"JOIN ci_projects ON ci_projects.id = #{table}.project_id " +
"SET gl_project_id=ci_projects.gitlab_id " +
"WHERE gl_project_id IS NULL"
)
end
end
end
class AddCiFieldsToProjectsTable < ActiveRecord::Migration
def up
add_column :projects, :shared_runners_enabled, :boolean, default: false
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