__PACKAGE__->mk_classdata('_filedata');
__PACKAGE__->mk_classdata('upgrade_directory');
+__PACKAGE__->mk_classdata('backup_directory');
sub on_connect
{
{
my ($self) = @_;
## Make each ::DBI::Foo do this
- $self->storage->backup();
+ $self->storage->backup($self->backup_directory());
}
sub upgrade
__PACKAGE__->load_components(qw/+DBIx::Class::Schema::Versioned/);
__PACKAGE__->upgrade_directory('/path/to/upgrades/');
+ __PACKAGE__->backup_directory('/path/to/backups/');
sub backup
{
path between the two versions supplied. By default, every change in
your VERSION is regarded as needing an upgrade.
+The actual upgrade is called manually by calling C<upgrade> on your
+schema object. Code is run at connect time to determine whether an
+upgrade is needed, if so, a warning "Versions out of sync" is
+produced.
+
NB: At the moment, SQLite upgrading is rather spotty, as SQL::Translator::Diff
returns SQL statements that SQLite does not support.
C<upgrade> method, running whichever commands you specify via the
regex in the parameter.
+=head2 upgrade_directory
+
+Use this to set the directory your upgrade files are stored in.
+
+=head2 backup_directory
+
+Use this to set the directory you want your backups stored in.
+
=head1 AUTHOR
Jess Robinson <castaway@desert-island.demon.co.uk>
sub backup
{
- my ($self) = @_;
+ my ($self, $dir) = @_;
+ $dir ||= './';
## Where is the db file?
my $dsn = $self->connect_info()->[0];
# print "Found database: $dbname\n";
# my $dbfile = file($dbname);
- my ($vol, $dir, $file) = File::Spec->splitpath($dbname);
+ my ($vol, $dbdir, $file) = File::Spec->splitpath($dbname);
# my $file = $dbfile->basename();
$file = strftime("%y%m%d%h%M%s", localtime()) . $file;
$file = "B$file" while(-f $file);
-
- my $res = copy($dbname, $file);
+
+ mkdir($dir) unless -f $dir;
+ my $backupfile = File::Spec->catfile($dir, $file);
+
+ my $res = copy($dbname, $backupfile);
$self->throw_exception("Backup failed! ($!)") if(!$res);
- return $file;
+ return $backupfile;
}
1;
$schema_upgrade->upgrade();
$tvrs = $schema_upgrade->resultset('Table');
is($schema_upgrade->exists($tvrs), 1, 'Upgraded schema from DDL file');
+
+unlink($db_file) if -e $db_file;
+unlink($db_file . "-journal") if -e $db_file . "-journal";
+unlink('t/var/DBICVersion-Schema-1.0-SQLite.sql');
+unlink('t/var/DBICVersion-Schema-2.0-SQLite.sql');
+unlink('t/var/DBICVersion-Schema-1.0-2.0-SQLite.sql');
+unlink(<t/var/backup/*>);
__PACKAGE__->register_class('Table', 'DBICVersion::Table');
__PACKAGE__->load_components('+DBIx::Class::Schema::Versioned');
+__PACKAGE__->upgrade_directory('t/var/');
+__PACKAGE__->backup_directory('t/var/backup/');
-sub upgrade_directory
-{
- return 't/var/';
-}
+#sub upgrade_directory
+#{
+# return 't/var/';
+#}
1;