@@ -76,12 +76,57 @@ namespace :db do
7676 end
7777 end
7878
79- # Use factory bot to create the associated units
80- #unit_definitions.each do |unit_definition|
81- # FactoryBot.create_list(:unit, 3, unit_definition_id: unit_definition.id)
82- #Send
83-
8479 puts "Database filled with courseflow data"
8580 puts "Unit Definitions: #{ UnitDefinition . count } "
8681 end
82+
83+ desc "Populate the courseflow db with fixed unit definitions"
84+ task populate_fixed_courseflow_data : :environment do
85+ require 'faker'
86+
87+ # Clear existing data from database
88+ old_units = Unit . where . not ( unit_definition_id : nil )
89+ puts "Deleting #{ old_units . count } units"
90+ old_units . destroy_all
91+ puts "Deleting #{ UnitDefinition . count } unit definitions"
92+ UnitDefinition . destroy_all
93+
94+ # Create new unit definitions
95+ unit_definitions = [
96+ { name : "Computer Systems" , code : "SIT111" , version : "1.0" } ,
97+ { name : "Discrete Mathematics" , code : "SIT192" , version : "1.0" } ,
98+ { name : "Data Science Concepts" , code : "SIT112" , version : "1.0" } ,
99+ { name : "Introduction to Programming" , code : "SIT102" , version : "1.0" } ,
100+
101+ { name : "Object-Oriented Development" , code : "SIT232" , version : "1.0" } ,
102+ { name : "Database Fundamentals" , code : "SIT103" , version : "1.0" } ,
103+ { name : "Linear Algebra for Data Analysis" , code : "SIT292" , version : "1.0" } ,
104+ { name : "Computer Networks and Communication" , code : "SIT202" , version : "1.0" } ,
105+
106+ { name : "Computer Intelligence" , code : "SIT215" , version : "1.0" } ,
107+ { name : "Data Structures and Algorithms" , code : "SIT221" , version : "1.0" } ,
108+ { name : "Gamified Media" , code : "ALM201" , version : "1.0" } ,
109+ { name : "Global Media" , code : "ALM215" , version : "1.0" } ,
110+
111+ { name : "Professional Practice" , code : "SIT344" , version : "1.0" } ,
112+ { name : "Team Project (A) - Project Management and Practices" , code : "SIT374" , version : "1.0" } ,
113+ { name : "Team Project (B) - Execution and Delivery" , code : "SIT378" , version : "1.0" } ,
114+ { name : "Concurrent and Distributed Programming" , code : "SIT315" , version : "1.0" } ,
115+
116+ { name : "Computer Networks and Communication" , code : "SIT202" , version : "1.0" } ,
117+ { name : "Cyber Security Management" , code : "SIT284" , version : "1.0" } ,
118+ { name : "Machine Learning" , code : "SIT307" , version : "1.0" } ,
119+ { name : "Full Stack Development: Secure Backend Services" , code : "SIT331" , version : "1.0" }
120+ ]
121+
122+ unit_definitions . each do |unit_definition |
123+ new_unit_definition = UnitDefinition . create (
124+ name : unit_definition [ :name ] ,
125+ description : Faker ::Lorem . paragraph ( sentence_count : 1 ) , # Generates a random description for the definitions
126+ code : unit_definition [ :code ] ,
127+ version : unit_definition [ :version ]
128+ )
129+ puts "Created Unit Definition: #{ new_unit_definition . name } "
130+ end
131+ end
87132end
0 commit comments