修改迁移文件

This commit is contained in:
nwb 2014-06-04 11:59:26 +08:00
parent c43bf84e42
commit d4bc8139a3
5 changed files with 45 additions and 34 deletions

View File

@ -4,7 +4,7 @@ class CreateRelativeMemos < ActiveRecord::Migration
t.integer :osp_id, :null => true
t.integer :parent_id, null: true
t.string :subject, null: false
t.mediumtext :content, null: false
t.text :content, null: false
t.integer :author_id
t.integer :replies_count, default: 0
t.integer :last_reply_id

View File

@ -2,13 +2,17 @@ class AddBoardsTypeToBoards < ActiveRecord::Migration
def change
add_column :boards, :course_id, :int
Board.all.each do |board|
project = Project.find_by_id(board.project_id)
if project && project.project_type == 1
board.course_id = board.project_id
board.project_id = nil
board.save
end
end
Board.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id")
Board.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1)
#Board.all.each do |board|
# project = Project.find_by_id(board.project_id)
# if project && project.project_type == 1
# board.course_id = board.project_id
# board.project_id = -1
# board.save
# end
# end
end
end

View File

@ -2,13 +2,16 @@ class AddCourseidToEnabledModules < ActiveRecord::Migration
def change
add_column :enabled_modules, :course_id, :int
EnabledModule.all.each do |enablemodule|
project = Project.find_by_id(enablemodule.project_id)
if project && project.project_type == 1
enablemodule.course_id = enablemodule.project_id
enablemodule.project_id = nil
enablemodule.save
end
end
EnabledModule.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id")
EnabledModule.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1)
#EnabledModule.all.each do |enablemodule|
# project = Project.find_by_id(enablemodule.project_id)
# if project && project.project_type == 1
# enablemodule.course_id = enablemodule.project_id
# enablemodule.project_id = -1
# enablemodule.save
# end
#end
end
end

View File

@ -1,15 +1,21 @@
class AddCourseidToToMembers < ActiveRecord::Migration
def change
add_column :members, :course_id, :int
change_column_null(:members, :project_id, true)
remove_index :members, name: 'index_members_on_user_id_and_project_id'
add_index "members", ["user_id", "project_id","course_id"], :name => "index_members_on_user_id_and_project_id", :unique => true
Member.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all("course_id = project_id")
Member.where('project_id IN (SELECT id FROM projects WHERE project_type=1)').update_all(project_id: -1)
# 课程成员数据迁移
Member.all.each do |member|
project = Project.find_by_id(member.project_id)
if project && project.project_type == 1
member.course_id = member.project_id
member.project_id = nil
member.save
end
end
#Member.all.each do |member|
# project = Project.find_by_id(member.project_id)
# if project && project.project_type == 1
# member.course_id = member.project_id
# member.project_id = -1
# member.save
# end
#end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140603081801) do
ActiveRecord::Schema.define(:version => 20140604011630) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -57,14 +57,11 @@ ActiveRecord::Schema.define(:version => 20140603081801) do
add_index "attachments", ["container_id", "container_type"], :name => "index_attachments_on_container_id_and_container_type"
add_index "attachments", ["created_on"], :name => "index_attachments_on_created_on"
create_table "attachmentstypes", :id => false, :force => true do |t|
t.integer "id", :null => false
t.integer "typeId"
create_table "attachmentstypes", :force => true do |t|
t.integer "typeId", :null => false
t.string "typeName", :limit => 50
end
add_index "attachmentstypes", ["id"], :name => "id"
create_table "auth_sources", :force => true do |t|
t.string "type", :limit => 30, :default => "", :null => false
t.string "name", :limit => 60, :default => "", :null => false
@ -519,13 +516,14 @@ ActiveRecord::Schema.define(:version => 20140603081801) do
create_table "members", :force => true do |t|
t.integer "user_id", :default => 0, :null => false
t.integer "project_id", :default => 0, :null => false
t.integer "project_id", :default => 0
t.datetime "created_on"
t.boolean "mail_notification", :default => false, :null => false
t.integer "course_id"
end
add_index "members", ["project_id"], :name => "index_members_on_project_id"
add_index "members", ["user_id", "project_id"], :name => "index_members_on_user_id_and_project_id", :unique => true
add_index "members", ["user_id", "project_id", "course_id"], :name => "index_members_on_user_id_and_project_id", :unique => true
add_index "members", ["user_id"], :name => "index_members_on_user_id"
create_table "memos", :force => true do |t|
@ -710,7 +708,7 @@ ActiveRecord::Schema.define(:version => 20140603081801) do
end
create_table "relative_memos", :force => true do |t|
t.integer "osp_id", :null => false
t.integer "osp_id"
t.integer "parent_id"
t.string "subject", :null => false
t.text "content", :null => false