source: mauRepo/xmi2sqlalchemy/trunk/src/main/resources/global_library.vm @ 8084

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/xmi2sqlalchemy/trunk/src/main/resources/global_library.vm@8084
Revision 8084, 1.9 KB checked in by mnagni, 8 years ago (diff)

Correctly generates DB tables for CEDAEditor

in sqlTables.sql

1) No more "metadata = MetaData?()"
2) no more "metadata.create_all(engine)"

Just a couple of stupid thigs has still to be fixed by hand:
3) Column('refDirection', ARRAY, nullable=True) ----> Column('refDirection', ARRAY(TEXT), nullable=True)
4) Column('role', CI_RoleCode.db_type(), nullable=False) ----> Column('role', CI_RoleCode.db_type())

  • Property svn:executable set to *
Line 
1
2#macro ( associationTableName $associationTable)
3#set ($rn = ${associationTable.rightTable.associatedClass.name.toLowerCase()})
4#set ($ln = ${associationTable.leftTable.associatedClass.name.toLowerCase()})
5${rn}_${ln}#end
6
7#macro( substituteClassType $typeName)
8#if($typeName.equals('CharacterString'))
9str#elseif($typeName.equals('Character'))
10str#else
11${typeName}
12#end
13#end
14
15#macro( tableName $tableModel)
16${tableModel.associatedClass.name.toLowerCase()}_table#end
17
18#macro( relationColumns $tableModel)
19#set ($tmn = $tableModel.associatedClass.name)
20#set ($ft = $tmn)
21#foreach( $relation in $tableModel.relationship)
22#relationColumn($tableModel, $relation, $foreach.hasNext)
23#end
24#end
25
26
27#macro(relationColumn $tableModel, $relation, $hasNext)
28#set ($tt = $relation.toTable.associatedClass.name)
29#set ($ft = $relation.fromTable.associatedClass.name)
30#set ($tmn = $tableModel.associatedClass.name)
31#if ($relation.isManyToMany())
32'${relation.name}': relationship(${tt}, secondary=#associationTableName($relation.associationTable)_table)#if($hasNext),#end
33#elseif($relation.isOneToMany())
34'${relation.name}': relationship(${tt}, primaryjoin=${tt.toLowerCase()}_table.c.${ft.toLowerCase()}_${relation.name.toLowerCase()}==${tmn.toLowerCase()}_table.c.id)#if($hasNext),#end
35#elseif($relation.isOneToOne())
36'${relation.name}': relationship(${tt}, uselist=False, backref='${relation.backrefName}', primaryjoin=${tt.toLowerCase()}_table.c.${ft.toLowerCase()}_${relation.name.toLowerCase()}_id==${tmn.toLowerCase()}_table.c.id)#if($hasNext),#end
37#end
38#if($tt == $tmn)
39, remote_side=[${tmn.toLowerCase()}_table.c.${tmn.toLowerCase()}_id]
40#end
41#end
42
43
44#macro( inheritedClasses $tableModel)
45#set ($tln = ${tableModel.associatedClass.name.toLowerCase()})
46#if($tableModel.inherited.size() > 0)
47        #foreach( $parent in $tableModel.inherited)
48                #set ($pn = ${parent.associatedClass.name})
49                , polymorphic_on=${tln}_table.c.t_type, inherits=${pn}, polymorphic_identity='${tln}'#break#end
50#else   
51#end
52#end
Note: See TracBrowser for help on using the repository browser.