# Conflicts: # db/seeds.rb # public/react/src/modules/tpm/NewHeader.js # public/react/src/modules/user/usersInfo/InfosBanner.jsdev_local_2
						commit
						cafe91bfab
					
				@ -0,0 +1,2 @@
 | 
				
			||||
// Place all the behaviors and hooks related to the matching controller here.
 | 
				
			||||
// All this logic will automatically be available in application.js.
 | 
				
			||||
@ -0,0 +1,3 @@
 | 
				
			||||
// Place all the styles related to the initialization_data controller here.
 | 
				
			||||
// They will automatically be included in application.css.
 | 
				
			||||
// You can use Sass (SCSS) here: http://sass-lang.com/
 | 
				
			||||
@ -0,0 +1,114 @@
 | 
				
			||||
class InitializationDataController < ApplicationController
 | 
				
			||||
 | 
				
			||||
  def init_subjects
 | 
				
			||||
    raise("实践课程id不能为空") if params[:paths].blank?
 | 
				
			||||
    paths = params[:paths].split(",")
 | 
				
			||||
    origin_database = EduSetting.where(name: origin_database)&.value
 | 
				
			||||
    database = EduSetting.where(name: database)&.value
 | 
				
			||||
    # 获取原始数据库导入数据
 | 
				
			||||
    get_origin_data origin_database, paths
 | 
				
			||||
    # 创建初始数据
 | 
				
			||||
    create_init_data database
 | 
				
			||||
 | 
				
			||||
 | 
				
			||||
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
 | 
				
			||||
 | 
				
			||||
  private
 | 
				
			||||
  def get_origin_data origin_database, paths
 | 
				
			||||
    connect_to_origin_date(origin_database)
 | 
				
			||||
    @subjects = get_subject_data(paths)
 | 
				
			||||
    @stages = get_stages_data(@subjects)
 | 
				
			||||
    @stage_shixuns = get_stage_shixuns_data(@stages)
 | 
				
			||||
    @shixuns = get_shixun_data(@stage_shixuns)
 | 
				
			||||
    @shixun_mirror_repositories = get_shixun_mirror_repositories_data(@shixuns)
 | 
				
			||||
    @shixun_tag_repertoires = get_shixun_tag_repertoires_data(@shixuns)
 | 
				
			||||
    @shixun_service_configs = get_shixun_service_configs_data(@shixuns)
 | 
				
			||||
    @challenges = get_challenges_data(@shixuns)
 | 
				
			||||
    @challenge_tags = get_challenge_tags_data(@challenges)
 | 
				
			||||
    @test_sets = get_test_sets_data(@challenges)
 | 
				
			||||
    @challenge_chooses = get_challenge_chooses_data(@challenges)
 | 
				
			||||
    @challenge_questions = get_challenge_questions_data(@challenge_chooses)
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  def create_init_data database
 | 
				
			||||
    connect_to_origin_date database
 | 
				
			||||
    #copy_shixuns
 | 
				
			||||
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  # 链接库
 | 
				
			||||
  def connect_to_origin_date database
 | 
				
			||||
    ActiveRecord::Base.establish_connection(
 | 
				
			||||
        adapter: "mysql2",
 | 
				
			||||
        host: "localhost",
 | 
				
			||||
        username: "root",
 | 
				
			||||
        password: "123456",
 | 
				
			||||
        database: "#{database}"
 | 
				
			||||
    )
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  # 查询需要的路径
 | 
				
			||||
  def get_subject_data paths
 | 
				
			||||
    Subject.where(id: paths)
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  # 获取实践课程的章节
 | 
				
			||||
  def get_stages_data subjects
 | 
				
			||||
    Stage.where(subject_id: subjects)
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  # 获取时间课程的关联实训表
 | 
				
			||||
  def get_stage_shixuns_data stages
 | 
				
			||||
    StageShixun.where(stage_id: stages)
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  # 获取实训数据
 | 
				
			||||
  def get_shixun_data stage_shixuns
 | 
				
			||||
    Shixun.where(id: stage_shixuns.map(&:shixun_id))
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  # 获取关卡数据
 | 
				
			||||
  def get_challenges_data shixuns
 | 
				
			||||
    Challenge.where(shixun_id: shixuns)
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  # 获取关卡标签数据
 | 
				
			||||
  def get_challenge_tags_data challenges
 | 
				
			||||
    ChallengeTag.where(challenge_id: challenges)
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  # 获取实训技能标签数据
 | 
				
			||||
  def get_shixun_mirror_repositories_data shixuns
 | 
				
			||||
    ShixunMirrorRepository.where(shixun_id: shixuns)
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  # 获取实训标签
 | 
				
			||||
  def get_shixun_tag_repertoires_data shixuns
 | 
				
			||||
    ShixunTagRepertoire.where(shixun_id: shixuns)
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  # 获取实训镜像配置
 | 
				
			||||
  def get_shixun_service_configs_data shixuns
 | 
				
			||||
    ShixunServiceConfig.where(shixun_id: shixuns)
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  # 获取测试集数据
 | 
				
			||||
  def get_test_sets_data challenges
 | 
				
			||||
    TestSet.where(challenge_id: challenges)
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  # 获取选择题题目
 | 
				
			||||
  def get_challenge_chooses_data challenges
 | 
				
			||||
    ChallengeChoose.where(challenge_id: challenges)
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  # 复制选择题选项
 | 
				
			||||
  def get_challenge_questions_data challenge_chooses
 | 
				
			||||
    ChallengeQuestion.where(challenge_choose_id: challenge_chooses)
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
 | 
				
			||||
end
 | 
				
			||||
@ -0,0 +1,2 @@
 | 
				
			||||
module InitializationDataHelper
 | 
				
			||||
end
 | 
				
			||||
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								@ -1,26 +0,0 @@
 | 
				
			||||
class CreateGraduationTopics < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    create_table :graduation_topics do |t|
 | 
				
			||||
      t.references :user
 | 
				
			||||
      t.references :course
 | 
				
			||||
      t.integer :tea_id
 | 
				
			||||
      t.string :name
 | 
				
			||||
      t.text :description
 | 
				
			||||
      t.integer :status, :default => 0
 | 
				
			||||
      t.integer :topic_type
 | 
				
			||||
      t.integer :source
 | 
				
			||||
      t.integer :property
 | 
				
			||||
      t.integer :property_two
 | 
				
			||||
      t.string :source_unit
 | 
				
			||||
      t.integer :repeat
 | 
				
			||||
      t.string :province
 | 
				
			||||
      t.string :city
 | 
				
			||||
      t.boolean :is_public, :default => 0
 | 
				
			||||
 | 
				
			||||
      t.timestamps
 | 
				
			||||
    end
 | 
				
			||||
    add_index :graduation_topics, :user_id
 | 
				
			||||
    add_index :graduation_topics, :course_id
 | 
				
			||||
    add_index :graduation_topics, :tea_id
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,6 +0,0 @@
 | 
				
			||||
