forked from NextAcademy/activerecord-jr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
56 lines (47 loc) · 1.44 KB
/
Rakefile
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
require 'faker'
task :console do
exec "irb -r./app.rb"
end
namespace :db do
task :seed do
require_relative 'app'
cohort_names = %w(Alpha Beta Delta Gamma Epsilon Zeta Eta Theta Iota)
cohort_ids = cohort_names.map do |name|
Cohort.create(:name => name)[:id]
end
2000.times do
Student.create :first_name => Faker::Name.first_name,
:last_name => Faker::Name.last_name,
:email => Faker::Internet.email,
:birthdate => Date.today - rand(15..40)*365,
:gender => ['m', 'f'].sample,
:cohort_id => cohort_ids.sample
end
end
task :setup do
require_relative 'app.rb'
print "Creating database at #{Database::Model.filename}..."
Database::Model.execute(<<-SQL)
CREATE TABLE "students" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"cohort_id" integer,
"first_name" varchar(255),
"last_name" varchar(255),
"email" varchar(255),
"gender" varchar(255),
"birthdate" date,
"created_at" datetime NOT NULL,
"updated_at" datetime NOT NULL
);
SQL
Database::Model.execute(<<-SQL)
CREATE TABLE "cohorts" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"name" varchar(255),
"created_at" datetime NOT NULL,
"updated_at" datetime NOT NULL
);
SQL
puts "done"
end
end