Permalink
Browse files

Add support for table options, table behaviors

  • Loading branch information...
1 parent a861403 commit b83088c2b5bf3a0fa7d03c999d9f521e80255bee @jphpsf committed Oct 14, 2009
View
@@ -11,11 +11,9 @@ Tired of hand writing your schema.yml to describe your database schema in Symfon
* Save database schema to schema.yml and sfSqlDesigner.xml
* Load database schema from sfSqlDesigner.xml
* TODO: Load database schema from schema.yml (issues to resolve: restore x/y position and comments)
- * TODO: Proper support for behaviors and table options (ie: not using a datatype hack)
* TODO: Import schema from database as configured in databases.yml
* TODO: Support all options of Doctrine syntax for schema.yml
* Not supported yet: actAsI18n, actAsGeographical, actAsSluggable, actAsSearchable, actAsNestedSet
- * Not supported yet: nested behaviors
* Not supported yet: inheritance
* Not supported yet: indexes
* Not supported yet: one to many and many to many relationships, delete cascade
@@ -61,7 +61,7 @@
<div id="background"></div>
<div id="window">
- <div id="windowtitle"><img id="throbber" src="<?php echo javascript_path('../sfSqlDesignerPlugin/images/throbber.gif'); ?>" alt="" title=""/></div>
+ <div id="windowtitle"><img id="throbber" src="<?php echo image_path('../sfSqlDesignerPlugin/images/throbber.gif'); ?>" alt="" title=""/></div>
<div id="windowcontent"></div>
<input type="button" id="windowok" />
<input type="button" id="windowcancel" />
@@ -26,11 +26,4 @@
<type label="Gzip" length="1" sql="gzip" quote="'"/>
</group>
- <group label="Table properties" color="rgb(221,221,221)">
- <type label="Class name" length="0" sql="tableClassName" quote="" note="The generated class name"/>
- <type label="Table name" length="0" sql="tableName" quote="" note="The sql table name" />
- <type label="Behaviors" length="0" sql="tableActAs" quote="" note="The behaviors on the table" />
- <type label="Options" length="0" sql="tableOptions" quote="" note="The options for the table" />
- </group>
-
</datatypes>
@@ -25,126 +25,157 @@
<xsl:text>:
</xsl:text>
- <!-- get table propertie "rows" -->
- <xsl:for-each select="row">
- <xsl:if test="default">
- <xsl:choose>
- <xsl:when test="datatype='tableName'">
- <xsl:text> tableName: </xsl:text>
- <xsl:value-of select="default"/>
- <xsl:text> ]
+ <!-- tableName in db -->
+ <xsl:if test="tableName">
+ <xsl:text> tableName: </xsl:text>
+ <xsl:value-of select="tableName" />
+ <xsl:text>
</xsl:text>
- </xsl:when>
- <xsl:when test="datatype='tableClassName'">
- <xsl:text> className: </xsl:text>
- <xsl:value-of select="default"/>
- <xsl:text> ]
+ </xsl:if>
+
+ <!-- className in model -->
+ <xsl:if test="className">
+ <xsl:text> className: </xsl:text>
+ <xsl:value-of select="className" />
+ <xsl:text>
</xsl:text>
- </xsl:when>
- <xsl:when test="datatype='tableOptions'">
- <xsl:text> options: [ </xsl:text>
- <xsl:value-of select="default"/>
- <xsl:text> ]
+ </xsl:if>
+
+ <!-- behaviors -->
+ <xsl:text> actAs:
</xsl:text>
- </xsl:when>
- <xsl:when test="datatype='tableActAs'">
- <xsl:text> actAs: [ </xsl:text>
- <xsl:value-of select="default"/>
- <xsl:text> ]
+ <xsl:if test="actAsTimestampable">
+ <xsl:text> Timestampable: ~
</xsl:text>
- </xsl:when>
- </xsl:choose>
- </xsl:if>
- </xsl:for-each>
+ </xsl:if>
+ <xsl:if test="actAsSoftDelete">
+ <xsl:text> SoftDelete: ~
+</xsl:text>
+ </xsl:if>
+ <xsl:if test="actAsVersionable">
+ <xsl:text> Versionable: ~
+</xsl:text>
+ </xsl:if>
+ <xsl:if test="actAsTaggable">
+ <xsl:text> Taggable: ~
+</xsl:text>
+ </xsl:if>
+ <xsl:if test="behaviors">
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="behaviors" />
+ <xsl:text>
+</xsl:text>
+ </xsl:if>
+
+ <!-- options -->
+ <xsl:text> options:
+</xsl:text>
+ <xsl:if test="tableType">
+ <xsl:text> type: </xsl:text>
+ <xsl:value-of select="tableType" />
+ <xsl:text>
+</xsl:text>
+ </xsl:if>
+ <xsl:if test="charset">
+ <xsl:text> charset: </xsl:text>
+ <xsl:value-of select="charset" />
+ <xsl:text>
+</xsl:text>
+ </xsl:if>
+ <xsl:if test="collate">
+ <xsl:text> collate: </xsl:text>
+ <xsl:value-of select="collate" />
+ <xsl:text>
+</xsl:text>
+ </xsl:if>
+
+ <xsl:if test="connection">
+ <xsl:text> connection: </xsl:text>
+ <xsl:value-of select="connection" />
+ <xsl:text>
+</xsl:text>
+ </xsl:if>
<xsl:text> columns:
</xsl:text>
<xsl:for-each select="row">
- <!-- skip table propertie "rows" -->
- <xsl:if test="not(datatype='tableActAs') and not(datatype='tableName') and not(datatype='tableClassName') and not(datatype='tableOptions')">
-
- <!-- if there is a comment, let's display it on its own line starting with # -->
- <xsl:if test="comment">
- <xsl:text> # </xsl:text>
- <xsl:value-of select="comment" />
- <xsl:text>
+ <!-- if there is a comment, let's display it on its own line starting with # -->
+ <xsl:if test="comment">
+ <xsl:text> # </xsl:text>
+ <xsl:value-of select="comment" />
+ <xsl:text>
</xsl:text>
+ </xsl:if>
+
+ <!-- first the name -->
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="@name" />
+ <xsl:text>: { type: </xsl:text>
+
+ <!-- then the datatype -->
+ <xsl:choose>
+ <xsl:when test="contains(datatype,'decimal')">
+ <xsl:value-of select="substring-before(datatype,',')"/>
+ <xsl:text>), scale: </xsl:text>
+ <xsl:value-of select="substring-before(substring-after(datatype,','),')')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="datatype" />
+ </xsl:otherwise>
+ </xsl:choose>
+
+ <!-- is it a primary key? -->
+ <xsl:variable name="rowname" select="@name" />
+ <xsl:for-each select="../key">
+ <xsl:if test="@type = 'PRIMARY'">
+ <xsl:for-each select="part">
+ <xsl:if test=".=$rowname">
+ <xsl:text>, primary: true</xsl:text>
+ </xsl:if>
+ </xsl:for-each>
</xsl:if>
+ </xsl:for-each>
+
+ <!-- can it be null? -->
+ <xsl:if test="@null = 0">
+ <xsl:text>, notnull: true</xsl:text>
+ </xsl:if>
- <!-- first the name -->
- <xsl:text> </xsl:text>
- <xsl:value-of select="@name" />
- <xsl:text>: { type: </xsl:text>
+ <!-- is an autoincrement? -->
+ <xsl:if test="@autoincrement = 1">
+ <xsl:text>, autoincrement: true</xsl:text>
+ </xsl:if>
- <!-- then the datatype -->
+ <!-- default value. for enum list of values, the first will be default -->
+ <xsl:if test="default">
<xsl:choose>
- <xsl:when test="contains(datatype,'decimal')">
- <xsl:value-of select="substring-before(datatype,',')"/>
- <xsl:text>), scale: </xsl:text>
- <xsl:value-of select="substring-before(substring-after(datatype,','),')')"/>
+ <xsl:when test="contains(datatype,'enum')">
+ <xsl:text>, values: [ </xsl:text>
+ <xsl:value-of select="default" />
+ <xsl:text> ]</xsl:text>
+ <xsl:text>, default: </xsl:text>
+ <xsl:choose>
+ <xsl:when test="contains(default,',')">
+ <xsl:value-of select="substring-before(default,',')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="default" />
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:when>
<xsl:otherwise>
- <xsl:value-of select="datatype" />
+ <xsl:text>, values: [ </xsl:text>
+ <xsl:value-of select="default" />
+ <xsl:text> ]</xsl:text>
</xsl:otherwise>
</xsl:choose>
-
- <!-- is it a primary key? -->
- <xsl:variable name="rowname" select="@name" />
- <xsl:for-each select="../key">
- <xsl:if test="@type = 'PRIMARY'">
- <xsl:for-each select="part">
- <xsl:if test=".=$rowname">
- <xsl:text>, primary: true</xsl:text>
- </xsl:if>
- </xsl:for-each>
- </xsl:if>
- </xsl:for-each>
-
- <!-- can it be null? -->
- <xsl:if test="@null = 0">
- <xsl:text>, notnull: true</xsl:text>
- </xsl:if>
-
- <!-- is an autoincrement? -->
- <xsl:if test="@autoincrement = 1">
- <xsl:text>, autoincrement: true</xsl:text>
- </xsl:if>
-
- <!-- default value. for enum list of values, the first will be default -->
- <xsl:if test="default">
- <xsl:choose>
- <xsl:when test="contains(datatype,'enum')">
- <xsl:text>, values: [ </xsl:text>
- <xsl:value-of select="default" />
- <xsl:text> ]</xsl:text>
- <xsl:text>, default: </xsl:text>
- <xsl:choose>
- <xsl:when test="contains(default,',')">
- <xsl:value-of select="substring-before(default,',')"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="default" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text>, values: [ </xsl:text>
- <xsl:value-of select="default" />
- <xsl:text> ]</xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:if>
-
-
- <!-- jump to next field -->
- <xsl:text> }
-</xsl:text>
-
- <!-- end if to skip table properties -->
</xsl:if>
+ <!-- jump to next field -->
+ <xsl:text> }
+</xsl:text>
<!-- end loop on rows -->
</xsl:for-each>
Oops, something went wrong.

0 comments on commit b83088c

Please sign in to comment.