class AddColumnToPoll < ActiveRecord::Migration[5.2]
 | 
				
			||||
  # 问卷是否实名
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :polls, :un_anonymous, :boolean, :default => 0
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddRepoNameToShixuns < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :shixuns, :repo_name, :string
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddRepoNameToMyshixuns < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :myshixuns, :repo_name, :string
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,13 +0,0 @@
 | 
				
			||||
class CreateRelationships < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    create_table :relationships do |t|
 | 
				
			||||
      t.integer :follower_id
 | 
				
			||||
      t.integer :followed_id
 | 
				
			||||
 | 
				
			||||
      t.timestamps
 | 
				
			||||
    end
 | 
				
			||||
    add_index :relationships, :followed_id
 | 
				
			||||
    add_index :relationships, :follower_id
 | 
				
			||||
    add_index :relationships, [:follower_id, :followed_id], unique: true
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,6 +0,0 @@
 | 
				
			||||
class SyncGitlabAdmin < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    user = User.find_by_login("forge01")
 | 
				
			||||
    user.update_column(:mail, 'admin@example.com')
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddCloudUrlToAttachments < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :attachments, :cloud_url, :string, default: ''
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddAvergeStarToShixuns < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :shixuns, :averge_star, :float, :default => 0
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,12 +0,0 @@
 | 
				
			||||
class SyncAvergerStarToShixun < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    Shixun.find_each do |shixun|
 | 
				
			||||
      averge_star = Game.find_by_sql("select ifnull(sum(g.star),0)/ifnull(count(*),1) as averge_star from (games g left join
 | 
				
			||||
                                     (myshixuns m join shixuns s on s.id = m.shixun_id) on m.id = g.myshixun_id)
 | 
				
			||||
                                     where star != 0 and s.id = #{shixun.id}").first.try(:averge_star)
 | 
				
			||||
      averge_star = averge_star || 5
 | 
				
			||||
      puts(averge_star)
 | 
				
			||||
      shixun.update_column(:averge_star, averge_star.round(1))
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,12 +0,0 @@
 | 
				
			||||
class CreateShixunInfos < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    create_table :shixun_infos do |t|
 | 
				
			||||
      t.longtext :propaedeutics
 | 
				
			||||
      t.longtext :description
 | 
				
			||||
      t.longtext :evaluate_script
 | 
				
			||||
      t.integer :shixun_id
 | 
				
			||||
 | 
				
			||||
      t.timestamps
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddIndexToUsers < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_index :users, :experience
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,6 +0,0 @@
 | 
				
			||||
class ModifyStatusAndVisitsForSubjects < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    change_column :subjects, :status, :integer, :default => 0
 | 
				
			||||
    change_column :subjects, :visits, :integer, :default => 1
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddOpeningTimeForShixuns < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :shixuns, :opening_time, :string
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class ModifyOpeningTimeForShixuns < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    change_column :shixuns, :opening_time, :datetime
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddAvergeStarDefaultForShixuns < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    change_column :shixuns, :averge_star, :float, :default => 5
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,16 +0,0 @@
 | 
				
			||||
class SyncReponame < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    g = Gitlab.client
 | 
				
			||||
    myshixuns = Myshixun.where("repo_name is null")
 | 
				
			||||
    myshixuns.find_each do |myshixun|
 | 
				
			||||
      begin
 | 
				
			||||
        puts myshixun.id
 | 
				
			||||
        repo_name = g.project(myshixun.gpid).path_with_namespace
 | 
				
			||||
        puts repo_name
 | 
				
			||||
        myshixun.update_column(:repo_name, repo_name)
 | 
				
			||||
      rescue Exception => e
 | 
				
			||||
        Rails.logger.error("e.message")
 | 
				
			||||
      end
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddShixunsCountToStage < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :stages, :shixuns_count, :integer, default: 0
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddShixunsCountToSubject < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :subjects, :shixuns_count, :integer, default: 0
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,8 +0,0 @@
 | 
				
			||||
class SyncCacheCountForSubjects < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    Subject.find_each do |s|
 | 
				
			||||
      Subject.reset_counters s.id, :shixuns
 | 
				
			||||
      Subject.reset_counters s.id, :stages
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddUsersCountToShixun < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :shixuns, :users_count, :integer, default: 0
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,7 +0,0 @@
 | 
				
			||||
class SyncUsersCountForShixun < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    Shixun.find_each do |s|
 | 
				
			||||
      Shixun.reset_counters s.id, :users_count
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,6 +0,0 @@
 | 
				
			||||
class DeleteNoneMyshixunGames < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    games = Game.where.not(myshixun_id: Myshixun.where(nil).pluck(:id))
 | 
				
			||||
    games.destroy_all
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,13 +0,0 @@
 | 
				
			||||
class CreateChallengeAnswers < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    create_table :challenge_answers do |t|
 | 
				
			||||
      t.string :name
 | 
				
			||||
      t.longtext :contents
 | 
				
			||||
      t.integer :score
 | 
				
			||||
      t.integer :level
 | 
				
			||||
      t.references :challenge, index: true
 | 
				
			||||
      t.timestamps
 | 
				
			||||
    end
 | 
				
			||||
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,19 +0,0 @@
 | 
				
			||||
class CreateCourseMembers < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    create_table :course_members do |t|
 | 
				
			||||
      t.integer :course_id
 | 
				
			||||
      t.integer :user_id
 | 
				
			||||
      t.integer :course_group_id, default: 0
 | 
				
			||||
      t.integer :graduation_group_id, default: 0
 | 
				
			||||
      t.integer :role, default: 0
 | 
				
			||||
      t.boolean :is_active, default: 1
 | 
				
			||||
 | 
				
			||||
      t.timestamps
 | 
				
			||||
    end
 | 
				
			||||
 | 
				
			||||
    add_index :course_members, :course_id
 | 
				
			||||
    add_index :course_members, :user_id
 | 
				
			||||
    add_index :course_members, :course_group_id
 | 
				
			||||
    add_index :course_members, :graduation_group_id
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class ModifyAnswerOpenForGames < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    change_column :games, :answer_open, :integer, :default => 0
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddCheckoutAnswerScoreForGames < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :games, :answer_deduction, :integer, :default => 0
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,9 +0,0 @@
 | 
				
			||||
