aboutsummaryrefslogtreecommitdiff
path: root/perl/create-ddl
blob: 51fa8ffeb499da6bf6a498cc3220393d58c05a79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/perl -w
#
# Create DDL files for the wallet.
#
# Written by Jon Robertson <jonrober@stanford.edu>
# Copyright 2012, 2014
#     The Board of Trustees of the Leland Stanford Junior University
#
# See LICENSE for licensing terms.

#############################################################################
# Modules and declarations
#############################################################################

use strict;
use vars qw();

use lib 'lib';

use Getopt::Long;
use Wallet::Admin;

#############################################################################
# Main routine
#############################################################################

# Get errors and output in the same order.
$| = 0;

# Clean up the path name.
my $fullpath = $0;
$0 =~ s%^.*/%%;

# Parse command-line options.
my ($help);
my $oldversion = '';
Getopt::Long::config ('bundling');
GetOptions ('h|help'         => \$help,
            'o|oldversion=s' => \$oldversion) or exit 1;
if ($help) {
    print "Feeding myself to perldoc, please wait....\n";
    exec ('perldoc', '-t', $fullpath);
}

# Default wallet settings, for Wallet::Admin.
$Wallet::Config::DB_DDL_DIRECTORY = 'sql/';
$Wallet::Config::DB_DRIVER = 'SQLite';
$Wallet::Config::DB_INFO = 'wallet-db';

# Create a Wallet::Admin object and run the backup.
my $admin = Wallet::Admin->new;
$admin->backup ($oldversion);

exit(0);

##############################################################################
# Documentation
##############################################################################

=for stopwords
DDL create-ddl

=head1 NAME

create-ddl - Create DDL files for Wallet

=head1 SYNOPSIS

B<create-ddl> [B<--help>] [B<--oldversion>=I<version>]

=head1 DESCRIPTION

create-ddl is used to create DDL files for the various DBIx::Class
Wallet::Schema modules.  It simply is an interface for the backup command
in Wallet::Admin, which does the work via DBIx::Class.  The end result
is a number of files that can be used to load the database for each
supported database server.

These files can be modified after creation to customize the database
load, though should only be done when necessary to prevent confusion
for the schema modules not matching the actual table definitions.  This
is currently only done in the case of SQLite databases, due to the
SQLite parser creating keys without AUTOINCREMENT.

=head1 OPTIONS

=over 4

=item B<--help>

Prints the perldoc information (this document) for the script.

=item B<--oldversion>=I<version>

The version number of the previous version.  If there are existing DDL
files for this version, then we will also create diff files to upgrade
a database from the old version to the current.

=back

=head1 AUTHORS

Jon Robertson <jonrober@stanford.edu>

=cut