Commit 40a3b467 authored by Micaël Bergeron's avatar Micaël Bergeron

add the Ci::Build `*_store` column

parent e43d7d2b
...@@ -3,6 +3,7 @@ module Ci ...@@ -3,6 +3,7 @@ module Ci
prepend ArtifactMigratable prepend ArtifactMigratable
include TokenAuthenticatable include TokenAuthenticatable
include AfterCommitQueue include AfterCommitQueue
include ObjectStorage::BackgroundMove
include Presentable include Presentable
include Importable include Importable
...@@ -41,10 +42,13 @@ module Ci ...@@ -41,10 +42,13 @@ module Ci
scope :unstarted, ->() { where(runner_id: nil) } scope :unstarted, ->() { where(runner_id: nil) }
scope :ignore_failures, ->() { where(allow_failure: false) } scope :ignore_failures, ->() { where(allow_failure: false) }
scope :with_artifacts, ->() do scope :with_artifacts, ->() do
where('(artifacts_file IS NOT NULL AND artifacts_file <> ?) OR EXISTS (?)', where('(artifacts_file IS NOT NULL AND artifacts_file <> ?) OR EXISTS (?)',
'', Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id')) '', Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id'))
end end
scope :with_artifacts_stored_locally, -> { with_artifacts.where(artifacts_file_store: [nil, LegacyArtifactUploader::Store::LOCAL]) }
scope :with_artifacts_not_expired, ->() { with_artifacts.where('artifacts_expire_at IS NULL OR artifacts_expire_at > ?', Time.now) } scope :with_artifacts_not_expired, ->() { with_artifacts.where('artifacts_expire_at IS NULL OR artifacts_expire_at > ?', Time.now) }
scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) } scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) }
scope :with_artifacts_stored_locally, ->() { with_artifacts.where(artifacts_file_store: [nil, LegacyArtifactUploader::Store::LOCAL]) } scope :with_artifacts_stored_locally, ->() { with_artifacts.where(artifacts_file_store: [nil, LegacyArtifactUploader::Store::LOCAL]) }
......
...@@ -7,31 +7,31 @@ class PortObjectStorageToCe < ActiveRecord::Migration ...@@ -7,31 +7,31 @@ class PortObjectStorageToCe < ActiveRecord::Migration
# Set this constant to true if this migration requires downtime. # Set this constant to true if this migration requires downtime.
DOWNTIME = false DOWNTIME = false
def up def add_column_idempotent(table, column, *defs)
unless column_exists?(:ci_job_artifacts, :file_store) return if column_exists?(table, column)
add_column(:ci_job_artifacts, :file_store, :integer)
end
unless column_exists?(:lfs_objects, :file_store)
add_column(:lfs_objects, :file_store, :integer)
end
unless column_exists?(:uploads, :store) add_column(table, column, *defs)
add_column(:uploads, :store, :integer)
end
end end
def down def remove_column_idempotent(table, column)
if column_exists?(:ci_job_artifacts, :file_store) return unless column_exists?(table, column)
remove_column(:ci_job_artifacts, :file_store)
end remove_column(table, column)
end
if column_exists?(:lfs_objects, :file_store) def up
remove_column(:lfs_objects, :file_store) add_column_idempotent(:ci_job_artifacts, :file_store, :integer)
end add_column_idempotent(:ci_builds, :artifacts_file_store, :integer)
add_column_idempotent(:ci_builds, :artifacts_metadata_store, :integer)
add_column_idempotent(:lfs_objects, :file_store, :integer)
add_column_idempotent(:uploads, :store, :integer)
end
if column_exists?(:uploads, :store) def down
remove_column(:uploads, :store) remove_column_idempotent(:ci_job_artifacts, :file_store)
end remove_column_idempotent(:ci_builds, :artifacts_file_store)
remove_column_idempotent(:ci_builds, :artifacts_metadata_store)
remove_column_idempotent(:lfs_objects, :file_store)
remove_column_idempotent(:uploads, :store)
end end
end end
...@@ -294,6 +294,8 @@ ActiveRecord::Schema.define(version: 20180222152310) do ...@@ -294,6 +294,8 @@ ActiveRecord::Schema.define(version: 20180222152310) do
t.integer "artifacts_metadata_store", default: 1, null: false t.integer "artifacts_metadata_store", default: 1, null: false
t.boolean "protected" t.boolean "protected"
t.integer "failure_reason" t.integer "failure_reason"
t.integer "artifacts_file_store"
t.integer "artifacts_metadata_store"
end end
add_index "ci_builds", ["artifacts_expire_at"], name: "index_ci_builds_on_artifacts_expire_at", where: "(artifacts_file <> ''::text)", using: :btree add_index "ci_builds", ["artifacts_expire_at"], name: "index_ci_builds_on_artifacts_expire_at", where: "(artifacts_file <> ''::text)", using: :btree
......
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