Merge branch 'forge' of https://bdgit.educoder.net/Hjqreturn/educoder into forge
commit
0fe8effe4b
@ -0,0 +1,41 @@
|
||||
class WatchersController < ApplicationController
|
||||
before_action :require_login, except: %i[index]
|
||||
before_action :set_project
|
||||
|
||||
def index
|
||||
scope = @project.watchers.includes(:user)
|
||||
@watchers = paginate(scope)
|
||||
end
|
||||
|
||||
def unfollow
|
||||
begin
|
||||
return normal_status(2, "你还没有关注哦") unless current_user.watched?(@project)
|
||||
current_user.unwatch!(@project)
|
||||
render_ok
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
|
||||
def follow
|
||||
begin
|
||||
return normal_status(2, "你已关注了") if current_user.watched?(@project)
|
||||
current_user.watch!(@project)
|
||||
render_ok
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def set_project
|
||||
@project = Project.find params[:project_id]
|
||||
rescue Exception => e
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
class Contents::DeleteForm < BaseForm
|
||||
attr_accessor :login, :repo_identifier, :filepath, :branch, :new_branch, :sha
|
||||
|
||||
validates :login, :repo_identifier, :filepath, :sha, presence: true
|
||||
|
||||
end
|
@ -0,0 +1,13 @@
|
||||
class Contents::UpdateForm < BaseForm
|
||||
attr_accessor :login, :repo_identifier, :filepath, :branch, :new_branch, :sha
|
||||
|
||||
validates :login, :repo_identifier, :filepath, :sha, presence: true
|
||||
|
||||
validate :check_branch
|
||||
|
||||
def check_branch
|
||||
raise "branch和new_branch必须存在一个 " if branch.blank? && new_branch.blank?
|
||||
raise "branch和new_branch只能存在一个" if !branch.blank? && !new_branch.blank?
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,2 @@
|
||||
module WatchersHelper
|
||||
end
|
@ -0,0 +1,65 @@
|
||||
module Gitea
|
||||
class DeleteFileInteractor
|
||||
def self.call(user, params={})
|
||||
interactor = new(user, params)
|
||||
interactor.run
|
||||
interactor
|
||||
end
|
||||
|
||||
attr_reader :error, :result
|
||||
|
||||
def initialize(user, params)
|
||||
@user = user
|
||||
@params = params
|
||||
end
|
||||
|
||||
def success?
|
||||
@error.nil?
|
||||
end
|
||||
|
||||
def result
|
||||
@result
|
||||
end
|
||||
|
||||
def run
|
||||
Contents::DeleteForm.new(valid_params).validate!
|
||||
response = Gitea::Repository::Entries::DeleteService.new(user, @params[:repo_identifier], @params[:filepath], file_params).call
|
||||
render_result(response)
|
||||
rescue Exception => exception
|
||||
fail!(exception.message)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :params, :user
|
||||
|
||||
def fail!(error)
|
||||
puts "[exception]: error"
|
||||
@error = error
|
||||
end
|
||||
|
||||
def render_result(response)
|
||||
if response.status == 200
|
||||
@result = JSON.parse(response.body)
|
||||
end
|
||||
end
|
||||
|
||||
def valid_params
|
||||
{
|
||||
login: @params[:login],
|
||||
repo_identifier: @params[:repo_identifier],
|
||||
filepath: @params[:filepath],
|
||||
sha: @params[:sha]
|
||||
}
|
||||
end
|
||||
|
||||
def file_params
|
||||
Hash.new.merge(
|
||||
branch: @params[:branch],
|
||||
sha: @params[:sha],
|
||||
new_branch: @params[:new_branch],
|
||||
message: @params[:message],
|
||||
).compact
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,69 @@
|
||||
module Gitea
|
||||
class UpdateFileInteractor
|
||||
def self.call(user, params={})
|
||||
interactor = new(user, params)
|
||||
interactor.run
|
||||
interactor
|
||||
end
|
||||
|
||||
attr_reader :error, :result
|
||||
|
||||
def initialize(user, params)
|
||||
@user = user
|
||||
@params = params
|
||||
end
|
||||
|
||||
def success?
|
||||
@error.nil?
|
||||
end
|
||||
|
||||
def result
|
||||
@result
|
||||
end
|
||||
|
||||
def run
|
||||
Contents::UpdateForm.new(valid_params).validate!
|
||||
response = Gitea::Repository::Entries::UpdateService.new(user, @params[:repo_identifier], @params[:filepath], file_params).call
|
||||
render_result(response)
|
||||
rescue Exception => exception
|
||||
fail!(exception.message)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :params, :user
|
||||
|
||||
def fail!(error)
|
||||
puts "[exception]: error"
|
||||
@error = error
|
||||
end
|
||||
|
||||
def render_result(response)
|
||||
if response.status == 200
|
||||
@result = JSON.parse(response.body)
|
||||
end
|
||||
end
|
||||
|
||||
def valid_params
|
||||
{
|
||||
login: @params[:login],
|
||||
repo_identifier: @params[:repo_identifier],
|
||||
filepath: @params[:filepath],
|
||||
branch: @params[:branch],
|
||||
new_branch: @params[:new_branch],
|
||||
sha: @params[:sha]
|
||||
}
|
||||
end
|
||||
|
||||
def file_params
|
||||
Hash.new.merge(
|
||||
branch: @params[:branch],
|
||||
sha: @params[:sha],
|
||||
new_branch: @params[:new_branch],
|
||||
from_path: @params[:from_path],
|
||||
message: @params[:message],
|
||||
content: Base64.encode64(@params[:content])
|
||||
).compact
|
||||
end
|
||||
end
|
||||
end
|
@ -1,32 +0,0 @@
|
||||
class Gitea::APIService < ApplicationService
|
||||
|
||||
def self.render_status(response)
|
||||
mark = " --from gitea platform."
|
||||
case response.status
|
||||
when 201
|
||||
JSON.parse(response&.body)
|
||||
when 401
|
||||
raise Error, "401 Unauthorized from gitea #{mark}"
|
||||
when 403, 422
|
||||
body = JSON.parse(response&.body)
|
||||
raise Error, body['message'] + mark
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def self.base_url
|
||||
Gitea.gitea_config[:base_url]
|
||||
end
|
||||
|
||||
def self.domain
|
||||
Gitea.gitea_config[:domain]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def logger
|
||||
Rails.logger
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
json.commit do
|
||||
json.sha @file['commit']['sha']
|
||||
json.message @file['commit']['message']
|
||||
json.author @file['commit']['author']
|
||||
json.committer @file['commit']['committer']
|
||||
end
|
@ -0,0 +1,10 @@
|
||||
json.name @file['content']['name']
|
||||
json.sha @file['content']['sha']
|
||||
json.size @file['content']['size']
|
||||
json.content @file['content']['content']
|
||||
json.encoding @file['content']['encoding']
|
||||
json.commit do
|
||||
json.message @file['commit']['message']
|
||||
json.author @file['commit']['author']
|
||||
json.committer @file['commit']['committer']
|
||||
end
|
@ -1,7 +1,3 @@
|
||||
if @sub_entries.is_a? Array
|
||||
json.array! @sub_entries do |entry|
|
||||
json.partial! 'repositories/simple_entry', locals: { entry: entry }
|
||||
end
|
||||
else
|
||||
json.partial! 'repositories/simple_entry', locals: { entry: @sub_entries }
|
||||
json.array! @sub_entries do |entry|
|
||||
json.partial! 'repositories/simple_entry', locals: { entry: entry }
|
||||
end
|
||||
|
@ -0,0 +1,5 @@
|
||||
json.username @user.full_name
|
||||
json.login @user.login
|
||||
json.user_id @user.id
|
||||
json.image_url url_to_avatar(@user)
|
||||
json.admin @user.admin
|
@ -0,0 +1,3 @@
|
||||
json.name watcher.user.real_name
|
||||
json.login watcher.user.login
|
||||
json.image_url url_to_avatar(watcher.user)
|
@ -0,0 +1,4 @@
|
||||
json.total_count @watchers.size
|
||||
json.watchers do
|
||||
json.partial! 'watcher', collection: @watchers, as: :watcher
|
||||
end
|
@ -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
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue