资源库的数据迁移
This commit is contained in:
parent
6b9b1fe013
commit
cf24bf1f75
|
|
@ -28,6 +28,7 @@ class Attachment < ActiveRecord::Base
|
|||
belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'"
|
||||
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
|
||||
belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id"
|
||||
belongs_to :resource_bank
|
||||
# 被ForgeActivity虚拟关联
|
||||
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
|
||||
has_many :forwards, :as => :from, :dependent => :destroy
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
class ResourceBank < ActiveRecord::Base
|
||||
belongs_to :course
|
||||
belongs_to :user
|
||||
attr_accessible :course_id, :user_id, :applicable_syllabus, :copy_from, :description, :digest, :discipline_category_id, :disk_directory, :disk_filename, :downloads, :filename, :filesize, :first_level_discipline_id, :is_public, :major_level, :quotes, :attachment_id
|
||||
end
|
||||
|
|
@ -1,43 +1,43 @@
|
|||
class HomeworkBankMigration < ActiveRecord::Migration
|
||||
def up
|
||||
# add_column :homework_commons, :homework_bank_id, :integer
|
||||
# add_column :homework_commons, :is_update, :boolean, :default => false
|
||||
#
|
||||
# count =Course.all.count / 30 + 2
|
||||
# transaction do
|
||||
# for i in 1 ... count do i
|
||||
# Course.page(i).per(30).each do |course|
|
||||
# if course.is_delete == 0
|
||||
# course.homework_commons.each do |homework|
|
||||
# unless homework.user.homework_banks.select("name").to_s.include?(homework.name)
|
||||
# homework_bank = HomeworkBank.create(:user_id => homework.user_id, :name => homework.name, :description => homework.description, :homework_type => homework.homework_type,
|
||||
# :quotes => 1, :is_public => course.is_public, :applicable_syllabus => course.syllabus.title, :homework_common_id => homework.id, :created_at => homework.created_at)
|
||||
# if homework.homework_type == 2 && homework.homework_detail_programing
|
||||
# homework_bank.update_attributes(:language => homework.homework_detail_programing.language, :standard_code => homework.homework_detail_programing.standard_code)
|
||||
# homework.homework_tests.each do |test|
|
||||
# homework_bank.homework_bank_tests << HomeworkBankTest.create(
|
||||
# input: test.input,
|
||||
# output: test.output,
|
||||
# test_type: true
|
||||
# )
|
||||
# end
|
||||
# homework.homework_samples.each do |test|
|
||||
# homework_bank.homework_bank_tests << HomeworkBankTest.create(
|
||||
# input: test.input,
|
||||
# output: test.output,
|
||||
# test_type: false
|
||||
# )
|
||||
# end
|
||||
# elsif homework.homework_type == 3 && homework.homework_detail_group
|
||||
# homework_bank.update_attributes(:min_num => homework.homework_detail_group.min_num, :max_num => homework.homework_detail_group.max_num, :base_on_project => homework.homework_detail_group.base_on_project)
|
||||
# end
|
||||
# homework.update_column('homework_bank_id', homework_bank.id)
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
add_column :homework_commons, :homework_bank_id, :integer
|
||||
add_column :homework_commons, :is_update, :boolean, :default => false
|
||||
|
||||
count =Course.all.count / 30 + 2
|
||||
transaction do
|
||||
for i in 1 ... count do i
|
||||
Course.page(i).per(30).each do |course|
|
||||
if course.is_delete == 0
|
||||
course.homework_commons.each do |homework|
|
||||
unless homework.user.homework_banks.select("name").to_s.include?(homework.name)
|
||||
homework_bank = HomeworkBank.create(:user_id => homework.user_id, :name => homework.name, :description => homework.description, :homework_type => homework.homework_type,
|
||||
:quotes => 1, :is_public => course.is_public, :applicable_syllabus => course.syllabus.title, :homework_common_id => homework.id, :created_at => homework.created_at)
|
||||
if homework.homework_type == 2 && homework.homework_detail_programing
|
||||
homework_bank.update_attributes(:language => homework.homework_detail_programing.language, :standard_code => homework.homework_detail_programing.standard_code)
|
||||
homework.homework_tests.each do |test|
|
||||
homework_bank.homework_bank_tests << HomeworkBankTest.create(
|
||||
input: test.input,
|
||||
output: test.output,
|
||||
test_type: true
|
||||
)
|
||||
end
|
||||
homework.homework_samples.each do |test|
|
||||
homework_bank.homework_bank_tests << HomeworkBankTest.create(
|
||||
input: test.input,
|
||||
output: test.output,
|
||||
test_type: false
|
||||
)
|
||||
end
|
||||
elsif homework.homework_type == 3 && homework.homework_detail_group
|
||||
homework_bank.update_attributes(:min_num => homework.homework_detail_group.min_num, :max_num => homework.homework_detail_group.max_num, :base_on_project => homework.homework_detail_group.base_on_project)
|
||||
end
|
||||
homework.update_column('homework_bank_id', homework_bank.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
class CreateResourceBanks < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :resource_banks do |t|
|
||||
t.references :course
|
||||
t.integer :attachment_id
|
||||
t.string :filename
|
||||
t.string :disk_filename
|
||||
t.integer :filesize
|
||||
t.string :digest
|
||||
t.integer :downloads
|
||||
t.references :user
|
||||
t.text :description
|
||||
t.string :disk_directory
|
||||
t.boolean :is_public
|
||||
t.integer :copy_from
|
||||
t.integer :quotes
|
||||
t.string :applicable_syllabus
|
||||
t.integer :major_level
|
||||
t.integer :discipline_category_id
|
||||
t.integer :first_level_discipline_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
add_index :resource_banks, :course_id
|
||||
add_index :resource_banks, :user_id
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
class ResourceBankMigration < ActiveRecord::Migration
|
||||
def up
|
||||
#add_column :attachments, :resource_bank_id, :integer
|
||||
|
||||
count =Attachment.where(:container_type => 'Course').count / 30 + 2
|
||||
transaction do
|
||||
for i in 1 ... count do i
|
||||
Attachment.where(:container_type => 'Course').page(i).per(30).each do |atta|
|
||||
if atta.course && atta.course.syllabus
|
||||
course = atta.course
|
||||
syllabus = course.syllabus
|
||||
resource_bank = ResourceBank.create(:course_id => course.id, :attachment_id => atta.id, :filename => atta.filename, :disk_filename => atta.disk_filename, :filesize => atta.filesize, :digest => atta.digest, :downloads => 0,
|
||||
:user_id => atta.author_id, :description => atta.description, :disk_directory => atta.disk_directory, :is_public => atta.is_public, :copy_from => atta.copy_from,
|
||||
:quotes => 1, :applicable_syllabus => syllabus.title, :major_level => syllabus.major_level, :discipline_category_id => syllabus.discipline_category_id, :first_level_discipline_id => syllabus.first_level_discipline_id, :created_at => atta.created_on)
|
||||
atta.update_column('resource_bank_id', resource_bank.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
FactoryGirl.define do
|
||||
factory :resource_bank do
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ResourceBank, :type => :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
Loading…
Reference in New Issue