DBIx-Class-Helper-ResultSet-MySQLHacks
view release on metacpan or search on metacpan
t/lib/CDTest.pm view on Meta::CPAN
[ qw/producerid name/ ],
[ 1, 'Matt S Trout' ],
[ 2, 'Bob The Builder' ],
[ 3, 'Fred The Phenotype' ],
[ 4, 'Various' ],
]);
$schema->populate('CDToProducer', [
[ qw/cd producer/ ],
[ 1, 1 ],
[ 1, 2 ],
[ 1, 3 ],
[ 2, 2 ],
[ 3, 2 ],
[ 3, 3 ],
[ 4, 1 ],
map { [ $_, 4 ] } qw< 9 10 11 15 16 17 19 21 22 24 25 30 >,
]);
$schema->populate('Track', [
[ qw/trackid cd position title/ ],
[ 4, 2, 1, "Stung with Success"],
[ 5, 2, 2, "Stripy"],
[ 6, 2, 3, "Sticky Honey"],
[ 7, 3, 1, "Yowlin"],
[ 8, 3, 2, "Howlin"],
[ 9, 3, 3, "Fowlin"],
[ 10, 4, 1, "Boring Name"],
[ 11, 4, 2, "Boring Song"],
[ 12, 4, 3, "No More Ideas"],
[ 13, 5, 1, "Sad"],
[ 14, 5, 2, "Under The Weather"],
[ 15, 5, 3, "Suicidal"],
[ 16, 1, 1, "The Bees Knees"],
[ 17, 1, 2, "Apiary"],
[ 18, 1, 3, "Beehind You"],
[ 20, 9, 1, "Diamond Circus"],
[ 21, 9, 2, "We're Crazy"],
[ 22, 9, 3, "First Heart"],
[ 23, 10, 1, "World Of Old"],
[ 24, 10, 2, "Story Of More"],
[ 26, 10, 3, "Home Secrets"],
[ 27, 10, 4, "Matter Of Right Now"],
[ 28, 11, 1, "Dance Tales"],
[ 29, 11, 2, "She Hopes We Like To Party"],
[ 30, 11, 3, "Stop Rhythm"],
[ 32, 15, 1, "Story Of My Party"],
[ 33, 15, 2, "Finding Her Fire"],
[ 34, 16, 1, "Crispy Dreams"],
[ 35, 16, 2, "Kent"],
[ 36, 16, 3, "Superman"],
[ 38, 17, 1, "42 Minutes of Silence"],
[ 40, 19, 1, "Surface Tension"],
[ 44, 19, 2, "This Could Totally Work"],
[ 45, 19, 3, "Off-By-One Errors"],
[ 46, 19, 4, "Two"],
[ 47, 21, 1, "Enemy"],
[ 48, 21, 2, "Gamma"],
[ 50, 21, 3, "258"],
[ 55, 21, 4, "Genetic Macroeconomics"],
[ 56, 22, 1, "That One Spot in the Game"],
[ 57, 22, 2, "Leitmotif"],
[ 58, 22, 3, "The Part Where He Kills You"],
[ 59, 24, 1, "Magenta"],
[ 65, 25, 1, "Yellow"],
[ 70, 30, 1, "Cyan"],
]);
}
=head2 mass_populate_schema
CDTest->mass_populate_schema( $schema, $batches );
Populate the schema with massive amounts of data, mostly as duplicates of different rows.
The C<$batches> are measured in thousands of artists. In other words, one batch is:
1000 artists
~2500 CDs
~20000 tracks
Just 10 batches takes up quite a bit of space (around 100MB of memory in the SQLite in-memory DB),
and takes around 30 seconds to populate.
=cut
sub mass_populate_schema {
my ($self, $schema, $batches) = @_;
$batches ||= 10;
for (1 .. $batches) {
if (is_class_loaded('Test2::Tools::Basic')) {
Test2::Tools::Basic::note("Mass populating data: $_,000 records");
}
# Create 1000 fake artists
my $artist_rows = [ [ qw/name/ ] ];
my $track_rows = [ [ qw/cd position title/ ] ];
for (1 .. 1000) {
push @$artist_rows, [ $self->_random_words ];
}
my @artists = $schema->populate('Artist', $artist_rows);
# Create a bunch of fake albums
while (my $artist = shift @artists) {
my $cd_rows = [ [ qw/artist title year/ ] ];
for (1 .. int(rand 5)+1) {
push @$cd_rows, [
$artist->artistid,
$self->_random_words,
1950 + int(rand(68)),
];
}
my @cds = $schema->populate('CD', $cd_rows);
# Create a bunch of fake tracks
while (my $cd = shift @cds) {
for (1 .. int(rand 15)+1) {
push @$track_rows, [
( run in 0.518 second using v1.01-cache-2.11-cpan-39bf76dae61 )