Skip to content
Snippets Groups Projects
Commit fcd2bdf1 authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Migrate tables

Revert some

Make it work

Migrate tags and taggings to
parent e3041b90
No related branches found
No related tags found
No related merge requests found
Showing
with 110 additions and 68 deletions
Loading
Loading
@@ -12,7 +12,7 @@ class Admin::RunnersController < Admin::ApplicationController
@builds = @runner.builds.order('id DESC').first(30)
@projects = Project.all
@projects = @projects.search(params[:search]) if params[:search].present?
@projects = @projects.where("projects.id NOT IN (?)", @runner.projects.pluck(:id)) if @runner.projects.any?
@projects = @projects.where("ci_projects.id NOT IN (?)", @runner.projects.pluck(:id)) if @runner.projects.any?
@projects = @projects.page(params[:page]).per(30)
end
 
Loading
Loading
Loading
Loading
@@ -10,7 +10,7 @@ class RunnersController < ApplicationController
def index
@runners = @project.runners.order('id DESC')
@specific_runners = current_user.authorized_runners.
where.not(id: @runners).order('runners.id DESC').page(params[:page]).per(20)
where.not(id: @runners).order('ci_runners.id DESC').page(params[:page]).per(20)
@shared_runners = Runner.shared.active
@shared_runners_count = @shared_runners.count(:all)
end
Loading
Loading
Loading
Loading
@@ -10,6 +10,7 @@
#
 
class ApplicationSetting < ActiveRecord::Base
extend Model
 
def self.current
ApplicationSetting.last
Loading
Loading
Loading
Loading
@@ -24,6 +24,8 @@
#
 
class Build < ActiveRecord::Base
extend Model
LAZY_ATTRIBUTES = ['trace']
 
belongs_to :commit
Loading
Loading
Loading
Loading
@@ -16,6 +16,8 @@
#
 
class Commit < ActiveRecord::Base
extend Model
belongs_to :project
has_many :builds, dependent: :destroy
has_many :trigger_requests, dependent: :destroy
Loading
Loading
Loading
Loading
@@ -12,6 +12,8 @@
#
 
class Event < ActiveRecord::Base
extend Model
belongs_to :project
 
validates :description,
Loading
Loading
Loading
Loading
@@ -26,6 +26,8 @@
#
 
class Project < ActiveRecord::Base
extend Model
include ProjectStatus
 
has_many :commits, ->() { order('CASE WHEN commits.committed_at IS NULL THEN 0 ELSE 1 END', :committed_at, :id) }, dependent: :destroy
Loading
Loading
@@ -105,19 +107,19 @@ ls -la
end
 
def unassigned(runner)
joins('LEFT JOIN runner_projects ON runner_projects.project_id = projects.id ' \
"AND runner_projects.runner_id = #{runner.id}").
where('runner_projects.project_id' => nil)
joins('LEFT JOIN ci_runner_projects ON ci_runner_projects.project_id = ci_projects.id ' \
"AND ci_runner_projects.runner_id = #{runner.id}").
where('ci_runner_projects.project_id' => nil)
end
 
def ordered_by_last_commit_date
last_commit_subquery = "(SELECT project_id, MAX(committed_at) committed_at FROM commits GROUP BY project_id)"
joins("LEFT JOIN #{last_commit_subquery} AS last_commit ON projects.id = last_commit.project_id").
last_commit_subquery = "(SELECT project_id, MAX(committed_at) committed_at FROM ci_commits GROUP BY project_id)"
joins("LEFT JOIN #{last_commit_subquery} AS last_commit ON ci_projects.id = last_commit.project_id").
order("CASE WHEN last_commit.committed_at IS NULL THEN 1 ELSE 0 END, last_commit.committed_at DESC")
end
 
