<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xml:lang="en">
    <xsd:annotation>
	<xsd:documentation>
	    XML Schema Definition (.xsd) for the XML Schema Language for XpressEngine.

	    XpressEngine is an open source framework for creating your web sites.
	    http://xpressengine.org/

	    XML Schema Language currently supports SQL CREATE TABLE statements only.

	    Author: Adrian Constantin, Arnia Software (adrian.constantin@arnia.ro)
	    Date:   22 mar 2012

	    The types defined here closely model the behavior of php classes in
	    classes/db/DB*.class.php
	</xsd:documentation>
    </xsd:annotation>

    <xsd:simpleType name="ColumnTypeType">
	<xsd:annotation>
	    <xsd:documentation>
		Possible column types. Value "tinytext" is only supported by
		CUBRID.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:restriction base="xsd:string">
	    <xsd:enumeration value="number" />
	    <xsd:enumeration value="bignumber" />
	    <xsd:enumeration value="varchar" />
	    <xsd:enumeration value="char" />
	    <xsd:enumeration value="text" />
	    <xsd:enumeration value="bigtext" />
	    <xsd:enumeration value="tinytext" />    <!-- CUBRID only -->
	    <xsd:enumeration value="date" />
	    <xsd:enumeration value="float" />
	</xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="NameString">
	<xsd:annotation>
	    <xsd:documentation>
		Non-empty string (to be used as a name).
	    </xsd:documentation>
	</xsd:annotation>
	
	<xsd:restriction base="xsd:string">
	    <xsd:pattern value=".+" />
	</xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="ColumnType">
	<xsd:annotation>
	    <xsd:documentation>
		XML Element type to represent a column definition in a
		SQL CREATE TABLE statement.

		Attribute 'size' should only be used for string and numeric
		column types.

		Attribute 'auto_increment' is only supported by SQL Server
		and mysql.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:complexContent>
	    <xsd:restriction base="xsd:anyType">
		<xsd:attribute name="name" use="required">
		    <xsd:simpleType>
			<xsd:restriction base="NameString">
			    <xsd:pattern value="([^sS].*)|([sS](([^eE].*)|([eE](([^qQ].*)|([qQ](([^uU].*)|([uU](([^eE].*)|([eE](([^nN].*)|([nN](([^cC].*)|([cC](([^eE].*)|([eE].+)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?">
				<xsd:annotation>
				    <xsd:documentation>
					The table name "sequence" is reserved by XE.
				    </xsd:documentation>
				</xsd:annotation>
			    </xsd:pattern>
			</xsd:restriction>
		    </xsd:simpleType>
		</xsd:attribute>
		<xsd:attribute name="type" type="ColumnTypeType" use="required" />
		<xsd:attribute name="size" type="xsd:positiveInteger" />
		<xsd:attribute name="default" type="xsd:string" />
		<xsd:attribute name="notnull">
		    <xsd:simpleType>
			<xsd:restriction base="xsd:string">
			    <xsd:enumeration value="notnull" />
			</xsd:restriction>
		    </xsd:simpleType>
		</xsd:attribute>
		<xsd:attribute name="primary_key">
		    <xsd:simpleType>
			<xsd:restriction base="xsd:string">
			    <xsd:enumeration value="primary_key" />
			</xsd:restriction>
		    </xsd:simpleType>
		</xsd:attribute>
		<xsd:attribute name="index" type="NameString" />
		<xsd:attribute name="unique" type="NameString" />
		<xsd:attribute name="auto_increment">
		    <xsd:simpleType>
			<xsd:restriction base="xsd:string">
			    <xsd:enumeration value="auto_increment" />
			</xsd:restriction>
		    </xsd:simpleType>
		</xsd:attribute>
	    </xsd:restriction>
	</xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="CreateTableType">
	<xsd:sequence>
	    <xsd:element name="column" type="ColumnType" minOccurs="1" maxOccurs="unbounded" />
	</xsd:sequence>

	<xsd:attribute name="name" type="NameString" use="required" />
    </xsd:complexType>

    <xsd:element name="table" type="CreateTableType">
	<xsd:annotation>
	    <xsd:documentation>
		The document element, representing a SQL CREATE TABLE
		statement.
	    </xsd:documentation>
	</xsd:annotation>

	<xsd:key name="unique_column_names">
	    <xsd:selector xpath="column" />
	    <xsd:field xpath="@name" />
	</xsd:key>
     </xsd:element>
</xsd:schema>