class AddCourseMembersCountToCourse < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :courses, :course_members_count, :integer, default: 0
 | 
				
			||||
 | 
				
			||||
    Course.find_each do |c|
 | 
				
			||||
      Course.reset_counters c.id, :course_members
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,6 +0,0 @@
 | 
				
			||||
class AddScoreForTestSets < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :test_sets, :score, :integer
 | 
				
			||||
    add_column :challenges, :test_set_score, :boolean, :default => false
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,10 +0,0 @@
 | 
				
			||||
class AddAnswerForChallengeAnswer < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    challenges = Challenge.where("answer is not null")
 | 
				
			||||
    challenges.find_each do |c|
 | 
				
			||||
      puts "####################{c.id}"
 | 
				
			||||
      ChallengeAnswer.create(name: "解题代码", contents: "#{c.answer}", level: 1, score: 100, challenge_id: c.id)
 | 
				
			||||
    end
 | 
				
			||||
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddPodLifeToShixuns < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :shixuns, :pod_life, :integer, :default => 0
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,38 +0,0 @@
 | 
				
			||||
class MigrateCourseMembers < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    # add_column :course_groups, :position, :integer, default: 0
 | 
				
			||||
 | 
				
			||||
    Course.find_each do |course|
 | 
				
			||||
      position = 1
 | 
				
			||||
      course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").each do |group|
 | 
				
			||||
        group.update_attribute(:position, position)
 | 
				
			||||
        position += 1
 | 
				
			||||
      end
 | 
				
			||||
    end
 | 
				
			||||
 | 
				
			||||
 | 
				
			||||
    add_column :course_groups, :course_members_count, :integer, default: 0
 | 
				
			||||
 | 
				
			||||
    CourseGroup.find_each do |g|
 | 
				
			||||
      CourseGroup.reset_counters g.id, :course_members
 | 
				
			||||
    end
 | 
				
			||||
 | 
				
			||||
    ActiveRecord::Base.transaction do
 | 
				
			||||
      begin
 | 
				
			||||
        Member.where("course_id != -1").includes(:member_roles).find_each(batch_size: 500) do |member|
 | 
				
			||||
          puts(member.id)
 | 
				
			||||
          member.member_roles.each do |role|
 | 
				
			||||
            course_member_role = role.role_id == 3 ? 1 : (role.role_id == 9 ? 2 : (role.role_id == 7 ? 3 : 4))
 | 
				
			||||
            member_group_id = role.role_id == 10 ? member.course_group_id : 0
 | 
				
			||||
            CourseMember.create!(course_id: member.course_id, user_id: member.user_id, course_group_id: member_group_id,
 | 
				
			||||
                                 graduation_group_id: member.graduation_group_id, role: course_member_role, is_active: role.is_current)
 | 
				
			||||
          end
 | 
				
			||||
        end
 | 
				
			||||
      rescue Exception => e
 | 
				
			||||
        uid_logger_error(e.message)
 | 
				
			||||
        tip_exception("migrate_course_members 迁移失败!")
 | 
				
			||||
        raise ActiveRecord::Rollback
 | 
				
			||||
      end
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,21 +0,0 @@
 | 
				
			||||
class AddCourseMemberId < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :student_graduation_topics, :course_member_id, :integer
 | 
				
			||||
    add_index :student_graduation_topics, :course_member_id
 | 
				
			||||
 | 
				
			||||
    StudentGraduationTopic.find_each do |student|
 | 
				
			||||
      course_member = CourseMember.where(course_id: student.course_id, user_id: student.user_id,
 | 
				
			||||
      role: 4).first
 | 
				
			||||
      student.update_column("course_member_id", course_member.try(:id)) if course_member.present?
 | 
				
			||||
    end
 | 
				
			||||
 | 
				
			||||
    add_column :teacher_course_groups, :course_member_id, :integer
 | 
				
			||||
    add_index :teacher_course_groups, :course_member_id
 | 
				
			||||
 | 
				
			||||
    TeacherCourseGroup.find_each do |teacher|
 | 
				
			||||
      course_member = CourseMember.where(course_id: teacher.course_id, user_id: teacher.user_id,
 | 
				
			||||
                                         role: [1, 2, 3]).first
 | 
				
			||||
      teacher.update_column("course_member_id", course_member.try(:id)) if course_member.present?
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,9 +0,0 @@
 | 
				
			||||
class AddCourseGroupsCountToCourse < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :courses, :course_groups_count, :integer, default: 0
 | 
				
			||||
 | 
				
			||||
    Course.find_each do |c|
 | 
				
			||||
      Course.reset_counters c.id, :course_groups
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddPositionToCourseGroups < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,12 +0,0 @@
 | 
				
			||||
class CreateCourseSecondCategories < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    create_table :course_second_categories do |t|
 | 
				
			||||
      t.references :course
 | 
				
			||||
      t.string :category_type
 | 
				
			||||
      t.string :name
 | 
				
			||||
      t.integer :position
 | 
				
			||||
 | 
				
			||||
      t.timestamps
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,19 +0,0 @@
 | 
				
			||||
