1#!/usr/bin/env perl 2 3use strict; 4use warnings; 5 6use FindBin; 7FindBin::again(); 8use Path::Class 'dir'; 9 10BEGIN { 11 # stuff useful locations into @INC 12 unshift @INC, 13 dir($FindBin::RealBin)->parent->subdir('lib')->stringify, 14 dir($FindBin::RealBin, 'lib')->stringify; 15} 16 17use App::Netdisco; 18use Dancer ':script'; 19use Dancer::Plugin::DBIC 'schema'; 20 21use App::Netdisco::DB; 22use Getopt::Long; 23 24=head1 NAME 25 26nd-dbic-versions - Create DB Schema Versions for Netdisco 27 28=head1 USAGE 29 30This script creates SQL DDL files of the Netdisco database schema. 31 32If called without any CLI options, it makes one SQL DDL file which will 33initialize the complete schema to the current DBIx::Class specification. 34 35If called with the "-p <version>" option, upgrade SQL DDL command files 36are created between the specified version and the current DBIx::Class 37specification. 38 39=head1 NEW VERSION 40 41=over 4 42 43=item 1. 44 45Alter the DBIC DDL files as you wish. 46 47=item 2. 48 49Increment the Schema's C<$VERSION> number. 50 51=item 3. 52 53Run this script with "C<-p $current_db_version>". 54 55=back 56 57=cut 58 59my $sql_dir = $App::Netdisco::DB::schema_versions_dir; 60my $version = schema('netdisco')->schema_version; 61 62my ( $preversion, $help ); 63GetOptions( 64 'p|preversion:s' => \$preversion, 65) or do { 66 print <<ENDHELP; 67 $0 [-p <version>] 68 69 This script creates SQL DDL files of the Netdisco database schema. 70 71 If called without any CLI options, it makes one SQL DDL file which will 72 initialize the complete schema to the current DBIx::Class specification. 73 74 If called with the "-p <version>" option, upgrade SQL DDL command files 75 are created between the specified version and the current DBIx::Class 76 specification. 77 78 SQL DDL files are stored in: 79$sql_dir 80ENDHELP 81 exit(1); 82}; 83 84schema('netdisco')->create_ddl_dir( 85 'PostgreSQL', $version, $sql_dir, $preversion ); 86 87