def search(query)
where('LOWER(projects.name) LIKE :query',
where('LOWER(ci_projects.name) LIKE :query',
query: "%#{query.try(:downcase)}%")
end
end
Loading
Loading
Loading
Loading
@@ -18,6 +18,8 @@
#
 
class Runner < ActiveRecord::Base
extend Model
has_many :builds
has_many :runner_projects, dependent: :destroy
has_many :projects, through: :runner_projects
Loading
Loading
@@ -34,7 +36,7 @@ class Runner < ActiveRecord::Base
acts_as_taggable
 
def self.search(query)
where('LOWER(runners.token) LIKE :query OR LOWER(runners.description) like :query',
where('LOWER(ci_runners.token) LIKE :query OR LOWER(ci_runners.description) like :query',
query: "%#{query.try(:downcase)}%")
end
 
Loading
Loading
Loading
Loading
@@ -10,6 +10,8 @@
#
 
class RunnerProject < ActiveRecord::Base
extend Model
belongs_to :runner
belongs_to :project
 
Loading
Loading
Loading
Loading
@@ -15,6 +15,8 @@
# To add new service you should build a class inherited from Service
# and implement a set of methods
class Service < ActiveRecord::Base
extend Model
serialize :properties, JSON
 
default_value_for :active, false
Loading
Loading
Loading
Loading
@@ -11,6 +11,8 @@
#
 
class Trigger < ActiveRecord::Base
extend Model
acts_as_paranoid
 
belongs_to :project
Loading
Loading
Loading
Loading
@@ -11,6 +11,8 @@
#
 
class TriggerRequest < ActiveRecord::Base
extend Model
belongs_to :trigger
belongs_to :commit
has_many :builds
Loading
Loading
Loading
Loading
@@ -67,7 +67,7 @@ class User
 
def authorized_runners
Runner.specific.includes(:runner_projects).
where(runner_projects: { project_id: authorized_projects } )
where(ci_runner_projects: { project_id: authorized_projects } )
end
 
def authorized_projects
Loading
Loading
Loading
Loading
@@ -12,6 +12,8 @@
#
 
class Variable < ActiveRecord::Base
extend Model
belongs_to :project
 
validates_presence_of :key
Loading
Loading
Loading
Loading
@@ -10,6 +10,8 @@
#
 
class WebHook < ActiveRecord::Base
extend Model
include HTTParty
 
belongs_to :project
Loading
Loading
Loading
Loading
@@ -7,7 +7,7 @@ class RegisterBuildService
builds =
if current_runner.shared?
# don't run projects which have not enables shared runners
builds.includes(:project).where(projects: { shared_runners_enabled: true })
builds.includes(:project).where(ci_projects: { shared_runners_enabled: true })
else
# do run projects which are only assigned to this runner
builds.where(project_id: current_runner.projects)
Loading
Loading
class MigrateCiTables < ActiveRecord::Migration
def up
rename_table :application_settings, :ci_application_settings
rename_table :builds, :ci_builds
rename_table :commits, :ci_commits
rename_table :events, :ci_events
rename_table :jobs, :ci_jobs
rename_table :projects, :ci_projects
rename_table :runner_projects, :ci_runner_projects
rename_table :runners, :ci_runners
rename_table :services, :ci_services
rename_table :tags, :ci_tags
rename_table :taggings, :ci_taggings
rename_table :trigger_requests, :ci_trigger_requests
rename_table :triggers, :ci_triggers
rename_table :variables, :ci_variables
rename_table :web_hooks, :ci_web_hooks
end
end
Loading
Loading
@@ -11,19 +11,19 @@
#
# It's strongly recommended that you check this file into your version control system.
 
ActiveRecord::Schema.define(version: 20150824202238) do
ActiveRecord::Schema.define(version: 20150914102123) do
 
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
 
create_table "application_settings", force: true do |t|
create_table "ci_application_settings", force: true do |t|
t.boolean "all_broken_builds"
t.boolean "add_pusher"
t.datetime "created_at"
t.datetime "updated_at"
end
 
create_table "builds", force: true do |t|
create_table "ci_builds", force: true do |t|
t.integer "project_id"
t.string "status"
t.datetime "finished_at"
Loading
Loading
@@ -44,12 +44,12 @@ ActiveRecord::Schema.define(version: 20150824202238) do
t.integer "trigger_request_id"
end
 
add_index "builds", ["commit_id"], name: "index_builds_on_commit_id", using: :btree
add_index "builds", ["project_id", "commit_id"], name: "index_builds_on_project_id_and_commit_id", using: :btree
add_index "builds", ["project_id"], name: "index_builds_on_project_id", using: :btree
add_index "builds", ["runner_id"], name: "index_builds_on_runner_id", using: :btree
add_index "ci_builds", ["commit_id"], name: "index_ci_builds_on_commit_id", using: :btree
add_index "ci_builds", ["project_id", "commit_id"], name: "index_ci_builds_on_project_id_and_commit_id", using: :btree
add_index "ci_builds", ["project_id"], name: "index_ci_builds_on_project_id", using: :btree
add_index "ci_builds", ["runner_id"], name: "index_ci_builds_on_runner_id", using: :btree
 
create_table "commits", force: true do |t|
create_table "ci_commits", force: true do |t|
t.integer "project_id"
t.string "ref"
t.string "sha"
Loading
Loading
@@ -62,13 +62,13 @@ ActiveRecord::Schema.define(version: 20150824202238) do
t.datetime "committed_at"
end
 
add_index "commits", ["project_id", "committed_at", "id"], name: "index_commits_on_project_id_and_committed_at_and_id", using: :btree
add_index "commits", ["project_id", "committed_at"], name: "index_commits_on_project_id_and_committed_at", using: :btree
add_index "commits", ["project_id", "sha"], name: "index_commits_on_project_id_and_sha", using: :btree
add_index "commits", ["project_id"], name: "index_commits_on_project_id", using: :btree
add_index "commits", ["sha"], name: "index_commits_on_sha", using: :btree
add_index "ci_commits", ["project_id", "committed_at", "id"], name: "index_ci_commits_on_project_id_and_committed_at_and_id", using: :btree
add_index "ci_commits", ["project_id", "committed_at"], name: "index_ci_commits_on_project_id_and_committed_at", using: :btree
add_index "ci_commits", ["project_id", "sha"], name: "index_ci_commits_on_project_id_and_sha", using: :btree
add_index "ci_commits", ["project_id"], name: "index_ci_commits_on_project_id", using: :btree
add_index "ci_commits", ["sha"], name: "index_ci_commits_on_sha", using: :btree
 
create_table "events", force: true do |t|
create_table "ci_events", force: true do |t|
t.integer "project_id"
t.integer "user_id"
t.integer "is_admin"
Loading
Loading
@@ -77,11 +77,11 @@ ActiveRecord::Schema.define(version: 20150824202238) do
t.datetime "updated_at"
end
 
add_index "events", ["created_at"], name: "index_events_on_created_at", using: :btree
add_index "events", ["is_admin"], name: "index_events_on_is_admin", using: :btree
add_index "events", ["project_id"], name: "index_events_on_project_id", using: :btree
add_index "ci_events", ["created_at"], name: "index_ci_events_on_created_at", using: :btree
add_index "ci_events", ["is_admin"], name: "index_ci_events_on_is_admin", using: :btree
add_index "ci_events", ["project_id"], name: "index_ci_events_on_project_id", using: :btree
 
create_table "jobs", force: true do |t|
create_table "ci_jobs", force: true do |t|
t.integer "project_id", null: false
t.text "commands"
t.boolean "active", default: true, null: false
Loading
Loading
@@ -95,10 +95,10 @@ ActiveRecord::Schema.define(version: 20150824202238) do
t.datetime "deleted_at"
end
 
add_index "jobs", ["deleted_at"], name: "index_jobs_on_deleted_at", using: :btree
add_index "jobs", ["project_id"], name: "index_jobs_on_project_id", using: :btree
add_index "ci_jobs", ["deleted_at"], name: "index_ci_jobs_on_deleted_at", using: :btree
add_index "ci_jobs", ["project_id"], name: "index_ci_jobs_on_project_id", using: :btree
 
create_table "projects", force: true do |t|
create_table "ci_projects", force: true do |t|
t.string "name", null: false
t.integer "timeout", default: 3600, null: false
t.datetime "created_at"
Loading
Loading
@@ -121,17 +121,17 @@ ActiveRecord::Schema.define(version: 20150824202238) do
t.text "generated_yaml_config"
end
 
create_table "runner_projects", force: true do |t|
create_table "ci_runner_projects", force: true do |t|
t.integer "runner_id", null: false
t.integer "project_id", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
 
add_index "runner_projects", ["project_id"], name: "index_runner_projects_on_project_id", using: :btree
add_index "runner_projects", ["runner_id"], name: "index_runner_projects_on_runner_id", using: :btree
add_index "ci_runner_projects", ["project_id"], name: "index_ci_runner_projects_on_project_id", using: :btree
add_index "ci_runner_projects", ["runner_id"], name: "index_ci_runner_projects_on_runner_id", using: :btree
 
create_table "runners", force: true do |t|
create_table "ci_runners", force: true do |t|
t.string "token"
t.datetime "created_at"
t.datetime "updated_at"
Loading
Loading
@@ -146,7 +146,7 @@ ActiveRecord::Schema.define(version: 20150824202238) do
t.string "architecture"
end
 
create_table "services", force: true do |t|
create_table "ci_services", force: true do |t|
t.string "type"
t.string "title"
t.integer "project_id", null: false
Loading
Loading
@@ -156,7 +156,7 @@ ActiveRecord::Schema.define(version: 20150824202238) do
t.text "properties"
end
 
add_index "services", ["project_id"], name: "index_services_on_project_id", using: :btree
add_index "ci_services", ["project_id"], name: "index_ci_services_on_project_id", using: :btree
 
create_table "sessions", force: true do |t|
t.string "session_id", null: false
Loading
Loading
@@ -168,27 +168,7 @@ ActiveRecord::Schema.define(version: 20150824202238) do
add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree
add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree
 
create_table "taggings", force: true do |t|
t.integer "tag_id"
t.integer "taggable_id"
t.string "taggable_type"
t.integer "tagger_id"
t.string "tagger_type"
t.string "context", limit: 128
t.datetime "created_at"
end
add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true, using: :btree
add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree
create_table "tags", force: true do |t|
t.string "name"
t.integer "taggings_count", default: 0
end
add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree
create_table "trigger_requests", force: true do |t|
create_table "ci_trigger_requests", force: true do |t|
t.integer "trigger_id", null: false
t.text "variables"
t.datetime "created_at"
Loading
Loading
@@ -196,7 +176,7 @@ ActiveRecord::Schema.define(version: 20150824202238) do
t.integer "commit_id"
end
 
create_table "triggers", force: true do |t|
create_table "ci_triggers", force: true do |t|
t.string "token"
t.integer "project_id", null: false
t.datetime "deleted_at"
Loading
Loading
@@ -204,9 +184,9 @@ ActiveRecord::Schema.define(version: 20150824202238) do
t.datetime "updated_at"
end
 
add_index "triggers", ["deleted_at"], name: "index_triggers_on_deleted_at", using: :btree
add_index "ci_triggers", ["deleted_at"], name: "index_ci_triggers_on_deleted_at", using: :btree
 
create_table "variables", force: true do |t|
create_table "ci_variables", force: true do |t|
t.integer "project_id", null: false
t.string "key"
t.text "value"
Loading
Loading
@@ -215,13 +195,33 @@ ActiveRecord::Schema.define(version: 20150824202238) do
t.string "encrypted_value_iv"
end
 
add_index "variables", ["project_id"], name: "index_variables_on_project_id", using: :btree
add_index "ci_variables", ["project_id"], name: "index_ci_variables_on_project_id", using: :btree
 
create_table "web_hooks", force: true do |t|
create_table "ci_web_hooks", force: true do |t|
t.string "url", null: false
t.integer "project_id", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
 
create_table "taggings", force: true do |t|
t.integer "tag_id"
t.integer "taggable_id"
t.string "taggable_type"
t.integer "tagger_id"
t.string "tagger_type"
t.string "context", limit: 128
t.datetime "created_at"
end
add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true, using: :btree
add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree
create_table "tags", force: true do |t|
t.string "name"
t.integer "taggings_count", default: 0
end
add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree
end
Loading
Loading
@@ -16,10 +16,10 @@ module Charts
def push(from, to, format)
@labels << from.strftime(format)
@total << project.builds.
where('? > builds.created_at AND builds.created_at > ?', to, from).
where('? > ci_builds.created_at AND ci_builds.created_at > ?', to, from).
count(:all)
@success << project.builds.
where('? > builds.created_at AND builds.created_at > ?', to, from).
where('? > ci_builds.created_at AND ci_builds.created_at > ?', to, from).
success.count(:all)
end
end
Loading
Loading
@@ -59,7 +59,7 @@ module Charts
 
class BuildTime < Chart
def collect
commits = project.commits.joins(:builds).where('builds.finished_at is NOT NULL AND builds.started_at is NOT NULL').last(30)
commits = project.commits.joins(:builds).where('ci_builds.finished_at is NOT NULL AND ci_builds.started_at is NOT NULL').last(30)
commits.each do |commit|
@labels << commit.short_sha
@build_times << (commit.duration / 60)
Loading
Loading
Loading
Loading
@@ -3,7 +3,7 @@ module CurrentSettings
key = :current_application_settings
 
RequestStore.store[key] ||= begin
if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.table_exists?('application_settings')
if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.table_exists?('ci_application_settings')
ApplicationSetting.current || ApplicationSetting.create_from_defaults
else
fake_application_settings
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment