about summary refs log tree commit diff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20170112154826_migrate_settings.rb19
-rw-r--r--db/schema.rb10
2 files changed, 24 insertions, 5 deletions
diff --git a/db/migrate/20170112154826_migrate_settings.rb b/db/migrate/20170112154826_migrate_settings.rb
new file mode 100644
index 000000000..f6f6ed531
--- /dev/null
+++ b/db/migrate/20170112154826_migrate_settings.rb
@@ -0,0 +1,19 @@
+class MigrateSettings < ActiveRecord::Migration
+  def up
+    remove_index :settings, [:target_type, :target_id, :var]
+    rename_column :settings, :target_id, :thing_id
+    rename_column :settings, :target_type, :thing_type
+    change_column :settings, :thing_id, :integer, null: true, default: nil
+    change_column :settings, :thing_type, :string, null: true, default: nil
+    add_index :settings, [:thing_type, :thing_id, :var], unique: true
+  end
+
+  def down
+    remove_index :settings, [:thing_type, :thing_id, :var]
+    rename_column :settings, :thing_id, :target_id
+    rename_column :settings, :thing_type, :target_type
+    change_column :settings, :target_id, :integer, null: false
+    change_column :settings, :target_type, :string, null: false, default: ''
+    add_index :settings, [:target_type, :target_id, :var], unique: true
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 5a5dd83c7..1cd1258db 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20170109120109) do
+ActiveRecord::Schema.define(version: 20170112154826) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -238,13 +238,13 @@ ActiveRecord::Schema.define(version: 20170109120109) do
   end
 
   create_table "settings", force: :cascade do |t|
-    t.string   "var",         null: false
+    t.string   "var",        null: false
     t.text     "value"
-    t.string   "target_type", null: false
-    t.integer  "target_id",   null: false
+    t.string   "thing_type"
+    t.integer  "thing_id"
     t.datetime "created_at"
     t.datetime "updated_at"
-    t.index ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true, using: :btree
+    t.index ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true, using: :btree
   end
 
   create_table "statuses", force: :cascade do |t|