Commit | Line | Data |
f54428ab |
1 | #!/usr/bin/env perl |
0c337847 |
2 | |
0c337847 |
3 | use strict; |
f54428ab |
4 | use warnings; |
5 | |
a5bd5d88 |
6 | use MyApp::Schema; |
e48635f7 |
7 | use DBIx::Class::_Util 'parent_dir'; |
0c337847 |
8 | |
e48635f7 |
9 | my $db_fn = parent_dir( $INC{'MyApp/Schema.pm'} ) . '../db/example.db'; |
15ff1933 |
10 | |
11 | my $schema = MyApp::Schema->connect("dbi:SQLite:$db_fn"); |
0c337847 |
12 | |
0c337847 |
13 | my @artists = (['Michael Jackson'], ['Eminem']); |
14 | $schema->populate('Artist', [ |
15 | [qw/name/], |
16 | @artists, |
17 | ]); |
18 | |
19 | my %albums = ( |
20 | 'Thriller' => 'Michael Jackson', |
21 | 'Bad' => 'Michael Jackson', |
22 | 'The Marshall Mathers LP' => 'Eminem', |
23 | ); |
24 | |
25 | my @cds; |
26 | foreach my $lp (keys %albums) { |
c6e27318 |
27 | my $artist = $schema->resultset('Artist')->find({ |
0c337847 |
28 | name => $albums{$lp} |
29 | }); |
c6e27318 |
30 | push @cds, [$lp, $artist->id]; |
0c337847 |
31 | } |
32 | |
33 | $schema->populate('Cd', [ |
1f9ae1a3 |
34 | [qw/title artistid/], |
0c337847 |
35 | @cds, |
36 | ]); |
37 | |
38 | |
39 | my %tracks = ( |
40 | 'Beat It' => 'Thriller', |
41 | 'Billie Jean' => 'Thriller', |
42 | 'Dirty Diana' => 'Bad', |
43 | 'Smooth Criminal' => 'Bad', |
44 | 'Leave Me Alone' => 'Bad', |
45 | 'Stan' => 'The Marshall Mathers LP', |
46 | 'The Way I Am' => 'The Marshall Mathers LP', |
47 | ); |
48 | |
49 | my @tracks; |
50 | foreach my $track (keys %tracks) { |
3d9632fd |
51 | my $cd = $schema->resultset('Cd')->find({ |
0c337847 |
52 | title => $tracks{$track}, |
53 | }); |
3d9632fd |
54 | push @tracks, [$cd->id, $track]; |
0c337847 |
55 | } |
56 | |
57 | $schema->populate('Track',[ |
1f9ae1a3 |
58 | [qw/cdid title/], |
0c337847 |
59 | @tracks, |
60 | ]); |