Adding an FK relationship with the -meta tag

Help
2011-07-01
2013-05-29
  • Cliff Evans
    Cliff Evans
    2011-07-01

    Just thought I'd post an example of how to add an FK relationship using the -meta tag as it took me a while to get it to work.  Hope it helps someone out there.

    The main thing to keep in mind is that the data in the .xml file you pass to the -meta tag doesn't get merged with the data read from the database, so you have to include both sides of the relationship even though you probably already have both tables showing from the database connection.  So I got it working with something like the following:

    <?xml version="1.0" encoding="UTF-8" ?> 
    <schemaMeta xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xsi:noNamespaceSchemaLocation="http://schemaspy.sourceforge.net/xmlschema/2011/02/05/schemaspy.meta.xsd">
     <comments>UnifiedDB World Database</comments> 
     <tables>
       <table name="instrument_measure">
         <column name="rowset_id">
           <foreignKey table="context_element" column="rowset_id" /> 
         </column>
       </table>
       <table name="context_element">
         <column name="rowset_id" />
        </table>
      </tables>
    </schemaMeta>
    

    One possible issue with this it that it currently only supports real relationships; by which I mean, it will assume that the

    rowset_id
    

    column in context_element is a PK and will mark it as such.  I've raised a feature request to allow you to mark the FK relationship as implied to allow adding logical relationships to the documentation of the database.  The request can be found here.