Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-10-30 08:17:14 +0300
committerShinya Maeda <shinya@gitlab.com>2018-10-30 08:17:14 +0300
commit44406080442810ffea38d266955547d00ef987ac (patch)
treebac60af1248e23e470da414bdf695a3ee1802711
parent2b7dd373c97bc7cba76c4a5a53fed0ac081eae9f (diff)
Add action
-rw-r--r--app/models/concerns/deployable.rb3
-rw-r--r--app/models/deployment.rb7
-rw-r--r--db/migrate/20181015155839_add_finished_at_to_deployments.rb2
-rw-r--r--db/migrate/20181016141739_add_status_to_deployments.rb5
-rw-r--r--db/post_migrate/20181030135124_fill_empty_values_in_deployments.rb25
-rw-r--r--db/schema.rb4
6 files changed, 44 insertions, 2 deletions
diff --git a/app/models/concerns/deployable.rb b/app/models/concerns/deployable.rb
index 5b409c504db..9556ec49c9d 100644
--- a/app/models/concerns/deployable.rb
+++ b/app/models/concerns/deployable.rb
@@ -21,7 +21,8 @@ module Deployable
sha: sha,
user: user,
deployable: self,
- on_stop: on_stop)
+ on_stop: on_stop,
+ action: environment_action)
end
end
end
diff --git a/app/models/deployment.rb b/app/models/deployment.rb
index aa162fdb46e..be6e7c103e3 100644
--- a/app/models/deployment.rb
+++ b/app/models/deployment.rb
@@ -4,6 +4,7 @@ class Deployment < ActiveRecord::Base
include AtomicInternalId
include IidRoutes
include AfterCommitQueue
+ include EnumWithNil
belongs_to :project, required: true
belongs_to :environment, required: true
@@ -17,6 +18,12 @@ class Deployment < ActiveRecord::Base
delegate :name, to: :environment, prefix: true
+ enum_with_nil action: {
+ unknown_action: nil,
+ start: 1,
+ stop: 2
+ }
+
scope :for_environment, -> (environment) { where(environment_id: environment) }
scope :success, -> { with_status(:success) }
diff --git a/db/migrate/20181015155839_add_finished_at_to_deployments.rb b/db/migrate/20181015155839_add_finished_at_to_deployments.rb
index 3ca37cc5ddf..a86ea6dd0cd 100644
--- a/db/migrate/20181015155839_add_finished_at_to_deployments.rb
+++ b/db/migrate/20181015155839_add_finished_at_to_deployments.rb
@@ -9,9 +9,11 @@ class AddFinishedAtToDeployments < ActiveRecord::Migration
def up
add_column :deployments, :finished_at, :datetime_with_timezone
+ add_column :deployments, :action, :integer, limit: 2
end
def down
remove_column :deployments, :finished_at, :datetime_with_timezone
+ remove_column :deployments, :action, :integer, limit: 2
end
end
diff --git a/db/migrate/20181016141739_add_status_to_deployments.rb b/db/migrate/20181016141739_add_status_to_deployments.rb
index 3f00e1bb839..321172696b4 100644
--- a/db/migrate/20181016141739_add_status_to_deployments.rb
+++ b/db/migrate/20181016141739_add_status_to_deployments.rb
@@ -9,6 +9,11 @@ class AddStatusToDeployments < ActiveRecord::Migration
disable_ddl_transaction!
+ ##
+ # NOTE:
+ # Ideally, `status` column should not have default value because it should be leveraged by state machine (i.e. application level).
+ # However, we have to use the default value for avoiding `NOT NULL` violation during the transition period.
+ # The default value should be removed in the future release.
def up
add_column_with_default(:deployments,
:status,
diff --git a/db/post_migrate/20181030135124_fill_empty_values_in_deployments.rb b/db/post_migrate/20181030135124_fill_empty_values_in_deployments.rb
new file mode 100644
index 00000000000..88f3365f02d
--- /dev/null
+++ b/db/post_migrate/20181030135124_fill_empty_values_in_deployments.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class FillEmptyValuesInDeployments < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+
+ class Deployments < ActiveRecord::Base
+ self.table_name = 'deployments'
+
+ include EachBatch
+ end
+
+ def up
+ FillEmptyValuesInDeployments::Deployments
+ .where('finished_at IS NULL')
+ .each_batch(of: 10_000) do |relation|
+ relation.update_all('finished_at=created_at')
+ end
+ end
+
+ def down
+ # no-op
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 182c0da42ae..108097dd527 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20181022135539) do
+ActiveRecord::Schema.define(version: 20181030135124) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -826,6 +826,7 @@ ActiveRecord::Schema.define(version: 20181022135539) do
t.string "on_stop"
t.integer "status", limit: 2, default: 2, null: false
t.datetime_with_timezone "finished_at"
+ t.integer "action", limit: 2
end
add_index "deployments", ["created_at"], name: "index_deployments_on_created_at", using: :btree
@@ -1843,6 +1844,7 @@ ActiveRecord::Schema.define(version: 20181022135539) do
end
add_index "redirect_routes", ["path"], name: "index_redirect_routes_on_path", unique: true, using: :btree
+ add_index "redirect_routes", ["path"], name: "index_redirect_routes_on_path_text_pattern_ops", using: :btree, opclasses: {"path"=>"varchar_pattern_ops"}
add_index "redirect_routes", ["source_type", "source_id"], name: "index_redirect_routes_on_source_type_and_source_id", using: :btree
create_table "releases", force: :cascade do |t|