From b3dc4fb72146d439314bdb40377272a317974397 Mon Sep 17 00:00:00 2001
From: Andrew8xx8 <avk@8xx8.ru>
Date: Mon, 25 Mar 2013 00:39:38 +0400
Subject: [PATCH] Migrations to convert data added

---
 db/migrate/20130323174317_add_private_to_snippets.rb   |  2 +-
 .../20130324203535_add_type_value_for_snippets.rb      |  8 ++++++++
 db/schema.rb                                           | 10 +++++-----
 3 files changed, 14 insertions(+), 6 deletions(-)
 create mode 100644 db/migrate/20130324203535_add_type_value_for_snippets.rb

diff --git a/db/migrate/20130323174317_add_private_to_snippets.rb b/db/migrate/20130323174317_add_private_to_snippets.rb
index 427b530464d..92f3a5c7011 100644
--- a/db/migrate/20130323174317_add_private_to_snippets.rb
+++ b/db/migrate/20130323174317_add_private_to_snippets.rb
@@ -1,5 +1,5 @@
 class AddPrivateToSnippets < ActiveRecord::Migration
   def change
-    add_column :snippets, :private, :boolean
+    add_column :snippets, :private, :boolean, null: false, default: true
   end
 end
diff --git a/db/migrate/20130324203535_add_type_value_for_snippets.rb b/db/migrate/20130324203535_add_type_value_for_snippets.rb
new file mode 100644
index 00000000000..8c05dd2cc71
--- /dev/null
+++ b/db/migrate/20130324203535_add_type_value_for_snippets.rb
@@ -0,0 +1,8 @@
+class AddTypeValueForSnippets < ActiveRecord::Migration
+  def up
+    Snippet.where("project_id IS NOT NULL").update_all(type: 'ProjectSnippet')
+  end
+
+  def down
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index f54bd2e16ea..c988b172d90 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20130324172327) do
+ActiveRecord::Schema.define(:version => 20130324203535) do
 
   create_table "events", :force => true do |t|
     t.string   "target_type"
@@ -184,13 +184,13 @@ ActiveRecord::Schema.define(:version => 20130324172327) do
   create_table "snippets", :force => true do |t|
     t.string   "title"
     t.text     "content"
-    t.integer  "author_id",  :null => false
+    t.integer  "author_id",                    :null => false
     t.integer  "project_id"
-    t.datetime "created_at", :null => false
-    t.datetime "updated_at", :null => false
+    t.datetime "created_at",                   :null => false
+    t.datetime "updated_at",                   :null => false
     t.string   "file_name"
     t.datetime "expires_at"
-    t.boolean  "private"
+    t.boolean  "private",    :default => true, :null => false
     t.string   "type"
   end
 
-- 
GitLab