From 90ee4bbe6061ec5c94b25af839329d3e4d60fcdb Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 20 Oct 2015 09:55:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=A9=BA=E7=9A=84=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E5=8A=A8=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20151019085603_update_attachments.rb | 23 ------------------- .../20151020013352_update_attachment.rb | 23 +++++++++++++++++++ ...51020014759_delete_null_course_activity.rb | 17 ++++++++++++++ db/schema.rb | 2 +- 4 files changed, 41 insertions(+), 24 deletions(-) delete mode 100644 db/migrate/20151019085603_update_attachments.rb create mode 100644 db/migrate/20151020013352_update_attachment.rb create mode 100644 db/migrate/20151020014759_delete_null_course_activity.rb diff --git a/db/migrate/20151019085603_update_attachments.rb b/db/migrate/20151019085603_update_attachments.rb deleted file mode 100644 index afb63a277..000000000 --- a/db/migrate/20151019085603_update_attachments.rb +++ /dev/null @@ -1,23 +0,0 @@ -class UpdateAttachments < ActiveRecord::Migration - def up - count = Attachment.all.count / 30 + 2 - transaction do - for i in 1 ... count do i - Attachment.page(i).per(30).each do |attachment| - if attachment.container_type == 'Course' - course = attachment.course - if course - if course.is_public == 0 - attachment.is_public = 0 - attachment.save - end - end - end - end - end - end - end - - def down - end -end diff --git a/db/migrate/20151020013352_update_attachment.rb b/db/migrate/20151020013352_update_attachment.rb new file mode 100644 index 000000000..3e1161c09 --- /dev/null +++ b/db/migrate/20151020013352_update_attachment.rb @@ -0,0 +1,23 @@ +class UpdateAttachment < ActiveRecord::Migration + def up + count = Attachment.all.count / 30 + 2 + transaction do + for i in 1 ... count do i + Attachment.page(i).per(30).each do |attachment| + if attachment.container_type == 'Course' + course = attachment.course + if course + if course.is_public == 0 + attachment.is_public = 0 + attachment.save + end + end + end + end + end + end + end + + def down + end +end diff --git a/db/migrate/20151020014759_delete_null_course_activity.rb b/db/migrate/20151020014759_delete_null_course_activity.rb new file mode 100644 index 000000000..0d7b11693 --- /dev/null +++ b/db/migrate/20151020014759_delete_null_course_activity.rb @@ -0,0 +1,17 @@ +class DeleteNullCourseActivity < ActiveRecord::Migration + def up + count = CourseActivity.all.count / 30 + 2 + transaction do + for i in 1 ... count do i + CourseActivity.page(i).per(30).each do |activity| + unless activity.course_act + activity.destroy + end + end + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 44548ad9c..41efc5698 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20151019085603) do +ActiveRecord::Schema.define(:version => 20151020014759) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false