Downgrade global version - highest version in 9002 on cpan is 1.58 - thus go with...
[dbsrgits/SQL-Translator.git] / bin / sqlt-dumper
CommitLineData
354b1807 1#!/usr/bin/perl
2
3# -------------------------------------------------------------------
478f608d 4# Copyright (C) 2002-2009 SQLFairy Authors
354b1807 5#
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of the GNU General Public License as
8# published by the Free Software Foundation; version 2.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18# 02111-1307 USA
19# -------------------------------------------------------------------
20
21=head1 NAME
22
23sqlt-dumper - create a dumper script from a schema
24
25=head1 SYNOPSIS
26
27 sqlt-dumper -d Oracle [options] schema.sql > dumper.pl
28
29 ./dumper.pl > data.sql
30
31 Options:
32
5a3f5c82 33 -h|--help Show help and exit
34 --skip=t1[,t2] Skip tables in comma-separated list
35 --skiplike=regex Skip tables matching the regular expression
36 -u|--user Database username
37 -p|--password Database password
38 --dsn DSN for DBI
354b1807 39
40=head1 DESCRIPTION
41
42This script uses SQL::Translator to parse the SQL schema and create a
43Perl script that can connect to the database and dump the data as
5a3f5c82 44INSERT statements (a la mysqldump) or MySQL's LOAD FILE syntax. You may
45specify tables to "skip" (also using a "skiplike" regular expression)
46and the generated dumper script will not have those tables. However,
47these will also be options in the generated dumper, so you can wait to
48specify these options when you dump your database. The database
49username, password, and DSN can be hardcoded into the generated
50script, or part of the DSN can be intuited from the "database"
51argument.
354b1807 52
53=cut
54
55# -------------------------------------------------------------------
56
57use strict;
58use Pod::Usage;
59use Getopt::Long;
60use SQL::Translator;
aba9fea4 61use File::Basename qw(basename);
354b1807 62
da06ac74 63use vars '$VERSION';
4ab3763d 64$VERSION = '1.59';
da06ac74 65
5a3f5c82 66my ( $help, $db, $skip, $skiplike, $db_user, $db_pass, $dsn );
354b1807 67GetOptions(
68 'h|help' => \$help,
69 'd|f|from|db=s' => \$db,
354b1807 70 'skip:s' => \$skip,
5a3f5c82 71 'skiplike:s' => \$skiplike,
354b1807 72 'u|user:s' => \$db_user,
73 'p|password:s' => \$db_pass,
74 'dsn:s' => \$dsn,
75) or pod2usage;
76
77pod2usage(0) if $help;
78pod2usage( 'No database driver specified' ) unless $db;
79$db_user ||= 'username';
80$db_pass ||= 'password';
81$dsn ||= "dbi:$db:_";
82
5a3f5c82 83my $file = shift @ARGV or pod2usage( -msg => 'No input file' );
84my $t = SQL::Translator->new(
85 from => $db,
86 to => 'Dumper',
87 producer_args => {
88 skip => $skip,
89 skiplike => $skiplike,
90 db_user => $db_user,
91 db_password => $db_pass,
92 dsn => $dsn,
354b1807 93 }
5a3f5c82 94);
354b1807 95
5a3f5c82 96print $t->translate( $file );
354b1807 97
354b1807 98exit(0);
99
100# -------------------------------------------------------------------
101
102=pod
103
104=head1 AUTHOR
105
106Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
107
108=head1 SEE ALSO
109
5a3f5c82 110perl, SQL::Translator, SQL::Translator::Producer::Dumper.
354b1807 111
112=cut