class MigrateCourseSecondCategory < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :homework_commons, :course_second_category_id, :integer, default: 0
 | 
				
			||||
    add_index :homework_commons, :course_second_category_id
 | 
				
			||||
    add_column :course_second_categories, :course_module_id, :integer
 | 
				
			||||
    add_index :course_second_categories, :course_module_id
 | 
				
			||||
 | 
				
			||||
    Course.find_each do |course|
 | 
				
			||||
      homework_position = 1
 | 
				
			||||
      course_module = course.course_modules.where(module_type: "shixun_homework").first
 | 
				
			||||
      course.course_homework_categories.reorder("CONVERT(name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |category|
 | 
				
			||||
        new_category = CourseSecondCategory.create!(course_id: course.id, name: category.name, category_type: "shixun_homework",
 | 
				
			||||
                                                    position: homework_position, course_module_id: course_module.id)
 | 
				
			||||
        course.homework_commons.where(course_homework_category_id: category.id).update_all(course_second_category_id: new_category.id)
 | 
				
			||||
        homework_position += 1
 | 
				
			||||
      end
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,6 +0,0 @@
 | 
				
			||||
class AddCourseSecondCategoryToAttachment < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :attachments, :course_second_category_id, :integer, default: 0
 | 
				
			||||
    add_index :attachments, :course_second_category_id
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,11 +0,0 @@
 | 
				
			||||
class AddPraisesCountToMessages < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :messages, :praises_count, :integer, :default => 0
 | 
				
			||||
 | 
				
			||||
    Message.find_each do |msg|
 | 
				
			||||
      total_count = msg.praise_treads.liker.count
 | 
				
			||||
      puts "====> set message's praises_count to #{total_count}"
 | 
				
			||||
      msg.update_column(:praises_count, total_count)
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class ChangePraiseOrTreadDefaultInPraiseTreads < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    change_column_default :praise_treads, :praise_or_tread, from: nil, to: 1
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,11 +0,0 @@
 | 
				
			||||
class CreateMessageDetails < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    create_table :message_details do |t|
 | 
				
			||||
      t.longtext :content
 | 
				
			||||
      t.integer :message_id
 | 
				
			||||
 | 
				
			||||
      t.timestamps
 | 
				
			||||
    end
 | 
				
			||||
    add_index :message_details, :message_id
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,10 +0,0 @@
 | 
				
			||||
class MoveContentOfMessagesToMessageDetails < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    Message.find_each do |msg|
 | 
				
			||||
      unless msg.message_detail.present?
 | 
				
			||||
        message_detail = MessageDetail.create(message: msg, content: msg.content)
 | 
				
			||||
        puts "-------> create MessageDetail success: id is #{message_detail.id}"
 | 
				
			||||
      end
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class RemoveContentFromMessages < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    remove_column :messages, :content, :longtext
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,8 +0,0 @@
 | 
				
			||||
class ModifyGraduationTopics < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    rename_column :graduation_topics, :source, :topic_source
 | 
				
			||||
    rename_column :graduation_topics, :property, :topic_property_first
 | 
				
			||||
    rename_column :graduation_topics, :property_two, :topic_property_second
 | 
				
			||||
    rename_column :graduation_topics, :repeat, :topic_repeat
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,8 +0,0 @@
 | 
				
			||||
class AddIsPublicToGraduationTask < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :graduation_tasks, :is_public, :boolean, default: false
 | 
				
			||||
    add_column :graduation_tasks, :late_time, :datetime
 | 
				
			||||
 | 
				
			||||
    GraduationTask.where(status: 3).update_all(status: 4)
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class ChangeDigestToStringInAttachments < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    change_column :attachments, :digest, :string, :limit => 60
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddHiddenForJournalForMessages < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :journals_for_messages, :hidden, :boolean, :default => false
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,6 +0,0 @@
 | 
				
			||||
class AddIsHiddenToMessages < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :messages, :is_hidden, :boolean, :default => false
 | 
				
			||||
    add_index :messages, :is_hidden
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class CourseGroupCountCache < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddIndexToShixunInfos < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_index :shixun_infos, :shixun_id, unique: true
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,6 +0,0 @@
 | 
				
			||||
class ChangeQuotesToIntegerInAttachments < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    change_column :attachments, :quotes, :integer, :default => 0
 | 
				
			||||
    add_index :attachments, :quotes
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddIndexToAttachmentsIsPublic < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_index :attachments, :is_public
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddInvalidToGraduationWorkScore < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :graduation_work_scores, :is_invalid, :boolean, default: false
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,40 +0,0 @@
 | 
				
			||||
# This migration comes from acts_as_taggable_on_engine (originally 1)
 | 
				
			||||
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
 | 
				
			||||
  class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]; end
 | 
				
			||||
else
 | 
				
			||||
  class ActsAsTaggableOnMigration < ActiveRecord::Migration; end
 | 
				
			||||
end
 | 
				
			||||
ActsAsTaggableOnMigration.class_eval do
 | 
				
			||||
  def self.up
 | 
				
			||||
    unless ActiveRecord::Base.connection.table_exists? 'tags'
 | 
				
			||||
      create_table :tags do |t|
 | 
				
			||||
        t.string :name
 | 
				
			||||
      end
 | 
				
			||||
    end
 | 
				
			||||
 | 
				
			||||
    unless ActiveRecord::Base.connection.table_exists? 'taggings'
 | 
				
			||||
      create_table :taggings do |t|
 | 
				
			||||
        t.references :tag
 | 
				
			||||
 | 
				
			||||
        # You should make sure that the column created is
 | 
				
			||||
        # long enough to store the required class names.
 | 
				
			||||
        t.references :taggable, polymorphic: true
 | 
				
			||||
        t.references :tagger, polymorphic: true
 | 
				
			||||
 | 
				
			||||
        # Limit is created to prevent MySQL error on index
 | 
				
			||||
        # length for MyISAM table type: http://bit.ly/vgW2Ql
 | 
				
			||||
        t.string :context, limit: 128
 | 
				
			||||
 | 
				
			||||
        t.datetime :created_at
 | 
				
			||||
      end
 | 
				
			||||
    end
 | 
				
			||||
 | 
				
			||||
    # add_index :taggings, :tag_id
 | 
				
			||||
    # add_index :taggings, [:taggable_id, :taggable_type, :context]
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  def self.down
 | 
				
			||||
    drop_table :taggings
 | 
				
			||||
    drop_table :tags
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,26 +0,0 @@
 | 
				
			||||
# This migration comes from acts_as_taggable_on_engine (originally 2)
 | 
				
			||||
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
 | 
				
			||||
  class AddMissingUniqueIndices < ActiveRecord::Migration[4.2]; end
 | 
				
			||||
else
 | 
				
			||||
  class AddMissingUniqueIndices < ActiveRecord::Migration; end
 | 
				
			||||
end
 | 
				
			||||
AddMissingUniqueIndices.class_eval do
 | 
				
			||||
  def self.up
 | 
				
			||||
    # add_index :tags, :name, unique: true
 | 
				
			||||
 | 
				
			||||
    remove_index :taggings, :tag_id if index_exists?(:taggings, :tag_id)
 | 
				
			||||
    remove_index :taggings, [:taggable_id, :taggable_type, :context]
 | 
				
			||||
    add_index :taggings,
 | 
				
			||||
              [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type],
 | 
				
			||||
              unique: true, name: 'taggings_idx'
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  def self.down
 | 
				
			||||
    remove_index :tags, :name
 | 
				
			||||
 | 
				
			||||
    remove_index :taggings, name: 'taggings_idx'
 | 
				
			||||
 | 
				
			||||
    add_index :taggings, :tag_id unless index_exists?(:taggings, :tag_id)
 | 
				
			||||
    add_index :taggings, [:taggable_id, :taggable_type, :context]
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,20 +0,0 @@
 | 
				
			||||
