Blame | Last modification | View Log | RSS feed
#!/usr/bin/perluse strict;use cPanelUserConfig;use DBI;use WebDB;my $host_name = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "localhost" : "192.168.1.5";$ENV{HOME} = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco" : "/tmp";my $dbh = WebDB::connect ("vorc", "OG");my $table = shift // "";my @tables;push @tables, $table ? $table : map { @{$_} } @{$dbh->selectall_arrayref ("show tables")};print "Creating database structure documentation:\n";foreach my $table (@tables) {my $filename = "db/".$table.".sql";open(FH, '>', $filename);my $object_type = ($table =~ /^v_/) ? "View" : "Table";print " ...for $object_type $table in file $filename.\n";print FH "## $object_type: $table\n#\n";foreach my $line (`/usr/bin/mysql --defaults-file=$ENV{HOME}/.my.cnf rollerco_vorc -h $host_name -t -e "describe $table"`) {print FH "# ".$line;}print FH "\n";my ($name, $structure, $charset, $colation) = $dbh->selectrow_array ("show create ".lc ($object_type)." ".$table);if ($object_type eq "View") {$structure =~ s/^CREATE .+? VIEW/CREATE OR REPLACE VIEW/;} else {$structure =~ s/AUTO_INCREMENT=\d+/AUTO_INCREMENT=0/;}print FH $structure."\n";close (FH);}print "fin.\n";