Git Product home page Git Product logo

dbix-delta's Introduction

NAME

DBIx::Delta - a module for applying outstanding database deltas (migrations) to a database instance

SYNOPSIS

# Must be used via a subclass providing a db connection e.g.
package Foo::Delta;
use base qw(DBIx::Delta);
use DBI;
sub connect { 
    DBI->connect('dbi:SQLite:dbname=foo.db');
}
1;

# Then:
perl -MFoo::Delta -le 'Foo::Delta->run'
# Or create a delta run script (e.g. delta.pl):
use Foo::Delta;
Foo::Delta->run;

# Then to check for deltas that have not been applied
./delta.pl 
# And to apply those deltas and update the database
./delta.pl -u

DESCRIPTION

DBIx::Delta is a module used to apply database deltas (migrations) to a database instance.

It is intended for use in maintaining multiple database schemas in sync e.g. you create deltas on your development database instance, and subsequently apply those deltas to your test instance, and then finally to production.

It is simple and only requires DBI/DBD for your database connectivity.

DELTAS

Deltas are just '*.sql' files containing arbitrary sql statements, in your current directory. Any deltas that haven't been seen before are executed against your database, and if successful, the filename is recorded in an 'applied' subdirectory, and those deltas are thereafter ignored.

This means that you can't change or add to a delta after it has been applied to the database. Changes to existing database objects must be done via new deltas using appropriate 'ALTER' commands.

USAGE

# Must be used via a subclass providing a db connection e.g.
package Foo::Delta;
use base qw(DBIx::Delta);
use DBI;
sub connect { 
    DBI->connect('dbi:SQLite:dbname=foo.db','','');
}
1;

# And then ...
perl -MFoo::Delta -le 'Foo::Delta->run'

STATEMENT FILTERING

As of version 0.5 DBIx::Delta supports statement filtering, allowing subclasses to do arbitrary munging of statements before they're applied. This is done by overriding the filter_statement method in your subclass:

sub filter_statement {
  my ($self, $statement) = @_;

  # Munge $statement

  return $statement;
}

This can be useful, for instance, if you're doing IP-based grants in your deltas, and need to use different addresses for your different environments. For instance, you could use the following grant in your delta (mysql syntax):

grant all on db.table to user@localhost;

and then modify it in your production DBIx::Delta subclass by doing:

$statement =~ s/^(grant.*)localhost/${1}192.168.0.10/;

AUTHOR

Gavin Carr [email protected]

LICENCE

Copyright 2005-2014, Gavin Carr.

This program is free software. You may copy or redistribute it under the same terms as perl itself.

dbix-delta's People

Contributors

gavincarr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.