# This migration comes from acts_as_taggable_on_engine (originally 3)
 | 
				
			||||
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
 | 
				
			||||
  class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[4.2]; end
 | 
				
			||||
else
 | 
				
			||||
  class AddTaggingsCounterCacheToTags < ActiveRecord::Migration; end
 | 
				
			||||
end
 | 
				
			||||
AddTaggingsCounterCacheToTags.class_eval do
 | 
				
			||||
  def self.up
 | 
				
			||||
    add_column :tags, :taggings_count, :integer, default: 0
 | 
				
			||||
 | 
				
			||||
    ActsAsTaggableOn::Tag.reset_column_information
 | 
				
			||||
    ActsAsTaggableOn::Tag.find_each do |tag|
 | 
				
			||||
      ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings)
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  def self.down
 | 
				
			||||
    remove_column :tags, :taggings_count
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,15 +0,0 @@
 | 
				
			||||
# This migration comes from acts_as_taggable_on_engine (originally 4)
 | 
				
			||||
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
 | 
				
			||||
  class AddMissingTaggableIndex < ActiveRecord::Migration[4.2]; end
 | 
				
			||||
else
 | 
				
			||||
  class AddMissingTaggableIndex < ActiveRecord::Migration; end
 | 
				
			||||
end
 | 
				
			||||
AddMissingTaggableIndex.class_eval do
 | 
				
			||||
  def self.up
 | 
				
			||||
    add_index :taggings, [:taggable_id, :taggable_type, :context]
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  def self.down
 | 
				
			||||
    remove_index :taggings, [:taggable_id, :taggable_type, :context]
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,15 +0,0 @@
 | 
				
			||||
# This migration comes from acts_as_taggable_on_engine (originally 5)
 | 
				
			||||
# This migration is added to circumvent issue #623 and have special characters
 | 
				
			||||
# work properly
 | 
				
			||||
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
 | 
				
			||||
  class ChangeCollationForTagNames < ActiveRecord::Migration[4.2]; end
 | 
				
			||||
else
 | 
				
			||||
  class ChangeCollationForTagNames < ActiveRecord::Migration; end
 | 
				
			||||
end
 | 
				
			||||
ChangeCollationForTagNames.class_eval do
 | 
				
			||||
  def up
 | 
				
			||||
    if ActsAsTaggableOn::Utils.using_mysql?
 | 
				
			||||
      execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,23 +0,0 @@
 | 
				
			||||
# This migration comes from acts_as_taggable_on_engine (originally 6)
 | 
				
			||||
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
 | 
				
			||||
  class AddMissingIndexesOnTaggings < ActiveRecord::Migration[4.2]; end
 | 
				
			||||
else
 | 
				
			||||
  class AddMissingIndexesOnTaggings < ActiveRecord::Migration; end
 | 
				
			||||
end
 | 
				
			||||
AddMissingIndexesOnTaggings.class_eval do
 | 
				
			||||
  def change
 | 
				
			||||
    add_index :taggings, :tag_id unless index_exists? :taggings, :tag_id
 | 
				
			||||
    add_index :taggings, :taggable_id unless index_exists? :taggings, :taggable_id
 | 
				
			||||
    add_index :taggings, :taggable_type unless index_exists? :taggings, :taggable_type
 | 
				
			||||
    add_index :taggings, :tagger_id unless index_exists? :taggings, :tagger_id
 | 
				
			||||
    add_index :taggings, :context unless index_exists? :taggings, :context
 | 
				
			||||
 | 
				
			||||
    unless index_exists? :taggings, [:tagger_id, :tagger_type]
 | 
				
			||||
      add_index :taggings, [:tagger_id, :tagger_type]
 | 
				
			||||
    end
 | 
				
			||||
 | 
				
			||||
    unless index_exists? :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy'
 | 
				
			||||
      add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy'
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,19 +0,0 @@
 | 
				
			||||
class CreateGtaskBanks < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    create_table :gtask_banks do |t|
 | 
				
			||||
      t.references :user
 | 
				
			||||
      t.string :name
 | 
				
			||||
      t.text :description
 | 
				
			||||
      t.integer :task_type
 | 
				
			||||
      t.integer :min_num, default: 0
 | 
				
			||||
      t.integer :max_num, default: 0
 | 
				
			||||
      t.integer :base_on_project, default: false
 | 
				
			||||
      t.boolean :is_public, default: false
 | 
				
			||||
      t.integer :quotes, default: 0
 | 
				
			||||
      t.references :graduation_task
 | 
				
			||||
      t.references :course_list
 | 
				
			||||
 | 
				
			||||
      t.timestamps
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,13 +0,0 @@
 | 
				
			||||
class AddPraisesCountForJouranlsForMessages < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :journals_for_messages, :praises_count, :integer, :default => 0
 | 
				
			||||
 | 
				
			||||
    messages = JournalsForMessage.includes(:praise_treads).all
 | 
				
			||||
    messages.find_each do |m|
 | 
				
			||||
      puts("####{m.id}")
 | 
				
			||||
      praises_count = m.praise_treads.liker.count
 | 
				
			||||
      m.update_column(:praises_count, praises_count)
 | 
				
			||||
    end
 | 
				
			||||
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,23 +0,0 @@
 | 
				
			||||
class CreateGtopicBanks < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    create_table :gtopic_banks do |t|
 | 
				
			||||
      t.references :user
 | 
				
			||||
      t.string :name
 | 
				
			||||
      t.text :description
 | 
				
			||||
      t.integer :quotes
 | 
				
			||||
      t.boolean :is_public
 | 
				
			||||
      t.integer :topic_type
 | 
				
			||||
      t.integer :topic_source
 | 
				
			||||
      t.integer :topic_property_first
 | 
				
			||||
      t.integer :topic_property_second
 | 
				
			||||
      t.string :source_unit
 | 
				
			||||
      t.integer :topic_repeat
 | 
				
			||||
      t.string :province
 | 
				
			||||
      t.string :city
 | 
				
			||||
      t.references :graduation_topic
 | 
				
			||||
      t.references :course_list
 | 
				
			||||
 | 
				
			||||
      t.timestamps
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,6 +0,0 @@
 | 
				
			||||
class AddIsOrderedToExerciseStandardAnswers < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    #试题的多空标准答案是否为一一对应,默认为一一对应,即true
 | 
				
			||||
    add_column :exercise_standard_answers,:is_ordered,:boolean,:default => true
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,12 +0,0 @@
 | 
				
			||||
