You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by mi...@apache.org on 2001/07/02 21:32:18 UTC
cvs commit: jakarta-turbine/conf/torque/templates/sql/base/postgresql columns.vm db.props foreignkey.vm
mikeh 01/07/02 12:32:17
Modified: conf/torque/templates/sql/base/postgresql columns.vm
db.props foreignkey.vm
Log:
Added the foreign key (on delete, on update) support for
postgresql. You have the option to inline the code or use
the alter table ... syntax. The default is to use the alter
table syntax.
Revision Changes Path
1.4 +28 -4 jakarta-turbine/conf/torque/templates/sql/base/postgresql/columns.vm
Index: columns.vm
===================================================================
RCS file: /home/cvs/jakarta-turbine/conf/torque/templates/sql/base/postgresql/columns.vm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- columns.vm 2001/02/27 16:37:43 1.3
+++ columns.vm 2001/07/02 19:32:15 1.4
@@ -1,11 +1,35 @@
#foreach ($col in $table.Columns)
- #set ( $type = $dbprops.get($col.Type) )
+ #if ($col.TorqueType.indexOf("BOOLEAN") != -1)
+ #set ( $type = $dbprops.get($col.TorqueType) )
+ #else
+ #set ( $type = $dbprops.get($col.Type) )
+ #end
#set ( $size = $col.printSize() )
#set ( $default = $col.DefaultSetting )
#set ( $nullString = $strings.select($col.isNotNull(), $dbprops.get("NOTNULL"),"") )
- #set ( $entry = "$col.Name $type $size $default $nullString," )
+ #set ( $entry = "$col.Name $type $size $default $nullString" )
#set ( $autoIncrement = $dbprops.get("AUTOINCREMENT") )
- #set ( $entry = $strings.select($col.isAutoIncrement(), "$col.Name $autoIncrement,", $entry) )
- #set ( $entry = $strings.collapseSpaces($entry) )
+ #set ( $entry = $strings.select($col.isAutoIncrement(), "$col.Name $autoIncrement", $entry) )
+##
+## the following works if you want to inline your foreign keys
+## if you turn it on, be sure to comment out foreignkey.vm
+#if (false)
+#if ($col.isForeignKey())
+#set ($fk = $col.ForeignKey)
+#set ($entry = "$entry REFERENCES $fk.ForeignTableName ($fk.ForeignColumnNames)")
+#if ($fk.hasOnUpdate())
+#set ($entry = "$entry ON UPDATE $fk.OnUpdate ")
+#end
+#if ($fk.hasOnDelete())
+#set ($entry = "$entry ON DELETE $fk.OnDelete ")
+#end
+#end
+#end
+#set ( $entry = $strings.collapseSpaces("$entry,") )
$strings.sub($entry," ,",",")
+## add a nice comment
+#if ($col.isForeignKey())
+#set ($fk = $col.ForeignKey)
+ -- REFERENCES $fk.ForeignTableName ($fk.ForeignColumnNames)
+#end
#end
1.3 +1 -1 jakarta-turbine/conf/torque/templates/sql/base/postgresql/db.props
Index: db.props
===================================================================
RCS file: /home/cvs/jakarta-turbine/conf/torque/templates/sql/base/postgresql/db.props,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- db.props 2001/06/20 20:03:34 1.2
+++ db.props 2001/07/02 19:32:15 1.3
@@ -8,7 +8,7 @@
BIGINT = int4
FLOAT = float
REAL = float
-
+BOOLEANCHAR = boolean
DOUBLE =
NUMERIC =
1.3 +15 -4 jakarta-turbine/conf/torque/templates/sql/base/postgresql/foreignkey.vm
Index: foreignkey.vm
===================================================================
RCS file: /home/cvs/jakarta-turbine/conf/torque/templates/sql/base/postgresql/foreignkey.vm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- foreignkey.vm 2001/05/27 02:53:14 1.2
+++ foreignkey.vm 2001/07/02 19:32:16 1.3
@@ -1,6 +1,17 @@
+##
+## The following will only work for non-circular references
+## if you have a dependancy chain, you will need to use
+## ADD CONSTRAINT syntax (with INITIALLY DEFERRED)
+## which is sticky and version dependant
+##
#foreach ($fk in $table.ForeignKeys)
ALTER TABLE $table.Name
- ADD CONSTRAINT $fk.LocalColumnNames FOREIGN KEY ($fk.LocalColumnNames)
- REFERENCES $fk.ForeignTableName ($fk.ForeignColumnNames);
-
-#end
\ No newline at end of file
+ADD FOREIGN KEY ($fk.LocalColumnNames) REFERENCES $fk.ForeignTableName ($fk.ForeignColumnNames)
+#if ($fk.hasOnUpdate())
+ON UPDATE $fk.OnUpdate
+#end
+#if ($fk.hasOnDelete())
+ON DELETE $fk.OnDelete
+#end
+;
+#end
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org