DBIx-Schema-UpToDate

 view release on metacpan or  search on metacpan

lib/DBIx/Schema/UpToDate.pm  view on Meta::CPAN

  $dbh->do('INSERT INTO ' . $self->quoted_table_name .
    ' (' .
      join(', ', $self->quote_identifiers(qw(version updated)))
    . ') VALUES(?, ?)',
    {}, $version, time()
  )
    or croak $dbh->errstr;
}


sub updates {
  my ($self) = @_;
  return $self->{updates} ||= [
  ];
}


sub update_to_version {
  my ($self, $version) = @_;

  $self->begin_work();

  # execute updates to bring database to $version
  $self->updates->[$version - 1]->($self);

  # save the version now in case we get interrupted before the next commit
  $self->set_version($version);

lib/DBIx/Schema/UpToDate.pm  view on Meta::CPAN


=head1 VERSION

version 1.001

=head1 SYNOPSIS

  package Local::Database;
  use parent 'DBIx::Schema::UpToDate';

  sub updates {
    shift->{updates} ||= [

      # version 1
      sub {
        my ($self) = @_;
        $self->dbh->do('-- sql');
        $self->do_something_else;
      },

      # version 2

t/lib/Test_Schema.pm  view on Meta::CPAN

#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
package
  Test_Schema;

require DBIx::Schema::UpToDate;
our @ISA = qw(DBIx::Schema::UpToDate);

sub updates {
  shift->{updates} ||= [
    # v1
    sub {
      my ($self) = @_;
      $self->dbh->do(q[CREATE TABLE tbl1 (fld1 text, fld2 int)]);
      $self->dbh->do(q[INSERT INTO tbl1 VALUES('goo', 1)]);
    },
    # v2
    sub {
      my ($self) = @_;



( run in 0.308 second using v1.01-cache-2.11-cpan-4d4bc49f3ae )