class ChangeColumnInHomeworks < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    change_column_default :homework_commons, :late_penalty, from: nil, to: 5
 | 
				
			||||
    change_column_default :homework_commons, :anonymous_comment, from: 0, to: 1
 | 
				
			||||
    change_column_default :homework_commons, :work_efficiency, from: 1, to: 0
 | 
				
			||||
    change_column_default :homework_commons, :eff_score, from: 20, to: 0
 | 
				
			||||
    change_column_default :homework_detail_manuals, :ta_proportion, from: nil, to: 0
 | 
				
			||||
    change_column_default :homework_detail_manuals, :comment_status, from: nil, to: 0
 | 
				
			||||
    change_column_default :homework_detail_manuals, :evaluation_num, from: nil, to: 0
 | 
				
			||||
    change_column_default :homework_detail_manuals, :absence_penalty, from: 1, to: 0
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,6 +0,0 @@
 | 
				
			||||
class ChangeIsOrderedFromAnswerToQuestion < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    remove_column :exercise_standard_answers,:is_ordered
 | 
				
			||||
    add_column :exercise_questions,:is_ordered,:boolean,:default => true
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class MigrateHomeworkAttachments < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    Attachment.where(container_type: "HomeworkCommon").update_all(attachtype: 1)
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddCloudUrlToAttachmentHistories < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :attachment_histories, :cloud_url, :string, default: ''
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,13 +0,0 @@
 | 
				
			||||
class ChangeHomeworkCommonColumns < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def up
 | 
				
			||||
    change_column :homework_commons, :score_open, :boolean, default: 1
 | 
				
			||||
    change_column :homework_commons, :anonymous_comment, :boolean, default: 1
 | 
				
			||||
    change_column :homework_commons, :anonymous_appeal, :boolean, default: 0
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  def down
 | 
				
			||||
    change_column :homework_commons, :score_open, :int, default: 1
 | 
				
			||||
    change_column :homework_commons, :anonymous_comment, :int, default: 1
 | 
				
			||||
    change_column :homework_commons, :anonymous_appeal, :int, default: 0
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,21 +0,0 @@
 | 
				
			||||
class MigrateHomeworkLateTime < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    homeworks = HomeworkCommon.where.not(end_time: nil).where(homework_type: [1, 3 ,4], allow_late: 1, late_time: nil)
 | 
				
			||||
    homeworks.each do |homework|
 | 
				
			||||
      if homework.course.try(:end_date).present?
 | 
				
			||||
        homework.update_column("late_time", homework.course.end_date)
 | 
				
			||||
      elsif homework.end_time.present?
 | 
				
			||||
        homework.update_column("late_time", Time.at(homework.end_time.to_i + 30*24*3600))
 | 
				
			||||
      end
 | 
				
			||||
    end
 | 
				
			||||
 | 
				
			||||
    tasks = GraduationTask.where.not(end_time: nil).where(allow_late: 1, late_time: nil)
 | 
				
			||||
    tasks.each do |task|
 | 
				
			||||
      if task.course.try(:end_date).present?
 | 
				
			||||
        task.update_column("late_time", task.course.end_date)
 | 
				
			||||
      elsif task.end_time.present?
 | 
				
			||||
        task.update_column("late_time", Time.at(task.end_time.to_i + 30*24*3600))
 | 
				
			||||
      end
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,18 +0,0 @@
 | 
				
			||||
class AddJournalsForMessagesCountForHmAndGtAndGw < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    #add_column :homework_commons, :journals_for_messages_count, :integer, :default => 0
 | 
				
			||||
    #add_column :graduation_tasks, :journals_for_messages_count, :integer, :default => 0
 | 
				
			||||
    #add_column :graduation_topics, :journals_for_messages_count, :integer, :default => 0
 | 
				
			||||
 | 
				
			||||
    type = ["GraduationTopic", "GraduationTask", "HomeworkCommon"]
 | 
				
			||||
    messages = JournalsForMessage.where(jour_type: type).where("m_parent_id is not null")
 | 
				
			||||
    # 迁移所有2级以上的回复
 | 
				
			||||
    messages.each do |message|
 | 
				
			||||
      while message.parent.try(:m_parent_id).present? do
 | 
				
			||||
        puts "parent: #{message.parent.try(:m_parent_id)}"
 | 
				
			||||
        message.update_attribute(:m_parent_id, message.parent.m_parent_id)
 | 
				
			||||
      end
 | 
				
			||||
    end
 | 
				
			||||
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,7 +0,0 @@
 | 
				
			||||
class MigrateHomeworkAnonymousComment < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    change_column_default :homework_commons, :anonymous_comment, from: 1, to: 0
 | 
				
			||||
 | 
				
			||||
    HomeworkCommon.update_all("anonymous_comment = !anonymous_comment")
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,25 +0,0 @@
 | 
				
			||||
