DBIx-Class

 view release on metacpan or  search on metacpan

lib/DBIx/Class/Schema/Versioned.pm  view on Meta::CPAN

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
 
use Time::HiRes qw/gettimeofday/;
use Scalar::Util 'weaken';
 
__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

437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
  $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

534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
    };
    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

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
DBIx::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 {
 
  require File::Spec;
  require File::Copy;
  require POSIX;
 
  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

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
    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

38
39
40
41
42
43
44
45
46
47
48
49
50
use strict;
 
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

46
47
48
49
50
51
52
53
54
55
56
57
58
use strict;
 
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 )