The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

DBIx::Class::Schema::Versioned::Inline::Upgrade

SYNOPSIS

  package MyApp::Schema::Upgrade;
 
  use base 'DBIx::Class::Schema::Versioned::Inline::Upgrade';
  use DBIx::Class::Schema::Versioned::Inline::Upgrade qw/before after/;

  before '0.3.3' => sub {
      my $schema = shift;
      $schema->resultset('Foo')->update({ bar => '' });
  };

  after '0.3.5' => sub {
      my $schema = shift;
      # do something
  };

  1;

DESCRIPTION

schema/data upgrade helper for DBIx::Class::Schema::Versioned::Inline.

Assuming that your Schema class is named MyApp::Schema then you create a subclass of this class as MyApp::Schema::Upgrade and call the before and after methods from your Upgrade.pm.

METHODS

before VERSION SUB

Calling it signifies that SUB should be run immediately before upgrading the schema to version VERSION. If multiple subroutines are given for the same version, they are run in the order that they were set up.

Example:

Say you have a column definition in one of you result classes that was initially created with is_nullable = 1> and you decide that in a newer schema version you need to change it to is_nullable = 0>. You need to make sure that any existing null values are changed to non-null before the schema is modified.

You old Foo result class looks like:

    __PACKAGE__->add_column(
        "bar",
        { data_type => "integer", is_nullable => 1 }
    );

For you updated version 0.4 schema you change this to:

    __PACKAGE__->add_column(
        "bar",
        { data_type => "integer", is_nullable => 1, extra => {
            changes => {
                '0.4' => { is_nullable => 0 },
            },
        }
    );

and in your Upgrade subclass;

    before '0.4' => sub {
        my $schema = shift;
        $schema->resultset('Foo')->update({ bar => '' });
    };

after VERSION SUB

Calling it signifies that SUB should be run immediately after upgrading the schema to version VERSION. If multiple subroutines are given for the same version, they are run in the order that they were set up.

versions

Returns an ordered list of the upgrade versions that have been registered.

after_upgrade VERSION

Returns the before subroutines that have been registered for the given version.

before_upgrade VERSION

Returns the before subroutines that have been registered for the given version.