class AddIsInvalidToStudentWorksScores < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    # add_column :student_works_scores, :is_invalid, :boolean, default: false
 | 
				
			||||
 | 
				
			||||
    StudentWorksScore.where("score is not null").order("id desc").find_each do |score|
 | 
				
			||||
      unless score.is_invalid
 | 
				
			||||
        if score.student_work.present?
 | 
				
			||||
          puts score.id
 | 
				
			||||
          work = score.student_work
 | 
				
			||||
 | 
				
			||||
          # 如果分数是调整分 则之前的所有分都无效
 | 
				
			||||
          if score.is_ultimate
 | 
				
			||||
            work.student_works_scores.where("score is not null and id < #{score.id}").update_all(is_invalid: 1)
 | 
				
			||||
 | 
				
			||||
            # 如果是同一个用户角色的重复评分,则之前的评分都无效
 | 
				
			||||
          elsif work.student_works_scores.where("user_id = #{score.user_id} and reviewer_role = #{score.reviewer_role}
 | 
				
			||||
                                                  and score is not null and id < #{score.id}").count > 0
 | 
				
			||||
            work.student_works_scores.where("user_id = #{score.user_id} and reviewer_role = #{score.reviewer_role}
 | 
				
			||||
                                             and score is not null and id < #{score.id}").update_all(is_invalid: 1)
 | 
				
			||||
          end
 | 
				
			||||
        end
 | 
				
			||||
      end
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,29 +0,0 @@
 | 
				
			||||
class ChangeExerciseScoreToFloat < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def up
 | 
				
			||||
    change_column :exercise_users,:score,:decimal,precision: 10, scale: 1
 | 
				
			||||
    change_column :exercise_users, :objective_score, :decimal,precision: 10, scale: 1,default: 0.0
 | 
				
			||||
    # change_column :exercise_users, :subjective_score, :decimal,precision: 10, scale: 1,default: 0.0
 | 
				
			||||
    change_column :exercise_users, :subjective_score, :decimal,precision: 10, scale: 1,default: -1.0
 | 
				
			||||
    # change_column :exercise_answers,:score,:decimal,precision: 10, scale: 1,default: 0.0
 | 
				
			||||
    change_column :exercise_answers,:score,:decimal,precision: 10, scale: 1,default: -1.0    #6.10修改,方便判断主观题是否批阅
 | 
				
			||||
    change_column :exercise_bank_questions,:question_score,:decimal,precision: 10, scale: 1
 | 
				
			||||
    change_column :exercise_bank_shixun_challenges,:question_score,:decimal,precision: 10, scale: 1
 | 
				
			||||
    change_column :exercise_questions,:question_score,:decimal,precision: 10, scale: 1
 | 
				
			||||
    change_column :exercise_shixun_answers,:score,:decimal,precision: 10, scale: 1
 | 
				
			||||
    change_column :exercise_shixun_challenges,:question_score,:decimal,precision: 10, scale: 1
 | 
				
			||||
    change_column :exercise_answer_comments, :score,:decimal,precision: 10, scale: 1
 | 
				
			||||
  end
 | 
				
			||||
 | 
				
			||||
  def down
 | 
				
			||||
    change_column :exercise_users,:score,:integer
 | 
				
			||||
    change_column :exercise_users, :objective_score, :integer,default: -1
 | 
				
			||||
    change_column :exercise_users, :subjective_score, :integer,default: -1
 | 
				
			||||
    change_column :exercise_answers,:score,:integer,default: -1
 | 
				
			||||
    change_column :exercise_bank_questions,:question_score,:integer
 | 
				
			||||
    change_column :exercise_shixun_answers,:score,:integer
 | 
				
			||||
    change_column :exercise_bank_shixun_challenges,:question_score,:integer
 | 
				
			||||
    change_column :exercise_questions,:question_score,:integer
 | 
				
			||||
    change_column :exercise_shixun_challenges,:question_score,:integer
 | 
				
			||||
    change_column :exercise_answer_comments, :score,:integer
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class ChangeDigestToStringInAttachmentHistories < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    change_column :attachment_histories, :digest, :string, :limit => 60
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,7 +0,0 @@
 | 
				
			||||
class AddDefaultForExercises < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    change_column :exercises, :exercise_status, :integer, :default => 1
 | 
				
			||||
    change_column :exercises, :show_result, :integer, :default => 1
 | 
				
			||||
    change_column :exercises, :time, :integer, :default => -1
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddQuotesForGraduationTopics < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :graduation_topics, :quotes, :integer, :default => 0
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddDefaultForPolls < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    change_column :polls, :polls_status, :integer, :default => 1
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,8 +0,0 @@
 | 
				
			||||
class SyncUsersIndex < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    remove_index :users, name: :index_users_on_phone_and_mail
 | 
				
			||||
    remove_index :users, name: :index_users_on_id_and_type
 | 
				
			||||
    remove_index :users, name: :index_users_on_auth_source_id
 | 
				
			||||
    remove_index :users, name: :index_users_on_type
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class RemoveIndexFromUsers < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    remove_index :users, name: :index_users_on_experience
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,9 +0,0 @@
 | 
				
			||||
class InitUseIndex < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    remove_index :users, name: :index_users_on_login if index_exists?(:users, :login, name: :index_users_on_login)
 | 
				
			||||
    remove_index :users, name: :index_users_on_mail if index_exists?(:users, :mail, name: :index_users_on_mail)
 | 
				
			||||
    # add_index :users, :login, unique: true
 | 
				
			||||
    # add_index :users, :mail, unique: true
 | 
				
			||||
    # add_index :users, :phone, unique: true
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,6 +0,0 @@
 | 
				
			||||
class AddAuthenticationAndProfessionalCertificationToCourses < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :courses, :authentication, :boolean, default: false
 | 
				
			||||
    add_column :courses, :professional_certification, :boolean, default: false
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,6 +0,0 @@
 | 
				
			||||
class MigrateNewStudentWorkStatus < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    homeworks = HomeworkCommon.where(allow_late: 0)
 | 
				
			||||
    StudentWork.where(homework_common_id: homeworks, work_status: 2).update_all(work_status: 1)
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddIsPublicToMessages < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :messages, :is_public, :boolean, :default => false
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,10 +0,0 @@
 | 
				
			||||
class AddColumnToZipPacks < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :zip_packs, :container_id, :integer, default: 0
 | 
				
			||||
    add_column :zip_packs, :container_type, :string
 | 
				
			||||
 | 
				
			||||
    add_index :zip_packs, [:container_id, :container_type]
 | 
				
			||||
 | 
				
			||||
    ZipPack.all.update_all("container_type='HomeworkCommon', container_id = homework_id")
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,11 +0,0 @@
 | 
				
			||||
class ChangeQuestionRandomExercises < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def up
 | 
				
			||||
    change_column :exercises,:question_random,:boolean,default: false
 | 
				
			||||
    change_column :exercises,:choice_random,:boolean,default: false
 | 
				
			||||
 | 
				
			||||
  end
 | 
				
			||||
  def down
 | 
				
			||||
    change_column :exercises,:question_random,:integer,default: 0
 | 
				
			||||
    change_column :exercises,:choice_random,:integer,default: 0
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,10 +0,0 @@
 | 
				
			||||
class ChangePollShowResultBoolean < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    def up
 | 
				
			||||
      change_column :polls,:show_result,:boolean,default: true
 | 
				
			||||
    end
 | 
				
			||||
    def down
 | 
				
			||||
      change_column :polls,:show_result,:integer,default: 1
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,5 +0,0 @@
 | 
				
			||||
class AddTestSetAverageForChallenges < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :challenges, :test_set_average, :boolean, :default => true
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,10 +0,0 @@
 | 
				
			||||
class CreateEduSettings < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    create_table :edu_settings do |t|
 | 
				
			||||
      t.string :name
 | 
				
			||||
      t.string :value
 | 
				
			||||
 | 
				
			||||
      t.timestamps
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,14 +0,0 @@
 | 
				
			||||
class AddDescriptionToEduSettings < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_column :edu_settings, :description, :string
 | 
				
			||||
    add_index :edu_settings, :name, unique: :true
 | 
				
			||||
 | 
				
			||||
    ['tomcat_webssh', 'webssh_username', 'webssh_password', 'git_address_ip', 'git_address_domain', 'git_username',
 | 
				
			||||
    'git_password', 'public_key', 'private_key', 'public_bucket', 'public_bucket_host', 'public_cdn_host', 'cloud_bridge',
 | 
				
			||||
    'cloud_tomcat_php', 'host_name', 'old_edu_host'].each do |name|
 | 
				
			||||
      if EduSetting.find_by_name(name).nil?
 | 
				
			||||
        EduSetting.create(name: name)
 | 
				
			||||
      end
 | 
				
			||||
    end
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,6 +0,0 @@
 | 
				
			||||
class AddIndexToVerificatiojnCodes < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
    add_index :verification_codes, [:phone], name: 'by_phone' if !index_exists?(:verification_codes, :phone)
 | 
				
			||||
    add_index :verification_codes, [:email], name: 'by_email' if !index_exists?(:verification_codes, :email)
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
@ -1,70 +0,0 @@
 | 
				
			||||
class AlterEducoderIndexs < ActiveRecord::Migration[5.2]
 | 
				
			||||
  def change
 | 
				
			||||
 | 
				
			||||
    add_index :onclick_times, :user_id if !index_exists?(:onclick_times, :user_id)
 | 
				
			||||
    remove_index :courses, :syllabus_id
 | 
				
			||||
    add_index :courses, :tea_id
 | 
				
			||||
    add_index :course_modules, [:course_id, :module_type]
 | 
				
			||||
    remove_index :homework_commons, :course_homework_category_id
 | 
				
			||||
    add_index :exercises, :course_id
 | 
				
			||||
    remove_index :teacher_course_groups, :member_id
 | 
				
			||||
    remove_index :student_works, :created_at
 | 
				
			||||
    remove_index :student_works, :user_id
 | 
				
			||||
    remove_index :student_works, :myshixun_id
 | 
				
			||||
    remove_index :homework_challenge_settings, :shixun_id
 | 
				
			||||
    remove_index :exercise_users, :exercise_id
 | 
				
			||||
    add_index :exercise_users, [:exercise_id, :user_id]
 | 
				
			||||
    add_index :homework_banks, :user_id
 | 
				
			||||
    remove_index :exercise_answers, :exercise_choice_id
 | 
				
			||||
    remove_index :exercise_answers, :exercise_question_id
 | 
				
			||||
    add_index :exercise_answers, [:exercise_question_id, :user_id]
 | 
				
			||||
    remove_index :exercise_shixun_challenges, :shixun_id
 | 
				
			||||
    remove_index :exercise_shixun_answers, :exercise_shixun_challenge_id
 | 
				
			||||
    remove_index :exercise_shixun_answers, :exercise_question_id
 | 
				
			||||
    add_index :exercise_shixun_answers, [:exercise_question_id, :user_id], name: "exercise_question_id_user_id"
 | 
				
			||||
    remove_index :student_works_evaluation_distributions, :student_work_id
 | 
				
			||||
    add_index :student_works_evaluation_distributions, :user_id
 | 
				
			||||
    remove_index :challenge_work_scores, :user_id
 | 
				
			||||
    add_index :poll_questions, :poll_id
 | 
				
			||||
    add_index :poll_users, [:poll_id, :user_id]
 | 
				
			||||
    add_index :poll_answers, :poll_question_id
 | 
				
			||||
    add_index :poll_votes, [:poll_question_id, :user_id], name: "poll_question_id_user_id"
 | 
				
			||||
    remove_index :graduation_tasks, :user_id
 | 
				
			||||
    remove_index :graduation_work_comment_assignations, :graduation_group_id
 | 
				
			||||
    remove_index :graduation_works, :course_id
 | 
				
			||||
    remove_index :graduation_works, :project_id
 | 
				
			||||
    remove_index :graduation_works, :graduation_task_id
 | 
				
			||||
    remove_index :graduation_works, :user_id
 | 
				
			||||
    add_index :graduation_works, [:graduation_task_id, :user_id], name: "graduation_task_id_user_id"
 | 
				
			||||
 | 
				
			||||
    remove_index :graduation_work_scores, :graduation_task_id
 | 
				
			||||
    remove_index :graduation_topics, :user_id
 | 
				
			||||
    remove_index :graduation_topics, :tea_id
 | 
				
			||||
    remove_index :student_graduation_topics, :member_id
 | 
				
			||||
    remove_index :student_graduation_topics, :course_member_id
 | 
				
			||||
    add_index :boards, :course_id
 | 
				
			||||
    remove_index :messages, :author_id
 | 
				
			||||
    remove_index :messages, :is_hidden
 | 
				
			||||
    remove_index :messages, :root_id
 | 
				
			||||
    remove_index :messages, :created_on
 | 
				
			||||
    remove_index :attachments, :quotes
 | 
				
			||||
    remove_index :attachments, :is_public
 | 
				
			||||
    remove_index :attachments, :course_second_category_id
 | 
				
			||||
    remove_index :course_members, :graduation_group_id
 | 
				
			||||
    add_index :student_works_scores_appeals, :student_works_score_id
 | 
				
			||||
    add_index :challenges, :shixun_id
 | 
				
			||||
    add_index :challenge_chooses, :challenge_id
 | 
				
			||||
    add_index :challenge_questions, :challenge_choose_id
 | 
				
			||||
    add_index :challenge_tags, :challenge_id
 | 
				
			||||
    remove_index :games, :user_id
 | 
				
			||||
    add_index :shixun_members, :shixun_id
 | 
				
			||||
    add_index :shixun_tag_repertoires, [:shixun_id, :tag_repertoire_id], name: "shixun_id_tag_repertoire_id"
 | 
				
			||||
    add_index :shixun_schools, :shixun_id
 | 
				
			||||
    add_index :shixun_mirror_repositories, :shixun_id
 | 
				
			||||
    add_index :shixun_modifies, [:shixun_id, :myshixun_id], name: "shixun_id_myshixun_id"
 | 
				
			||||
    remove_index :myshixuns, :user_id
 | 
				
			||||
    remove_index :outputs, :created_at
 | 
				
			||||
    remove_index :outputs, :test_set_position
 | 
				
			||||
    remove_index :stages, :user_id
 | 
				
			||||
  end
 | 
				
			||||
end
 | 
				
			||||
Some files were not shown because too many files have changed in this diff Show More
					Loading…
					
					
				
		Reference in new issue