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

Doodle::Migration

ABSTRACT

Database Migration Class

SYNOPSIS

  # in lib/My/Migration/Step1.pm

  package My::Migration::Step1;

  use parent 'Doodle::Migration';

  sub up {
    my ($self, $doodle) = @_;

    my $users = $doodle->table('users');
    $users->primary('id');
    $users->string('email');
    $users->create;
    $users->index(columns => ['email'])->unique->create;

    return $doodle;
  }

  sub down {
    my ($self, $doodle) = @_;

    my $users = $doodle->table('users');
    $users->delete;

    return $doodle;
  }

  # in lib/My/Migration/Step2.pm

  package My::Migration::Step2;

  use parent 'Doodle::Migration';

  sub up {
    my ($self, $doodle) = @_;

    my $users = $doodle->table('users');
    $users->string('first_name')->create;
    $users->string('last_name')->create;

    return $doodle;
  }

  sub down {
    my ($self, $doodle) = @_;

    my $users = $doodle->table('users');
    $users->string('first_name')->delete;
    $users->string('last_name')->delete;

    return $doodle;
  }

  1;

DESCRIPTION

This package provides a base class for creating database migration classes which will be handled by Doodle::Migrator classes.

METHODS

This package implements the following methods.

down

  down(Doodle $doodle) : Doodle

The migrate "DOWN" method is invoked automatically by the migrator Doodle::Migrator.

down example
  $doodle = $self->down($doodle);

up

  up(Doodle $doodle) : Doodle

The migrate "UP" method is invoked automatically by the migrator Doodle::Migrator.

up example
  $doodle = $self->up($doodle);