Commit 855b2820 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve db migrations for notification settings

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 4ca73f56
class CreateNotificationSettings < ActiveRecord::Migration class CreateNotificationSettings < ActiveRecord::Migration
def change def change
create_table :notification_settings do |t| create_table :notification_settings do |t|
t.integer :user_id t.references :user, null: false
t.integer :level t.references :source, polymorphic: true, null: false
t.integer :source_id t.integer :level, default: 0, null: false
t.string :source_type
t.timestamps null: false t.timestamps null: false
end end
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
class MigrateNewNotificationSetting < ActiveRecord::Migration class MigrateNewNotificationSetting < ActiveRecord::Migration
def up def up
timestamp = Time.now timestamp = Time.now
execute "INSERT INTO notification_settings ( user_id, source_id, source_type, level, created_at, updated_at ) SELECT user_id, source_id, source_type, notification_level, '#{timestamp}', '#{timestamp}' FROM members" execute "INSERT INTO notification_settings ( user_id, source_id, source_type, level, created_at, updated_at ) SELECT user_id, source_id, source_type, notification_level, '#{timestamp}', '#{timestamp}' FROM members WHERE user_id IS NOT NULL"
end end
def down def down
......
...@@ -639,12 +639,12 @@ ActiveRecord::Schema.define(version: 20160328121138) do ...@@ -639,12 +639,12 @@ ActiveRecord::Schema.define(version: 20160328121138) do
add_index "notes", ["updated_at"], name: "index_notes_on_updated_at", using: :btree add_index "notes", ["updated_at"], name: "index_notes_on_updated_at", using: :btree
create_table "notification_settings", force: :cascade do |t| create_table "notification_settings", force: :cascade do |t|
t.integer "user_id" t.integer "user_id", null: false
t.integer "level" t.integer "source_id", null: false
t.integer "source_id" t.string "source_type", null: false
t.string "source_type" t.integer "level", default: 0, null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end end
add_index "notification_settings", ["source_id", "source_type"], name: "index_notification_settings_on_source_id_and_source_type", using: :btree add_index "notification_settings", ["source_id", "source_type"], name: "index_notification_settings_on_source_id_and_source_type", using: :btree
...@@ -798,9 +798,9 @@ ActiveRecord::Schema.define(version: 20160328121138) do ...@@ -798,9 +798,9 @@ ActiveRecord::Schema.define(version: 20160328121138) do
t.string "type" t.string "type"
t.string "title" t.string "title"
t.integer "project_id" t.integer "project_id"
t.datetime "created_at", null: false t.datetime "created_at"
t.datetime "updated_at", null: false t.datetime "updated_at"
t.boolean "active", null: false t.boolean "active", default: false, null: false
t.text "properties" t.text "properties"
t.boolean "template", default: false t.boolean "template", default: false
t.boolean "push_events", default: true t.boolean "push_events", default: true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment