summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicaël Bergeron <mbergeron@gitlab.com>2018-02-26 14:14:00 -0500
committerMicaël Bergeron <mbergeron@gitlab.com>2018-02-26 14:14:00 -0500
commit94c881b75ff8ccfb0445316cd644f3e311451f53 (patch)
tree5ec1a04970b74437c60ce2f07740ebb5fbe3edec
parentca0bedb6372040dcd395fd93028986932364dff7 (diff)
downloadgitlab-ce-94c881b75ff8ccfb0445316cd644f3e311451f53.tar.gz
add the Ci::Build `*_store` column
-rw-r--r--app/models/ci/build.rb4
-rw-r--r--db/migrate/20180222152310_port_object_storage_to_ce.rb42
-rw-r--r--db/schema.rb2
3 files changed, 27 insertions, 21 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index ee987949080..8ec7002c888 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -3,6 +3,7 @@ module Ci
prepend ArtifactMigratable
include TokenAuthenticatable
include AfterCommitQueue
+ include ObjectStorage::BackgroundMove
include Presentable
include Importable
@@ -41,10 +42,13 @@ module Ci
scope :unstarted, ->() { where(runner_id: nil) }
scope :ignore_failures, ->() { where(allow_failure: false) }
+
scope :with_artifacts, ->() do
where('(artifacts_file IS NOT NULL AND artifacts_file <> ?) OR EXISTS (?)',
'', Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id'))
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_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) }
scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) }
diff --git a/db/migrate/20180222152310_port_object_storage_to_ce.rb b/db/migrate/20180222152310_port_object_storage_to_ce.rb
index aa1e15072b8..f2e2e53ed8c 100644
--- a/db/migrate/20180222152310_port_object_storage_to_ce.rb
+++ b/db/migrate/20180222152310_port_object_storage_to_ce.rb
@@ -7,31 +7,31 @@ class PortObjectStorageToCe < ActiveRecord::Migration
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
- def up
- unless column_exists?(:ci_job_artifacts, :file_store)
- add_column(:ci_job_artifacts, :file_store, :integer)
- end
-
- unless column_exists?(:lfs_objects, :file_store)
- add_column(:lfs_objects, :file_store, :integer)
- end
+ def add_column_idempotent(table, column, *defs)
+ return if column_exists?(table, column)
- unless column_exists?(:uploads, :store)
- add_column(:uploads, :store, :integer)
- end
+ add_column(table, column, *defs)
end
- def down
- if column_exists?(:ci_job_artifacts, :file_store)
- remove_column(:ci_job_artifacts, :file_store)
- end
+ def remove_column_idempotent(table, column)
+ return unless column_exists?(table, column)
+
+ remove_column(table, column)
+ end
- if column_exists?(:lfs_objects, :file_store)
- remove_column(:lfs_objects, :file_store)
- end
+ def up
+ add_column_idempotent(:ci_job_artifacts, :file_store, :integer)
+ 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)
- remove_column(:uploads, :store)
- end
+ def down
+ remove_column_idempotent(:ci_job_artifacts, :file_store)
+ 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
diff --git a/db/schema.rb b/db/schema.rb
index d6c1ff134ef..622c6e06491 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -291,6 +291,8 @@ ActiveRecord::Schema.define(version: 20180222152310) do
t.integer "stage_id"
t.boolean "protected"
t.integer "failure_reason"
+ t.integer "artifacts_file_store"
+ t.integer "artifacts_metadata_store"
end
add_index "ci_builds", ["artifacts_expire_at"], name: "index_ci_builds_on_artifacts_expire_at", where: "(artifacts_file <> ''::text)", using: :btree