init
This commit is contained in:
92
livejournal/doc/raw/int/db/db2ref.xsl
Executable file
92
livejournal/doc/raw/int/db/db2ref.xsl
Executable file
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!-- LiveJournal XSLT stylesheet created by Tribeless Nomad (AJW) -->
|
||||
<!-- converts DB schema documentation from custom XML to DocBook XML -->
|
||||
<!-- The source document should comply with dbschema.dtd version 1.0.4. -->
|
||||
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
||||
<xsl:output method="xml" indent="yes" />
|
||||
|
||||
<xsl:template match="/">
|
||||
|
||||
<!-- W3C-compliant processors emit an XML declaration by default. -->
|
||||
|
||||
<reference>
|
||||
<title>Schema Browser</title>
|
||||
<xsl:for-each select="dbschema/dbtbl">
|
||||
<refentry><xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
|
||||
<refnamediv>
|
||||
<refname><database class="table"><xsl:value-of select="name"/></database></refname>
|
||||
<refpurpose><xsl:apply-templates select="description/node()"/></refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title><database class="table"><xsl:value-of select="name"/></database></title>
|
||||
<informaltable><tgroup cols="5">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Column name</entry>
|
||||
<entry>Type</entry>
|
||||
<entry>Null</entry>
|
||||
<entry>Default</entry>
|
||||
<entry>Description</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<xsl:for-each select="dbcol">
|
||||
<row>
|
||||
<entry><database class="field"><xsl:value-of select="name"/></database></entry>
|
||||
<entry><type><xsl:value-of select="@type"/></type></entry>
|
||||
<entry align="center"><xsl:if test="@required[.='false']">YES</xsl:if></entry>
|
||||
<entry align="center"><xsl:if test="@default"><literal role="value"><xsl:value-of select="@default"/></literal></xsl:if></entry>
|
||||
<entry><xsl:apply-templates select="description/node()"/></entry>
|
||||
</row>
|
||||
</xsl:for-each>
|
||||
</tbody>
|
||||
</tgroup></informaltable>
|
||||
<xsl:choose>
|
||||
<xsl:when test="dbkey">
|
||||
<informaltable><tgroup cols="3">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Key name</entry>
|
||||
<entry>Type</entry>
|
||||
<entry>Column(s)</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<xsl:for-each select="dbkey">
|
||||
<row>
|
||||
<entry>
|
||||
<database class="key1"><xsl:value-of select="@name"/></database>
|
||||
</entry>
|
||||
<entry>
|
||||
<type><xsl:value-of select="@type"/></type>
|
||||
</entry>
|
||||
<entry>
|
||||
<xsl:for-each select="id(@colids)">
|
||||
<database class="field"><xsl:value-of select="name"/></database>
|
||||
|
||||
<xsl:if test="position() != last()">, </xsl:if>
|
||||
</xsl:for-each>
|
||||
</entry>
|
||||
</row>
|
||||
</xsl:for-each>
|
||||
</tbody>
|
||||
</tgroup></informaltable>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<para>No keys defined.</para>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
</xsl:for-each>
|
||||
</reference>
|
||||
</xsl:template>
|
||||
<xsl:template match="dbtblref"><link><xsl:attribute name="linkend"><xsl:value-of select="@tblid"/></xsl:attribute><database class="table"><xsl:value-of select="."/></database></link></xsl:template>
|
||||
<xsl:template match="dbcolref"><database class="field"><xsl:value-of select="."/></database></xsl:template>
|
||||
|
||||
<!-- I don't think the following template should be necessary, but in IE5 it is: -->
|
||||
<xsl:template match="text()"><xsl:value-of select="."/></xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
35
livejournal/doc/raw/int/db/dbschema.dtd
Executable file
35
livejournal/doc/raw/int/db/dbschema.dtd
Executable file
@@ -0,0 +1,35 @@
|
||||
<!-- DTD for LiveJournal database schema documentation in XML -->
|
||||
<!-- draft version created by Tribeless Nomad (AJW), April 30, 2001 -->
|
||||
<!-- Send questions and comments to: tribelessnomad (at) att.net -->
|
||||
|
||||
<!-- Revision history:
|
||||
1.0.2 2001 May 1 AJW modified dbtbl, dbcol, dbkey, dbtblref, dbcolref
|
||||
1.0.1 2001 May 1 AJW added dbkey, modified dbtbl, dbcol
|
||||
1.0.0 2001 Apr 30 AJW released first draft version
|
||||
-->
|
||||
|
||||
<!-- Documents are expected to use 'dbschema' as the root element. -->
|
||||
|
||||
<!ELEMENT dbschema (dbtbl+)>
|
||||
|
||||
<!ELEMENT dbtbl (name, description?, dbcol+, dbkey*, data?)>
|
||||
<!ATTLIST dbtbl id ID #IMPLIED public_browsable (0|1) #IMPLIED>
|
||||
|
||||
<!ELEMENT dbcol (name, description?)>
|
||||
<!ATTLIST dbcol type CDATA #REQUIRED size CDATA #IMPLIED required (true|false) #REQUIRED default CDATA #IMPLIED>
|
||||
|
||||
<!ELEMENT dbkey EMPTY>
|
||||
<!ATTLIST dbkey name NMTOKEN #IMPLIED type (INDEX|UNIQUE|PRIMARY) #REQUIRED colids IDREFS #REQUIRED>
|
||||
|
||||
<!ELEMENT data ANY>
|
||||
|
||||
<!ELEMENT name (#PCDATA)>
|
||||
|
||||
<!ELEMENT description (#PCDATA | dbtblref | dbcolref)*>
|
||||
|
||||
<!ELEMENT dbtblref (#PCDATA)>
|
||||
<!ATTLIST dbtblref tblid IDREF #REQUIRED>
|
||||
|
||||
<!ELEMENT dbcolref (#PCDATA)>
|
||||
<!ATTLIST dbcolref colid IDREF #REQUIRED>
|
||||
|
||||
126
livejournal/doc/raw/int/db/dbschema.pl
Executable file
126
livejournal/doc/raw/int/db/dbschema.pl
Executable file
@@ -0,0 +1,126 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
|
||||
use strict;
|
||||
|
||||
require "$ENV{'LJHOME'}/cgi-bin/ljlib.pl";
|
||||
|
||||
my $dbr = LJ::get_dbh("slave", "master");
|
||||
my $sth;
|
||||
|
||||
sub magic_links
|
||||
{
|
||||
my $des = shift;
|
||||
$$des =~ s!table\[(\w+?)\]!<dbtblref tblid="_$1">$1</dbtblref>!g;
|
||||
}
|
||||
|
||||
sub dump_xml
|
||||
{
|
||||
my $tables = shift;
|
||||
|
||||
print "<?xml version=\"1.0\" ?>\n";
|
||||
print "<!DOCTYPE dbschema SYSTEM \"dbschema.dtd\">\n";
|
||||
print "<dbschema>\n";
|
||||
foreach my $table (sort keys %$tables)
|
||||
{
|
||||
print "<dbtbl id=\"_$table\">\n";
|
||||
|
||||
# table name
|
||||
print "<name>$table</name>\n";
|
||||
|
||||
# description of table
|
||||
if ($tables->{$table}->{'des'}) {
|
||||
my $des = $tables->{$table}->{'des'};
|
||||
&magic_links(\$des);
|
||||
print "<description>$des</description>\n";
|
||||
}
|
||||
|
||||
# columns
|
||||
foreach my $col (@{$tables->{$table}->{'cols'}})
|
||||
{
|
||||
print "<dbcol id=\"_$table.$col->{'name'}\" type=\"$col->{'type'}\" required=\"$col->{'required'}\" default=\"$col->{'default'}\">\n";
|
||||
print "<name>$col->{'name'}</name>\n";
|
||||
if ($col->{'des'}) {
|
||||
my $des = $col->{'des'};
|
||||
&magic_links(\$des);
|
||||
print "<description>$des</description>\n";
|
||||
}
|
||||
print "</dbcol>\n";
|
||||
}
|
||||
|
||||
# indexes
|
||||
foreach my $indexname (sort keys %{$tables->{$table}->{'index'}})
|
||||
{
|
||||
my $index = $tables->{$table}->{'index'}->{$indexname};
|
||||
|
||||
print "<dbkey name=\"$indexname\" type=\"$index->{'type'}\" colids=\"", join(" ", @{$index->{'cols'}}), "\" />\n";
|
||||
}
|
||||
|
||||
print "</dbtbl>\n";
|
||||
}
|
||||
print "</dbschema>\n";
|
||||
}
|
||||
|
||||
my %table;
|
||||
my %coldes;
|
||||
|
||||
$sth = $dbr->prepare("SHOW TABLES");
|
||||
$sth->execute;
|
||||
while (my ($table) = $sth->fetchrow_array) {
|
||||
$table{$table} = {};
|
||||
}
|
||||
|
||||
$sth = $dbr->prepare("SELECT tablename, public_browsable, des FROM schematables");
|
||||
$sth->execute;
|
||||
while (my ($name, $public, $des) = $sth->fetchrow_array) {
|
||||
next unless (defined $table{$name});
|
||||
$table{$name} = { 'public' => $public, 'des' => $des };
|
||||
}
|
||||
|
||||
$sth = $dbr->prepare("SELECT tablename, colname, des FROM schemacols");
|
||||
$sth->execute;
|
||||
while (my ($table, $col, $des) = $sth->fetchrow_array) {
|
||||
next unless (defined $table{$table});
|
||||
$coldes{$table}->{$col} = $des;
|
||||
}
|
||||
|
||||
foreach my $table (sort keys %table)
|
||||
{
|
||||
$sth = $dbr->prepare("DESCRIBE $table");
|
||||
$sth->execute;
|
||||
while (my $r = $sth->fetchrow_hashref)
|
||||
{
|
||||
my $col = {};
|
||||
$col->{'name'} = $r->{'Field'};
|
||||
|
||||
my $type = $r->{'Type'};
|
||||
$type =~ s/int\(\d+\)/int/g;
|
||||
if ($r->{'Extra'} eq "auto_increment") {
|
||||
$type .= " auto_increment";
|
||||
}
|
||||
$col->{'type'} = $type;
|
||||
|
||||
$col->{'default'} = $r->{'Default'};
|
||||
$col->{'required'} = $r->{'Null'} eq "YES" ? "false" : "true";
|
||||
|
||||
$col->{'des'} = $coldes{$table}->{$r->{'Field'}};
|
||||
|
||||
push @{$table{$table}->{'cols'}}, $col;
|
||||
}
|
||||
|
||||
$sth = $dbr->prepare("SHOW INDEX FROM $table");
|
||||
$sth->execute;
|
||||
while (my $r = $sth->fetchrow_hashref)
|
||||
{
|
||||
my $name = $r->{'Key_name'};
|
||||
my $type = $r->{'Non_unique'} ? "INDEX" : "UNIQUE";
|
||||
if ($name eq "PRIMARY") { $type = "PRIMARY"; }
|
||||
|
||||
$table{$table}->{'index'}->{$name}->{'type'} = $type;
|
||||
push @{$table{$table}->{'index'}->{$name}->{'cols'}}, "_$table.$r->{'Column_name'}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
&dump_xml(\%table);
|
||||
9
livejournal/doc/raw/int/db/schema.xml
Executable file
9
livejournal/doc/raw/int/db/schema.xml
Executable file
@@ -0,0 +1,9 @@
|
||||
<chapter>
|
||||
<?dbhtml filename="schema.html"?>
|
||||
<title>Database Schema</title>
|
||||
|
||||
<para>
|
||||
FIXME: Since a reference can't go in a chapter (?), this has nothing here. Go look at the reference in the book. :P
|
||||
</para>
|
||||
|
||||
</chapter>
|
||||
Reference in New Issue
Block a user