default => undef,
);
+has force_overwrite => (
+ isa => 'Bool',
+ is => 'ro',
+ default => undef,
+);
+
has schema => (
isa => 'DBIx::Class::Schema',
is => 'ro',
my $filename = $self->$to_file($db, $version, $dir);
if (-e $filename ) {
- carp "Overwriting existing DDL file - $filename";
- unlink $filename;
+ if ($self->force_overwrite) {
+ carp "Overwriting existing DDL file - $filename";
+ unlink $filename;
+ } else {
+ die "Cannot overwrite '$filename', either enable force_overwrite or delete it"
+ }
}
open my $file, q(>), $filename;
print {$file} join ";\n", @$sql;
foreach my $db (@$databases) {
my $diff_file = $self->$diff_file_method($db, $version_set, $dir );
if(-e $diff_file) {
- carp("Overwriting existing $direction-diff file - $diff_file");
- unlink $diff_file;
+ if ($self->force_overwrite) {
+ carp("Overwriting existing $direction-diff file - $diff_file");
+ unlink $diff_file;
+ } else {
+ die "Cannot overwrite '$diff_file', either enable force_overwrite or delete it"
+ }
}
open my $file, q(>), $diff_file;
unless $yml;
if (-e $filename ) {
- carp "Overwriting existing DDL-YML file - $filename";
- unlink $filename;
+ if ($self->force_overwrite) {
+ carp "Overwriting existing DDL-YML file - $filename";
+ unlink $filename;
+ } else {
+ die "Cannot overwrite '$filename', either enable force_overwrite or delete it"
+ }
}
open my $file, q(>), $filename;
probably the best plan of action as you will not be putting as many generated
files in your version control. Goes well with with C<databases> of C<[]>.
+=attr force_overwrite
+
+When this attribute is true generated files will be overwritten when the
+methods which create such files are run again. The default is false, in which
+case the program will die with a message saying which file needs to be deleted.
+
=attr schema
The L<DBIx::Class::Schema> (B<required>) that is used to talk to the database
ok -e 'foobar';
- {
- my $warned = 0;
- local $SIG{__WARN__} = sub{$warned = 1};
- $dm->prepare_deploy;
- ok( $warned, 'prepare_deploy warns if you run it twice' );
- }
+ dies_ok {$dm->prepare_deploy} 'prepare_deploy dies if you run it twice' ;
ok(
-f catfile(qw( t sql SQLite deploy 1.0 001-auto.sql )),
to_version => $version,
version_set => ['2.0', $version]
});
- {
- my $warned = 0;
- local $SIG{__WARN__} = sub{$warned = 1};
+ dies_ok {
$dm->prepare_upgrade({
from_version => '2.0',
to_version => $version,
version_set => ['2.0', $version]
});
- ok( $warned, 'prepare_upgrade warns if you clobber an existing upgrade file' );
- }
+ }
+ 'prepare_upgrade dies if you clobber an existing upgrade file' ;
ok(
-f catfile(qw( t sql SQLite upgrade 1.0-2.0 001-auto.sql )),
'2.0-3.0 diff gets generated properly'