Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reスキルコースにプラクティスをコピーするタスクを作成 #8293

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: 2.1

orbs:
ruby: circleci/ruby@2.1.0
node: circleci/node@5.1.0
ruby: circleci/ruby@2.3.1
node: circleci/node@7.0.0
browser-tools: circleci/browser-tools@1.5.0
jobs:
build:
Expand Down Expand Up @@ -67,7 +67,6 @@ jobs:
parallelism: 3
steps:
- checkout
- run: sudo apt-get update # TODO: remove it https://github.com/CircleCI-Public/browser-tools-orb/issues/75#issuecomment-1641031119
- browser-tools/install-chrome:
replace-existing: true
chrome-version: 130.0.6723.116
Expand Down
2 changes: 1 addition & 1 deletion app/models/practice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class Practice < ApplicationRecord
has_one_attached :ogp_image
has_one_attached :completion_image

has_many :books, through: :practices_books
has_many :practices_books, dependent: :destroy
has_many :books, through: :practices_books
accepts_nested_attributes_for :practices_books, reject_if: :all_blank, allow_destroy: true

has_one :submission_answer, dependent: :destroy
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20250129033027_add_source_id_to_practices.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSourceIdToPractices < ActiveRecord::Migration[6.1]
def change
add_column :practices, :source_id, :integer
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_11_03_082456) do
ActiveRecord::Schema.define(version: 2025_01_29_033027) do

# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
Expand Down Expand Up @@ -539,6 +539,7 @@
t.text "memo"
t.integer "last_updated_user_id"
t.text "summary"
t.integer "source_id"
t.index ["category_id"], name: "index_practices_on_category_id"
end

Expand Down
65 changes: 55 additions & 10 deletions lib/tasks/bootcamp.rake
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,66 @@ namespace :bootcamp do
end
end

desc 'Copy practices from rails course to reskill course.'
task copy_practices: :environment do
sufix = '(Reスキル)'
slug = '-reskill'
rails_course = Course.find_by(title: 'Railsエンジニア')
reskill_course = Course.find_by(title: 'Railsエンジニア(Reスキル講座認定)')

if rails_course && reskill_course
Course.transaction do
# Copy categories
rails_course.categories.each do |category|
Category.exists?(name: category.name + sufix) && next

new_category = category.dup
new_category.id = nil
new_category.name = category.name + sufix
new_category.slug = category.slug + slug
puts "Copying category: #{new_category.name}"
reskill_course.categories << new_category
new_category.save!

# Copy practices
category.practices.each do |practice|
Practice.exists?(title: practice.title + sufix) && next

new_practice = practice.dup
new_practice.id = nil
new_practice.title = practice.title + sufix
new_practice.category_id = new_category.id
new_practice.source_id = practice.id

new_practice.categories << new_category

puts "Copying practice: #{new_practice.title}"
new_practice.save!

# Copy reports
practice.reports.each do |report|
new_practice.reports << report
end

# Copy books
practice.books.each do |book|
new_practice.books << book
end
end
end
puts 'Practices copied successfully.'
end
else
puts 'One or both courses not found.'
end
end

namespace :oneshot do
desc 'Cloud Build Task'
task cloudbuild: :environment do
puts '== START Cloud Build Task =='

watches = []
Watch.find_each do |watch|
w = "#{watch.watchable_type}-#{watch.watchable_id}-#{watch.user_id}"
if watches.include?(w)
puts w
watch.destroy
else
watches << w
end
end
Rake::Task['bootcamp:copy_practices'].invoke

puts '== END Cloud Build Task =='
end
Expand Down