## Copyright 2001-2005 The Apache Software Foundation.
##
## Licensed under the Apache License, Version 2.0 (the "License")
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
##     http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
#set ( $basepath = "sql/base/$targetDatabase" )
#set ( $fname= "sql/base/$targetDatabase/table.vm" )
#set ( $fnamekeys= "sql/base/$targetDatabase/tablefk.vm" )
#set ( $idname = "sql/id-table/idtable.$targetDatabase" )

#foreach ($database in $dataModels)

  #set ( $platform = $database.Platform )

  Platform used: $platform.class.Name

  #set ($outFile = "$database.FileName")
  #if (!$outFile.toLowerCase().endsWith('.sql'))
    #set ($outFile = "${outFile}.sql")
  #end

  SQL file to be created: $outFile

  #foreach ($tbl in $database.tables)
    Primary Key:#if ($tbl.hasPrimaryKey()) Yes #else No #end
    #if (!$tbl.isSkipSql())
      $generator.parse($fname,$outFile,"table",$tbl)
    #end
  #end

  #foreach ($tbl in $database.tables)
    #if (!$tbl.isSkipSql())
      $generator.parse($fnamekeys,$outFile,"tablefk",$tbl)
    #end
  #end

  #if ($idmodel)

    Creating id-table

    #set ($tbl = $idmodel.getTable("ID_TABLE"))
    $generator.parse($fname,$outFile,"table",$tbl)

    ## Generate inserts into ID-TABLE for initial ids.
    #set ( $initialID = 1 )
    $generator.parse($idname, $outFile, "tables", $database.tables)

  #end

#end
