LasTres/script/prepare.pl

40 lines
857 B
Perl
Raw Permalink Normal View History

2023-06-01 08:45:43 +02:00
#!/usr/bin/env perl
2023-06-08 09:02:32 +02:00
2023-06-01 08:45:43 +02:00
use strict;
use warnings;
use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
use Getopt::Long;
use FindBin;
use lib "$FindBin::Bin/../lib";
use LasTres::Schema;
2023-06-08 09:02:32 +02:00
2023-06-01 08:45:43 +02:00
my $force_overwrite = 1;
2023-06-08 09:02:32 +02:00
2023-06-01 08:45:43 +02:00
unless ( GetOptions( 'force_overwrite!' => \$force_overwrite ) ) {
die "Invalid options";
}
2023-06-08 09:02:32 +02:00
2023-06-01 08:45:43 +02:00
my $schema = LasTres::Schema->Schema;
2023-06-08 09:02:32 +02:00
2023-06-01 08:45:43 +02:00
my $dh = DH->new(
{
schema => $schema,
script_directory => "$FindBin::Bin/../dbicdh",
databases => 'PostgreSQL',
sql_translator_args => { add_drop_table => 0 },
force_overwrite => $force_overwrite,
}
);
2023-06-08 09:02:32 +02:00
2023-06-01 08:45:43 +02:00
$dh->prepare_deploy;
eval {
2023-06-08 09:02:32 +02:00
$dh->prepare_upgrade({
from_version => $LasTres::Schema::VERSION - 1,
to_version => $LasTres::Schema::VERSION
});
2023-06-01 08:45:43 +02:00
};
if ($@) {
2023-06-08 09:02:32 +02:00
print "$@\n";
2023-06-01 08:45:43 +02:00
$dh->prepare_install;
}