Subversion Repositories VORC

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
206 - 1
#!/usr/bin/perl
2
 
3
use strict;
4
use cPanelUserConfig;
5
use DBI;
6
use WebDB;
7
 
8
my $host_name = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "localhost" : "192.168.1.5";
9
$ENV{HOME} = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco" : "/tmp";
10
 
11
my $dbh = WebDB::connect ("vorc", "OG");
12
my $table = shift // "";
13
my @tables;
14
 
15
push @tables, $table ? $table : map { @{$_} } @{$dbh->selectall_arrayref ("show tables")};
16
 
17
print "Creating database structure documentation:\n";
18
foreach my $table (@tables) {
19
  my $filename = "db/".$table.".sql";
20
  open(FH, '>', $filename);
21
  my $object_type = ($table =~ /^v_/) ? "View" : "Table";
22
  print "  ...for $object_type $table in file $filename.\n";
23
 
24
  print FH "## $object_type: $table\n#\n";
25
  foreach my $line (`/usr/bin/mysql --defaults-file=$ENV{HOME}/.my.cnf rollerco_vorc -h $host_name -t -e "describe $table"`) {
26
    print FH "# ".$line;
27
  }
28
  print FH "\n";
29
  my ($name, $structure, $charset, $colation) = $dbh->selectrow_array ("show create ".lc ($object_type)." ".$table);
30
  if ($object_type eq "View") {
31
    $structure =~ s/^CREATE .+? VIEW/CREATE OR REPLACE VIEW/;
32
  } else {
33
    $structure =~ s/AUTO_INCREMENT=\d+/AUTO_INCREMENT=0/;
34
  }
35
  print FH $structure."\n";
36
 
37
  close (FH);
38
}
39
print "fin.\n";