-
Notifications
You must be signed in to change notification settings - Fork 51
/
clone_sql.pl
executable file
·71 lines (51 loc) · 1.46 KB
/
clone_sql.pl
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
#!/usr/bin/perl -w
=head1 NAME
clone_db.pl - installation script to clone an existing database
=head1 VERSION
$Revision: 1.2 $
=head1 DATE
$Date: 2003-06-13 16:49:12 $
=head1 DESCRIPTION
This script is called during "make clone" to clone the Bricolage
database.
=head1 AUTHOR
Sam Tregar <stregar@about-inc.com>
=head1 SEE ALSO
L<Bric::Admin>
=cut
use strict;
use FindBin;
use lib "$FindBin::Bin/lib";
use Bric::Inst qw(:all);
use File::Spec::Functions qw(:ALL);
use File::Find qw(find);
use DBI;
print "\n\n==> Cloning Bricolage Database <==\n\n";
our $PG;
do "./postgres.db" or die "Failed to read postgres.db : $!";
# dump out database (NOTE: when the installer uses psql to load
# Pg.sql drop the -d for a speedup)
system(catfile($PG->{bin_dir}, 'pg_dump') .
" -U$PG->{root_user} -O -x -d $PG->{db_name} > inst/Pg.sql.tmp");
# fix problem with the Usr table's circular dependecy on login_avail().
open(TMP, "inst/Pg.sql.tmp") or die $!;
open(SQL, ">inst/Pg.sql") or die $!;
my $last;
while(<TMP>) {
if (/CONSTRAINT\s+"?ck_usr__login"?/) {
$last =~ s/,\s*$//;
print SQL $last if $last;
$last = '';
} else {
print SQL $last if $last;
$last = $_;
}
}
print SQL $last if $last;
close TMP;
print SQL "\nALTER TABLE usr ADD CONSTRAINT ck_usr__login ",
"CHECK (login_avail(LOWER(login), active, id));\n";
close SQL;
unlink "inst/Pg.sql.tmp" or die $!;
print "\n\n==> Finished Cloning Bricolage Database <==\n\n";
exit 0;