An open API service indexing awesome lists of open source software.

https://github.com/awncorp/moodle

Mojo DB Driver Migrations
https://github.com/awncorp/moodle

database ddl migrations perl perl5

Last synced: about 2 months ago
JSON representation

Mojo DB Driver Migrations

Awesome Lists containing this project

README

          

NAME

Moodle

ABSTRACT

Mojo DB Driver Migrations

SYNOPSIS

# migration: step #1

package Migration::Step1;

use parent 'Doodle::Migration';

no warnings 'redefine';

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

my $table = $doodle->table('users');
$table->primary('id');
$table->create;

return $doodle;
}

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

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

return $doodle;
}

# migration: step #2

package Migration::Step2;

use parent 'Doodle::Migration';

no warnings 'redefine';

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

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

return $doodle;
}

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

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

return $doodle;
}

# migration: root

package Migration;

use parent 'Doodle::Migration';

sub migrations {[
'Migration::Step1',
'Migration::Step2',
]}

# main program

package main;

use Moodle;

my $self = Moodle->new(
driver => $main::driver,
migrator => Migration->new
);

# $self->migrate;

DESCRIPTION

This package uses Doodle with Mojo database drivers to easily install
and evolve database schema migrations. See Doodle::Migration for help
setting up Doodle migrations, and Mojo::Pg, Mojo::mysql or Mojo::SQLite
for help configuring DB drivers.

LIBRARIES

This package uses type constraints from:

Moodle::Library

ATTRIBUTES

This package has the following attributes:

driver

driver(Driver)

This attribute is read-only, accepts (Driver) values, and is required.

migrator

migrator(Migrator)

This attribute is read-only, accepts (Migrator) values, and is
required.

METHODS

This package implements the following methods:

content

content() : Str

This method generates DB migration statements returning a string
containing "UP" and "DOWN" versioned migration strings suitable for use
with the migration feature of Mojo database drivers.

content example #1

# given: synopsis

my $content = $self->content;

migrate

migrate(Maybe[Str] $target) : Object

This method uses the DB migration statements generated by the "content"
method and installs them using the Mojo database driver. This method
returns a migration object relative to the DB driver used.

migrate example #1

# given: synopsis

my $migrate = $self->migrate;

AUTHOR

Al Newkirk, awncorp@cpan.org

LICENSE

Copyright (C) 2011-2019, Al Newkirk, et al.

This is free software; you can redistribute it and/or modify it under
the terms of the The Apache License, Version 2.0, as elucidated in the
"license file"
.

PROJECT

Wiki

Project

Initiatives

Milestones

Contributing

Issues