0142814c56595cf9d1ce91f3f4af6f70ec4bfc20
[dbsrgits/DBIx-Class-Fixtures.git] / lib / DBIx / Class / Fixtures / Versioned.pm
1 package DBIx::Class::Fixtures::Versioned;
2
3 use strict;
4 use warnings;
5
6 use base qw/DBIx::Class::Fixtures/;
7 use Class::C3;
8
9 =head1 VERSION
10
11 Version 1.000
12
13 =cut
14
15 our $VERSION = '1.000';
16
17 =head1 NAME
18
19 =head1 SYNOPSIS
20
21 =head1 DESCRIPTION
22
23 =head1 AUTHOR
24
25 =head1 CONTRIBUTORS
26
27 =head1 METHODS
28
29 =head2 new
30
31 =cut
32
33 sub populate {
34   my $self = shift;
35   my ($params) = @_;
36
37   $self->schema_class("DBIx::Class::Fixtures::SchemaVersioned");
38   unless ($params->{version}) {
39       return DBIx::Class::Exception->throw('You must pass a version to populate');
40   }
41
42   return $self->next::method(@_);
43 }
44
45 sub _generate_schema {
46   my $self = shift;
47   my ($params) = @_;
48
49   my $v = $self->schema_class;
50   # manually set the schema version
51   ${$v::VERSION} = $params->{version};
52
53   my $schema = $self->next::method(@_);
54
55   # set the db version to the schema version
56   $schema->upgrade(); # set version number  
57
58   return $schema;
59 }
60
61 1;