MAN page from OpenSuSE perl-Mojo-SQLite-2.002-10.1.noarch.rpm
Mojo::SQLite::Migrations
Section: User Contributed Perl Documentation (3pm)
Updated: 2017-06-01
Index NAME
Mojo::SQLite::Migrations - Migrations
SYNOPSIS
use Mojo::SQLite::Migrations; my $migrations = Mojo::SQLite::Migrations->new(sqlite => $sql); $migrations->from_file('/home/dbook/migrations.sql')->migrate;
DESCRIPTION
Mojo::SQLite::Migrations is used by Mojo::SQLite to allow databaseschemas to evolve easily over time. A migration file is just a collection ofsql blocks, with one or more statements, separated by comments of the form
"-- VERSION UP/DOWN".
-- 1 up create table messages (message text); insert into messages values ('I X Mojolicious!'); -- 1 down drop table messages; -- 2 up (...you can comment freely here...) create table stuff (whatever integer); -- 2 down drop table stuff;
The idea is to let you migrate from any version, to any version, up and down.Migrations are very safe, because they are performed in transactions and onlyone can be performed at a time. If a single statement fails, the wholemigration will fail and get rolled back. Every set of migrations has a``name'', which is stored together with the currently active version in anautomatically created table named "mojo_migrations".
ATTRIBUTES
Mojo::SQLite::Migrations implements the following attributes.
name
my $name = $migrations->name; $migrations = $migrations->name('foo');
Name for this set of migrations, defaults to "migrations".
sqlite
my $sql = $migrations->sqlite; $migrations = $migrations->sqlite(Mojo::SQLite->new);
Mojo::SQLite object these migrations belong to.
METHODS
Mojo::SQLite::Migrations inherits all methods from Mojo::Base andimplements the following new ones.
active
my $version = $migrations->active;
Currently active version.
from_data
$migrations = $migrations->from_data; $migrations = $migrations->from_data('main'); $migrations = $migrations->from_data('main', 'file_name');
Extract migrations from a file in the DATA section of a class with``data_section'' in Mojo::Loader, defaults to using the caller class and``name''.
__DATA__ @@ migrations -- 1 up create table messages (message text); insert into messages values ('I X Mojolicious!'); -- 1 down drop table messages;
from_file
$migrations = $migrations->from_file('/home/dbook/migrations.sql');
Extract migrations from a file.
from_string
$migrations = $migrations->from_string( '-- 1 up create table foo (bar integer); -- 1 down drop table foo;' );
Extract migrations from string.
latest
my $version = $migrations->latest;
Latest version available.
migrate
$migrations = $migrations->migrate; $migrations = $migrations->migrate(3);
Migrate from ``active'' to a different version, up or down, defaults to using``latest''. All version numbers need to be positive, with version 0representing an empty database.
# Reset database $migrations->migrate(0)->migrate;
DEBUGGING
You can set the
"MOJO_MIGRATIONS_DEBUG" environment variable to get someadvanced diagnostics information printed to
"STDERR".
MOJO_MIGRATIONS_DEBUG=1
BUGS
Report any issues on the public bugtracker.
AUTHOR
Dan Book,
"dbookAATTcpan.org" COPYRIGHT AND LICENSE
Copyright 2015, Dan Book.
This library is free software; you may redistribute it and/or modify it underthe terms of the Artistic License version 2.0.
SEE ALSO
Mojo::SQLite
Index
- NAME
- SYNOPSIS
- DESCRIPTION
- ATTRIBUTES
- name
- sqlite
- METHODS
- active
- from_data
- from_file
- from_string
- latest
- migrate
- DEBUGGING
- BUGS
- AUTHOR
- COPYRIGHT AND LICENSE
- SEE ALSO
This document was created byman2html,using the manual pages.