-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbuild_sample_db.pl
More file actions
executable file
·64 lines (45 loc) · 1.63 KB
/
build_sample_db.pl
File metadata and controls
executable file
·64 lines (45 loc) · 1.63 KB
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
#!/usr/bin/env perl
# This file fills a database with sample data from JSON files.
use warnings;
use strict;
use feature 'say';
use Mojo::File qw/curfile/;
use YAML::XS qw/LoadFile/;
use lib curfile->dirname->dirname->sibling('lib')->to_string;
use lib curfile->dirname->dirname->sibling('t/lib')->to_string;
use DB::Schema;
use BuildDB qw/loadPermissions addCourses addUsers addSets addProblems addUserSets addProblemPools addUserProblems/;
my $ww3_dir = curfile->dirname->dirname->dirname;
# Load the configuration for the database settings.
my $config_file = $ww3_dir->child('conf', 'webwork3-dev.yml');
$config_file = $ww3_dir->child('conf/webwork3.yml') unless -e $config_file;
$config_file = $ww3_dir->child('conf/webwork3.dist.yml') unless -e $config_file;
my $config = LoadFile($config_file);
# Connect to the database.
my $schema = DB::Schema->connect(
$config->{database_dsn},
$config->{database_user},
$config->{database_password},
{ quote_names => 1 }
);
say "restoring the database with dbi: $config->{database_dsn}";
# Create the database based on the schema.
$schema->deploy({ add_drop_table => 1 });
# The permissions need to be loaded into the database first.
say 'loading permissions';
loadPermissions($schema, $ww3_dir);
say 'adding courses';
addCourses($schema, $ww3_dir);
say 'adding users';
addUsers($schema, $ww3_dir);
say 'adding problem sets';
addSets($schema, $ww3_dir);
say 'adding problems';
addProblems($schema, $ww3_dir);
say 'adding user sets';
addUserSets($schema, $ww3_dir);
say 'adding problem pools';
addProblemPools($schema, $ww3_dir);
say 'adding user problems';
addUserProblems($schema, $ww3_dir);
1;