summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2015-09-24 17:09:33 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2015-09-29 10:47:03 +0200
commit1530f68c9876bc8376bf4aa199c8abda570f5214 (patch)
tree025a0ff29e9c886a866d0e5c3362947257f75480
parente1b7fcedfb24353c857a160cd0c981f02fb2542a (diff)
downloadgitlab-ce-1530f68c9876bc8376bf4aa199c8abda570f5214.tar.gz
WIP
-rw-r--r--app/models/ci/build.rb3
-rw-r--r--app/models/ci/commit.rb8
-rw-r--r--app/models/ci/project.rb4
-rw-r--r--app/models/project.rb2
-rw-r--r--db/migrate/20150924125150_add_project_id_to_ci_tables.rb12
-rw-r--r--db/migrate/20150924125436_migrate_project_id_for_ci_tables.rb15
-rw-r--r--db/migrate/20150924131004_add_ci_fields_to_projects_table.rb5
7 files changed, 43 insertions, 6 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 8096d4fa5ae..16ff6e38630 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -30,7 +30,6 @@ module Ci
LAZY_ATTRIBUTES = ['trace']
belongs_to :commit, class_name: 'Ci::Commit'
- belongs_to :project, class_name: 'Ci::Project'
belongs_to :runner, class_name: 'Ci::Runner'
belongs_to :trigger_request, class_name: 'Ci::TriggerRequest'
@@ -137,7 +136,7 @@ module Ci
state :canceled, value: 'canceled'
end
- delegate :sha, :short_sha, :before_sha, :ref,
+ delegate :sha, :short_sha, :before_sha, :ref, :project,
to: :commit, prefix: false
def trace_html
diff --git a/app/models/ci/commit.rb b/app/models/ci/commit.rb
index f102d0a7679..31638c7e1dc 100644
--- a/app/models/ci/commit.rb
+++ b/app/models/ci/commit.rb
@@ -18,8 +18,8 @@
module Ci
class Commit < ActiveRecord::Base
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 :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest'
@@ -32,6 +32,10 @@ module Ci
sha[0...8]
end
+ def project
+ @project ||= gl_project.gitlab_ci_project
+ end
+
def to_param
sha
end
diff --git a/app/models/ci/project.rb b/app/models/ci/project.rb
index 8fb54b90d61..ea7547f5d43 100644
--- a/app/models/ci/project.rb
+++ b/app/models/ci/project.rb
@@ -33,7 +33,7 @@ module Ci
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 :runner_projects, dependent: :destroy, class_name: 'Ci::RunnerProject'
has_many :runners, through: :runner_projects, class_name: 'Ci::Runner'
@@ -41,7 +41,7 @@ module Ci
has_many :events, dependent: :destroy, class_name: 'Ci::Event'
has_many :variables, dependent: :destroy, class_name: 'Ci::Variable'
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
has_many :services, dependent: :destroy, class_name: 'Ci::Service'
diff --git a/app/models/project.rb b/app/models/project.rb
index e912c48467d..efa573c82b9 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -118,6 +118,8 @@ class Project < ActiveRecord::Base
has_many :deploy_keys, through: :deploy_keys_projects
has_many :users_star_projects, dependent: :destroy
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 :gitlab_ci_project, dependent: :destroy, class_name: "Ci::Project", foreign_key: :gitlab_id
diff --git a/db/migrate/20150924125150_add_project_id_to_ci_tables.rb b/db/migrate/20150924125150_add_project_id_to_ci_tables.rb
new file mode 100644
index 00000000000..8b45bcf5fe1
--- /dev/null
+++ b/db/migrate/20150924125150_add_project_id_to_ci_tables.rb
@@ -0,0 +1,12 @@
+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
diff --git a/db/migrate/20150924125436_migrate_project_id_for_ci_tables.rb b/db/migrate/20150924125436_migrate_project_id_for_ci_tables.rb
new file mode 100644
index 00000000000..28d63c8c840
--- /dev/null
+++ b/db/migrate/20150924125436_migrate_project_id_for_ci_tables.rb
@@ -0,0 +1,15 @@
+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
diff --git a/db/migrate/20150924131004_add_ci_fields_to_projects_table.rb b/db/migrate/20150924131004_add_ci_fields_to_projects_table.rb
new file mode 100644
index 00000000000..bb97ec30051
--- /dev/null
+++ b/db/migrate/20150924131004_add_ci_fields_to_projects_table.rb
@@ -0,0 +1,5 @@
+class AddCiFieldsToProjectsTable < ActiveRecord::Migration
+ def up
+ add_column :projects, :shared_runners_enabled, :boolean, default: false
+ end
+end