OwlcodeAds/script/prepare.pl
2023-08-02 16:19:44 +02:00

48 lines
1.0 KiB
Perl

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