<database name="default" defaultIdMethod="native"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="http://xsd.propelorm.org/1.6/database.xsd"
          namespace="Eater\Glim\Model"
        >
    <table name="user">
        <column name="id" type="integer" primaryKey="true" autoIncrement="true" />
        <column name="max_keys" type="integer" default="5" />
        <column name="username" type="varchar" size="64" />
        <column name="email" type="integer" />
        <column name="password" type="varchar" size="64" />
        <column name="superuser" type="boolean" default="false" />
        <column name="max_invites" type="integer" default="0" />
        <column name="used_invites" type="integer" default="0" />

        <unique>
            <unique-column name="username" />
        </unique>

        <foreign-key foreignTable="email_address">
            <reference local="email" foreign="id" />
        </foreign-key>
    </table>

    <table name="email_address">
        <column name="id" type="integer" primaryKey="true" autoIncrement="true" />
        <column name="verified" type="boolean" default="false" />
        <column name="verification" type="varchar" size="64" />
        <column name="address" type="varchar" size="256" />
        <column name="owner" type="integer" />

        <foreign-key foreignTable="user">
            <reference local="owner" foreign="id" />
        </foreign-key>
    </table>

    <table name="email_message">
        <column name="recipient" type="integer" />
        <column name="sender" type="integer" />
        <column name="contents" type="longvarchar" />
        <column name="subject" type="varchar" size="256" />

        <foreign-key phpName="RecipientEmailAddress" foreignTable="email_address">
            <reference local="recipient" foreign="id" />
        </foreign-key>

        <foreign-key phpName="SenderEmailAddress" foreignTable="email_address">
            <reference local="sender" foreign="id" />
        </foreign-key>
    </table>

    <table name="certificate">
        <column name="id" type="integer" primaryKey="true" autoIncrement="true" />
        <column name="user_id" type="integer" />
        <column name="name" type="varchar" size="64" />
        <column name="certificate" type="longvarchar" />
        <column name="private_key" type="longvarchar" />
        <column name="expires_on" type="timestamp" />
        <column name="revoked" type="boolean" default="false" />
        <column name="serial" type="varchar" size="64" />

        <index>
            <index-column name="user_id" />
        </index>

        <index>
            <index-column name="serial" />
        </index>

        <unique>
            <unique-column name="name" />
            <unique-column name="user_id" />
        </unique>

        <foreign-key foreignTable="user">
            <reference local="user_id" foreign="id" />
        </foreign-key>
    </table>

    <table name="invite">
        <column name="id" type="integer" primaryKey="true" autoIncrement="true" />
        <column name="invite" type="varchar" size="64" />
        <column name="owner" type="integer" />

        <foreign-key foreignTable="user">
            <reference local="owner" foreign="id" />
        </foreign-key>
    </table>

    <table name="server">
        <column name="id" type="integer" primaryKey="true" autoIncrement="true" />
        <column name="fqdn" type="varchar" size="64" />
        <column name="fingerprint" type="varchar" size="64"/>
        <column name="public_key" type="longvarchar" />
        <column name="certificate" type="longvarchar" />
        <column name="location" type="varchar" size="64" default="Unknown" />
        <column name="speed" type="integer" default="-1" />
        <column name="external_ip" type="varchar" size="128" />
        <column name="internal_ip" type="varchar" size="128" default="10.24.0.0" />
        <column name="netmask" type="integer" size="4" default="16" />
        <column name="first_dns" type="varchar" size="128" />
        <column name="second_dns" type="varchar" size="128" />
        <column name="port" type="integer" default="1194" />
        <column name="protocol" type="enum" valueSet="udp,tcp" default="udp" />
        <column name="status" type="enum" default="registered" valueSet="registered,signed,revoked" />

        <index>
            <index-column name="fqdn" />
        </index>

        <index>
            <index-column name="status" />
        </index>

        <unique>
            <unique-column name="fingerprint" />
        </unique>
    </table>
</database>
