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