The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

CouchDB::Deploy - Simple configuration scripting to deploy CouchDB databases

SYNOPSIS

    use CouchDB::Deploy;

    db 'my-test-db/', containing {
        doc {
            _id     => 'foo',
            key     => 'value',
            _attachments => {
                'foo.txt'   => {
                    content_type    => 'text/plain',
                    data            => 'RGFodXRzIEZvciBXb3JsZCBEb21pbmF0aW9uXCE=',
                },
                'bar.svg'   => {
                    content_type    => 'image/svg+xml',
                    data            => file 'dahut.svg',
                },
                'circle.html'   => {
                    content_type    => 'text/html;charset=utf-8',
                    data            => base64 <<EOHTML,
                                            <p>Hello!</p>
    EOHTML
                },
            },
        };
        design {
            _id         => '_design/dahuts',
            language    => 'javascript',
            views   => {
                'all'   => {
                    map     => "function(doc) { if (doc.type == 'dahut')  emit(null, doc) }",
                },
            },
        };
    };
    
    # then run the above as
    
    my-db-config.pl http://my.server:5984/

DESCRIPTION

This module attempts to help with the common issue of deploying databases and updates to database schemata in distributed development settings (which can simply be when you have your own dev box and a server to deploy to).

CouchDB does not have schemata, but it does have views (in design documents) on which methods in your code are likely to rely. At times, you may also wish to have a given document in a database, say the default configuration.

What this module does is:

  • Check that a given database exists, and create it if not

  • Check that a given document exists and has the same content as the one provided, and create or update it if not

  • Check that a given design document exists and has the same content as the one provided, and create or update it if not

  • Provide a simple helper for attachments and the specific base64 that CouchDB requires.

Currently this is done in Perl, using simple syntax sugar but it is expected that it will be updated to also support a Config::Any approach.

SYNTAX SUGAR

db $DATABASE, containing { CONTENT }

Creates a database with the given name, and adds the content, unless it exists. Keep in mind that CouchDB databases must have a trailing slash in their names.

doc { CONTENT }

Creates a document with that content, unless it is there and up to date. Note that currently only documents with an _id field are supported (otherwise we couldn't do the create-unless-exists logic). The content is of the exact same structure as the JSON one would post to CouchDB.

file $PATH

Reads the file at $PATH, converts it to base64, and returns that on a single line. This is a helper made to assist in creating CouchDB attachments. Note that in the current state it will read the file into memory.

base64 $CONTENT

Returns the content encoded in single-line Base 64.

design { CONTENT }

Creates a design document with those views and parameters, unless it is there and up to date. The content is of the exact same structure as the JSON one would post to CouchDB, except that if the _id field does not start with _design/ it will be automatically added.

AUTHOR

Robin Berjon, <robin @t berjon d.t com>

BUGS

Please report any bugs or feature requests to bug-couchdb-deploy at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CouchDb-Deploy.

COPYRIGHT & LICENSE

Copyright 2008 Robin Berjon, all rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.