| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package DBIx::Changeset; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 12 |  |  | 12 |  | 319300 | use warnings; | 
|  | 12 |  |  |  |  | 28 |  | 
|  | 12 |  |  |  |  | 420 |  | 
| 4 | 12 |  |  | 12 |  | 62 | use strict; | 
|  | 12 |  |  |  |  | 26 |  | 
|  | 12 |  |  |  |  | 1816 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 12 |  |  | 12 |  | 14228 | use Data::Phrasebook; | 
|  | 12 |  |  |  |  | 22822 |  | 
|  | 12 |  |  |  |  | 373 |  | 
| 7 | 12 |  |  | 12 |  | 10487 | use File::ShareDir qw(dist_file); | 
|  | 12 |  |  |  |  | 90908 |  | 
|  | 12 |  |  |  |  | 1068 |  | 
| 8 | 12 |  |  | 12 |  | 124 | use File::Spec; | 
|  | 12 |  |  |  |  | 26 |  | 
|  | 12 |  |  |  |  | 312 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 12 |  |  | 12 |  | 63 | use base qw/Class::Accessor DBIx::Changeset::Exception/; | 
|  | 12 |  |  |  |  | 25 |  | 
|  | 12 |  |  |  |  | 12749 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 12 |  |  | 12 |  | 2078 | use vars qw{$VERSION}; | 
|  | 12 |  |  |  |  | 26 |  | 
|  | 12 |  |  |  |  | 584 |  | 
| 14 |  |  |  |  |  |  | BEGIN { | 
| 15 | 12 |  |  | 12 |  | 214 | $VERSION = '1.11'; | 
| 16 |  |  |  |  |  |  | } | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =head1 NAME | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | DBIx::Changeset - Discrete management for database changes. | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =cut | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 12 |  |  | 12 |  | 262 | use 5.008000; | 
|  | 12 |  |  |  |  | 41 |  | 
|  | 12 |  |  |  |  | 3691 |  | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | my @ACCESSORS = qw/changeset_location create_template history_db_user history_db_password history_db_dsn/; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | __PACKAGE__->mk_accessors(@ACCESSORS); | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | You probably want to use dbix_changeset.pl from the command line. | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | dbix_changeset.pl --help | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | DBIx::Changeset provides an application to aid with the distrubution and application of database | 
| 40 |  |  |  |  |  |  | schemas and schema data as incremental updates. A Changeset is a discrete chunk of sql stored | 
| 41 |  |  |  |  |  |  | in a file with a unique id. DBIx::Changeset will compare a list of changesets against a table of | 
| 42 |  |  |  |  |  |  | applied changesets and apply the differences using the target databases native sql insertion tool | 
| 43 |  |  |  |  |  |  | in order. This greatly aids the distrubted development of a database application. | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | =head2 Example | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | User A creates a schema change in his development environment and applies it. Alls good so he checks | 
| 48 |  |  |  |  |  |  | in the changeset file. User B does a checkout on his development environment and runs the changeset | 
| 49 |  |  |  |  |  |  | update which notices User A's changeset and applies it. User B's development database is now the same | 
| 50 |  |  |  |  |  |  | as User A's. The database schema/schema data is in sync with the code logic. | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | DBIx::Changeset does not include an undo feature as it is dealing with schema changes this could cause | 
| 53 |  |  |  |  |  |  | data loss so is actually an update. | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | DBIx::Changeset uses a table to store the history of which changesets have been applied, while this | 
| 56 |  |  |  |  |  |  | is normally in the target database in can be set to another location. | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | DBIx::Changeset Currently supports MySQL,Postgres and SQLlite, but should be easy to port to other | 
| 59 |  |  |  |  |  |  | databases. | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =head1 USAGE | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =head2 Setting up a Database for Changeset | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | DBIx::Changeset requires a table to store the history of applied changesets. Changeset will | 
| 66 |  |  |  |  |  |  | add this table for you with the bootstrap command. It requires several options: | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | --history_db_dsn           DBI DSN for the history db | 
| 69 |  |  |  |  |  |  | --history_db_user          db user for history db | 
| 70 |  |  |  |  |  |  | --history_db_password      db password for the history db user | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =head2 Creating a Changeset | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | To create a new empty changeset file from the given template use the create command. | 
| 76 |  |  |  |  |  |  | It has several required options: | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | --location      Path to changeset files | 
| 79 |  |  |  |  |  |  | --template      Path to changeset template | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | The location is the path were the changeset files are stored and the template is a the path to a file | 
| 82 |  |  |  |  |  |  | that is used as the template. There are a couple of optional parameters: | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | --edit          Call editor | 
| 85 |  |  |  |  |  |  | --editor        Path to Editor | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | This loads the created delta up in the choses editor. | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | --vcs           Add to version control | 
| 90 |  |  |  |  |  |  | --vcsadd        Command to add to version control | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | These add the created delta file to your vcs using the command given by the vcsadd option. | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =head2 Comparing a database | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | To compare a database to a set of changeset files, you use the compare command. | 
| 98 |  |  |  |  |  |  | It has a few required options: | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | --location                 Path to changeset files | 
| 101 |  |  |  |  |  |  | --history_db_dsn           DBI DSN for the history db | 
| 102 |  |  |  |  |  |  | --history_db_user          db user for history ddb | 
| 103 |  |  |  |  |  |  | --history_db_password      db password for the history db user | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | There are also a couple of other useful options: | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | --type		               Which factory to use (default disk) | 
| 108 |  |  |  |  |  |  | --like                     only types matching regex | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | =head2 Updating a database | 
| 111 |  |  |  |  |  |  | To update a database based on changeset files use the update command. The update command | 
| 112 |  |  |  |  |  |  | has several required options: | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | --location                 Path to changeset files | 
| 115 |  |  |  |  |  |  | --type                     Which factory to use (default disk) | 
| 116 |  |  |  |  |  |  | --loader                   Which loader factory to use (default mysql) | 
| 117 |  |  |  |  |  |  | --like                     only types matching regex | 
| 118 |  |  |  |  |  |  | --history_db_dsn           DBI DSN for the history db | 
| 119 |  |  |  |  |  |  | --history_db_user          db user for history db | 
| 120 |  |  |  |  |  |  | --history_db_password      db password for the history db user | 
| 121 |  |  |  |  |  |  | --db_name                  db name for update db | 
| 122 |  |  |  |  |  |  | --db_host                  db host for update db | 
| 123 |  |  |  |  |  |  | --db_user                  db user for update db | 
| 124 |  |  |  |  |  |  | --db_password              db password for the update db user | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | =head3 | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | =head1 ACCESSORS | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | =head2 db_user | 
| 131 |  |  |  |  |  |  | the db_user | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | =head2 db_password | 
| 134 |  |  |  |  |  |  | the db_password | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | =head2 db_uri | 
| 137 |  |  |  |  |  |  | the db_uri | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | =head2 changeset_location | 
| 140 |  |  |  |  |  |  | the location of the changeset files, in a format the DBIx::Changeset::File factory object will be expecting | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | =cut | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | sub _connect_to_db { | 
| 145 | 1 |  |  | 1 |  | 3 | my $self = shift; | 
| 146 |  |  |  |  |  |  |  | 
| 147 | 1 |  |  |  |  | 12 | my $dbh = DBI->connect($self->history_db_dsn, $self->history_db_user, $self->history_db_password, { | 
| 148 |  |  |  |  |  |  | PrintError  => 0, | 
| 149 |  |  |  |  |  |  | RaiseError  => 0, | 
| 150 |  |  |  |  |  |  | HandleError => Exception::Class::DBI->handler, | 
| 151 |  |  |  |  |  |  | }); | 
| 152 |  |  |  |  |  |  |  | 
| 153 | 0 | 0 |  |  |  |  | if ( defined $dbh ) { | 
| 154 | 0 |  |  |  |  |  | $self->dbh($dbh); | 
| 155 |  |  |  |  |  |  | ### setup our sql lib object with normal and if exists specific to this db type | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | ## query the DB type from the DBD handle - info key 17 | 
| 158 | 0 |  |  |  |  |  | my $dbtype = $self->dbh->get_info( 17 ); | 
| 159 | 0 |  |  |  |  |  | eval { | 
| 160 | 0 |  |  |  |  |  | $self->pb(Data::Phrasebook->new( | 
| 161 |  |  |  |  |  |  | class => 'SQL', | 
| 162 |  |  |  |  |  |  | dbh => $self->dbh, | 
| 163 |  |  |  |  |  |  | loader => 'YAML', | 
| 164 |  |  |  |  |  |  | file => dist_file('DBIx-Changeset', 'changeset_history.yml'), | 
| 165 |  |  |  |  |  |  | dict   => $dbtype) ); | 
| 166 |  |  |  |  |  |  | }; | 
| 167 | 0 | 0 |  |  |  |  | if ( $@ ) { | 
| 168 | 0 |  |  |  |  |  | DBIx::Changeset::Exception::ObjectCreateException->throw(error => sprintf('Could not load SQL phrasebook because: %s.', $@)); | 
| 169 |  |  |  |  |  |  | } | 
| 170 |  |  |  |  |  |  | } else { | 
| 171 | 0 |  |  |  |  |  | DBIx::Changeset::Exception::ObjectCreateException->throw(error => 'Could not connect to db.'); | 
| 172 |  |  |  |  |  |  | } | 
| 173 |  |  |  |  |  |  |  | 
| 174 | 0 |  |  |  |  |  | return; | 
| 175 |  |  |  |  |  |  | } | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | =head1 SUPPORT | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | Please report any bugs or feature requests via the CPAN bug tracker | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | L | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | =head1 AUTHORS | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | Mike Bissett, Stephen Steneker, Paul Puse | 
| 186 |  |  |  |  |  |  | C<<  >> | 
| 187 |  |  |  |  |  |  |  | 
| 188 |  |  |  |  |  |  | =head1 ACKNOWLEDGEMENTS | 
| 189 |  |  |  |  |  |  |  | 
| 190 |  |  |  |  |  |  | Thank you to Grox (L) for permitting | 
| 191 |  |  |  |  |  |  | the open sourcing and release of this distribution. | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | =head1 COPYRIGHT & LICENSE | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | Copyright 2004-2008 Grox Pty Ltd. | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 198 |  |  |  |  |  |  | under the same terms as Perl itself. | 
| 199 |  |  |  |  |  |  |  | 
| 200 |  |  |  |  |  |  | The full text of the license can be found in the LICENSE file included with this module. | 
| 201 |  |  |  |  |  |  |  | 
| 202 |  |  |  |  |  |  | =cut | 
| 203 |  |  |  |  |  |  |  | 
| 204 |  |  |  |  |  |  | 1; # End of DBIx::Changeset |