From de12a69a3c33562e7cd4fa81b5e12799a3f68f95 Mon Sep 17 00:00:00 2001
From: Felipe Artur <felipefac@gmail.com>
Date: Fri, 27 Jan 2017 17:22:17 -0200
Subject: [PATCH] Disable invalid service templates

---
 changelogs/unreleased/issue_25112.yml             |  4 ++++
 ...211073944_disable_invalid_service_templates.rb | 15 +++++++++++++++
 db/schema.rb                                      |  2 +-
 3 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 changelogs/unreleased/issue_25112.yml
 create mode 100644 db/post_migrate/20170211073944_disable_invalid_service_templates.rb

diff --git a/changelogs/unreleased/issue_25112.yml b/changelogs/unreleased/issue_25112.yml
new file mode 100644
index 00000000000..c43d2732b9a
--- /dev/null
+++ b/changelogs/unreleased/issue_25112.yml
@@ -0,0 +1,4 @@
+---
+title: Disable invalid service templates
+merge_request:
+author:
diff --git a/db/post_migrate/20170211073944_disable_invalid_service_templates.rb b/db/post_migrate/20170211073944_disable_invalid_service_templates.rb
new file mode 100644
index 00000000000..84954b1ef64
--- /dev/null
+++ b/db/post_migrate/20170211073944_disable_invalid_service_templates.rb
@@ -0,0 +1,15 @@
+class DisableInvalidServiceTemplates < ActiveRecord::Migration
+  DOWNTIME = false
+
+  unless defined?(Service)
+    class Service < ActiveRecord::Base
+      self.inheritance_column = nil
+    end
+  end
+
+  def up
+    Service.where(template: true, active: true).each do |template|
+      template.update(active: false) unless template.valid?
+    end
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index d421d5c6774..3dde4b9c82b 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: 20170210075922) do
+ActiveRecord::Schema.define(version: 20170211073944) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
-- 
GitLab