forked from TheOdinProject/theodinproject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseeds.rb
106 lines (85 loc) · 3.54 KB
/
seeds.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# This file should contain all the record creation needed to seed the database
# with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the
# db with db:setup).
# ******* NOTE ********
# You will have problems if you try to change the titles of
# courses/sections/lessons, since that's currently what's used to uniquely
# identify them!
# rubocop:disable Metrics/AbcSize
def create_or_update_path(path_attrs)
path = Path.where(title: path_attrs[:title]).first
if path.nil?
path = Path.create!(path_attrs)
Rails.logger.info ">>>> Created new path: #{path_attrs[:title]}!"
elsif path.attributes == path_attrs
Rails.logger.info "No changes to existing path: #{path_attrs[:title]}"
else
path.update_attributes(path_attrs)
Rails.logger.info "Updated existing << PATH >>: #{path_attrs[:title]}"
end
path
end
def create_or_update_course(course_attrs)
course = Course.where(title: course_attrs[:title]).first
if course.nil?
course = Course.create!(course_attrs)
Rails.logger.info ">>>> Created new course: #{course_attrs[:title]}!"
elsif course.attributes == course_attrs
Rails.logger.info "No changes to existing course: #{course_attrs[:title]}"
else
course.update_attributes(course_attrs)
Rails.logger.info "Updated existing << COURSE >>: #{course_attrs[:title]}"
end
course
end
def create_or_update_section(section_attrs)
section = Section.where(title: section_attrs[:title], course_id: section_attrs[:course_id]).first
if section.nil?
section = Section.create!(section_attrs)
Rails.logger.info ">>>> Created new SECTION: #{section_attrs[:title]}!"
elsif section.attributes == section_attrs
Rails.logger.info "No changes to existing section: #{section_attrs[:title]}"
else
section.update_attributes(section_attrs)
Rails.logger.info "Updated existing SECTION: #{section_attrs[:title]}"
end
section
end
def create_or_update_lesson(lesson_attrs)
lesson = Lesson.where(title: lesson_attrs[:title], section_id: lesson_attrs[:section_id]).first
if lesson.nil?
lesson = Lesson.create!(lesson_attrs)
Rails.logger.info ">>>> Created new lesson: #{lesson_attrs[:title]}!"
elsif lesson.attributes == lesson_attrs
Rails.logger.info "No changes to existing lesson: #{lesson_attrs[:title]}"
else
lesson.update_attributes!(lesson_attrs)
Rails.logger.info "Updated existing lesson: #{lesson_attrs[:title]}"
end
lesson
end
# rubocop:enable Metrics/AbcSize
load './db/seeds/01_foundations_seeds.rb'
load './db/seeds/02_ruby_course_seeds.rb'
load './db/seeds/03_database_course_seeds.rb'
load './db/seeds/04_rails_course_seeds.rb'
load './db/seeds/05_html_css_course_seeds.rb'
load './db/seeds/06_javascript_course_seeds.rb'
load './db/seeds/07_getting_hired_course_seeds.rb'
load './db/seeds/08_node_js_course_seeds.rb'
Rails.logger.info "\n\n***** STARTING PATHS *****"
load './db/seeds/paths/foundations.rb'
load './db/seeds/paths/full_stack_rails.rb'
load './db/seeds/paths/full_stack_javascript.rb'
load './db/seeds/paths/front_end.rb'
# GENERATE SUCCESS STORY Content
load './db/seeds/success_stories.rb'
# GENERATE test projects
load './db/seeds/test_project_submissions.rb'
#################
# SANITY CHECKS #
#################
Rails.logger.info "\n\n\n\n\n################## SANITY CHECKS ##################\n\n"
Rails.logger.info "#{Path.count} paths, #{Course.count} courses, #{Section.count} sections and #{Lesson.count} lessons in the database.\n"
Rails.logger.info "\n#######################################################\n\n\n\n"