diff --git a/LocalReadMe.md b/LocalReadMe.md index 1752c37b0..5b9abf9a7 100644 --- a/LocalReadMe.md +++ b/LocalReadMe.md @@ -18,4 +18,7 @@ educoder 123456789 9、 需要导入的TPM版本库: 在mysql中:select repo_name from shixuns; - 将mysql输出的结果交给运维使用脚本一建导入 \ No newline at end of file + 将mysql输出的结果交给运维使用脚本一建导入 + + 10、 关于实训的附件问题: + select * from attachments where container_type='Shixun' and container_id in(select distinct(c.id) from subjects s join stage_shixuns ss on ss.subject_id = s.id join shixun_mirror_repositories smr on smr.shixun_id = ss.shixun_id join mirror_repositories mr on mr.id = smr.mirror_repository_id join challenges c on c.shixun_id = ss.shixun_id where s.id in(406, 51, 388, 408, 413, 411, 412, 410, 405, 407, 414)); \ No newline at end of file diff --git a/app/controllers/initialization_data_controller.rb b/app/controllers/initialization_data_controller.rb index 68f679ac1..3dc695bbb 100644 --- a/app/controllers/initialization_data_controller.rb +++ b/app/controllers/initialization_data_controller.rb @@ -9,13 +9,23 @@ class InitializationDataController < ApplicationController logger.info("#########{origin_database}") raise("请配置原始数据库") if origin_database.blank? raise("请配置本地数据库") if database.blank? - # 获取原始数据库导入数据 + # 获取原始数据库导入数据 TODO: 附件同步问题。 attachemnts表 get_origin_data origin_database, paths # 创建初始数据 create_init_data database normal_status("初始化数据成功!") end + def clear_test_data + # 删除测试数据. + ActiveRecord::Base.transaction do + User.where("id > 2").destroy_all + Myshixun.where(user: 1).destroy_all + Course.where(tea_id: 1).destroy_all + normal_status("初始化数据成功!") + end + end + def get_origin_data origin_database, paths connect_to_origin_date(origin_database) get_subject_data(paths) diff --git a/app/models/user.rb b/app/models/user.rb index 12759ea4d..4ff85b2d5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -36,7 +36,7 @@ class User < ApplicationRecord has_many :myshixuns, :dependent => :destroy has_many :study_shixuns, through: :myshixuns, source: :shixun # 已学习的实训 has_many :course_messages - has_many :courses, dependent: :destroy + has_many :courses, foreign_key: :tea_id, dependent: :destroy #试卷 has_many :exercise_banks, :dependent => :destroy @@ -108,8 +108,8 @@ class User < ApplicationRecord has_many :manage_courses, through: :manage_course_members, source: :course # 关注 - has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注 - has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户 + #has_many :be_watchers, foreign_key: :user_id, dependent: :destroy # 我的关注 + #has_many :be_watcher_users, through: :be_watchers, dependent: :destroy # 我关注的用户 # 认证 has_many :apply_user_authentication diff --git a/config/routes.rb b/config/routes.rb index d17235737..9dd3d6c15 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,7 +33,11 @@ Rails.application.routes.draw do end end - resources :initialization_data + resources :initialization_data do + collection do + get :clear_test_data + end + end resources :tem_tests # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html #