DBIx-Class
view release on metacpan or search on metacpan
lib/DBIx/Class/Schema/Versioned.pm view on Meta::CPAN
202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234use
DBIx::Class::Carp;
use
Try::Tiny;
use
namespace::clean;
__PACKAGE__->mk_classdata(
'_filedata'
);
__PACKAGE__->mk_classdata(
'upgrade_directory'
);
__PACKAGE__->mk_classdata(
'backup_directory'
);
__PACKAGE__->mk_classdata(
'do_backup'
);
__PACKAGE__->mk_classdata(
'do_diff_on_init'
);
=head1 METHODS
=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 (note that backups
are disabled by default).
=cut
=head2 install
=over 4
=item Arguments: $db_version
lib/DBIx/Class/Schema/Versioned.pm view on Meta::CPAN
437438439440441442443444445446447448449450451452453454455456457458459
$self
->create_upgrade_path({
upgrade_file
=>
$upgrade_file
});
unless
(-f
$upgrade_file
) {
carp
"Upgrade not possible, no upgrade file found ($upgrade_file), please create one"
;
return
;
}
carp
"DB version ($db_version) is lower than the schema version ("
.
$self
->schema_version.
"). Attempting upgrade.\n"
;
# backup if necessary then apply upgrade
$self
->_filedata(
$self
->_read_sql_file(
$upgrade_file
));
$self
->backup()
if
(
$self
->do_backup);
$self
->txn_do(
sub
{
$self
->do_upgrade() });
# set row in dbix_class_schema_versions table
$self
->_set_db_version({
version
=>
$target_version
});
}
=head2 do_upgrade
This is an overwritable method used to run your upgrade. The freeform method
allows you to run your upgrade any way you please, you can call C<run_upgrade>
lib/DBIx/Class/Schema/Versioned.pm view on Meta::CPAN
534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
};
return
$version
|| 0;
}
=head2 schema_version
Returns the current schema class' $VERSION
=cut
=head2 backup
This is an overwritable method which is called just before the upgrade, to
allow you to make a backup of the database. Per default this method attempts
to call C<< $self->storage->backup >>, to run the standard backup on each
database type.
This method should return the name of the backup file, if appropriate..
This method is disabled by default. Set $schema->do_backup(1) to enable it.
=cut
sub
backup
{
my
(
$self
) =
@_
;
## Make each ::DBI::Foo do this
$self
->storage->backup(
$self
->backup_directory());
}
=head2 connection
Overloaded method. This checks the DBIC schema version against the DB version and
warns if they are not the same or if the DB is unversioned. It also provides
compatibility between the old versions table (SchemaVersions) and the new one
(dbix_class_schema_versions).
To avoid the checks on connect, set the environment var DBIC_NO_VERSION_CHECK or alternatively you can set the ignore_version attr in the forth argument like so:
lib/DBIx/Class/Storage/DBI/SQLite.pm view on Meta::CPAN
717273747576777879808182838485868788899091DBIx::Class warned about this condition
for
several years, hoping to give
anyone affected sufficient notice of the potential issues. The warning was
removed in 2015/v0.082820.
=back
=head1 METHODS
=cut
sub
backup {
my
(
$self
,
$dir
) =
@_
;
$dir
||=
'./'
;
## Where is the db file?
my
$dsn
=
$self
->_dbi_connect_info()->[0];
lib/DBIx/Class/Storage/DBI/SQLite.pm view on Meta::CPAN
99100101102103104105106107108109110111112113114115116117118119120121122123124
if
(!
$dbname
|| !-f
$dbname
);
# print "Found database: $dbname\n";
# my $dbfile = file($dbname);
my
(
$vol
,
$dbdir
,
$file
) = File::Spec->splitpath(
$dbname
);
# my $file = $dbfile->basename();
$file
= POSIX::strftime(
"%Y-%m-%d-%H_%M_%S"
,
localtime
()) .
$file
;
$file
=
"B$file"
while
(-f
$file
);
mkdir
(
$dir
)
unless
-f
$dir
;
my
$backupfile
= File::Spec->catfile(
$dir
,
$file
);
my
$res
= File::Copy::copy(
$dbname
,
$backupfile
);
$self
->throw_exception(
"Backup failed! ($!)"
)
if
(!
$res
);
return
$backupfile
;
}
sub
_exec_svp_begin {
my
(
$self
,
$name
) =
@_
;
$self
->_dbh->
do
(
"SAVEPOINT $name"
);
}
sub
_exec_svp_release {
my
(
$self
,
$name
) =
@_
;
t/lib/DBICVersion_v2.pm view on Meta::CPAN
38394041424344454647484950package
DBICVersion::Schema;
use
strict;
use
warnings;
our
$VERSION
=
'2.0'
;
__PACKAGE__->register_class(
'Table'
,
'DBICVersion::Table'
);
__PACKAGE__->load_components(
'+DBIx::Class::Schema::Versioned'
);
__PACKAGE__->upgrade_directory(
"t/var/versioning_ddl-$$"
);
__PACKAGE__->backup_directory(
"t/var/versioning_backup-$$"
);
1;
t/lib/DBICVersion_v3.pm view on Meta::CPAN
46474849505152535455565758package
DBICVersion::Schema;
use
strict;
use
warnings;
our
$VERSION
=
'3.0'
;
__PACKAGE__->register_class(
'Table'
,
'DBICVersion::Table'
);
__PACKAGE__->load_components(
'+DBIx::Class::Schema::Versioned'
);
__PACKAGE__->upgrade_directory(
"t/var/versioning_ddl-$$"
);
__PACKAGE__->backup_directory(
"t/var/versioning_backup-$$"
);
1;
( run in 0.379 second using v1.01-cache-2.11-cpan-87723dcf8b7 )