restructure model

This commit is contained in:
2025-10-16 21:19:41 +02:00
parent 3783540e12
commit 23262d8be6
26 changed files with 75 additions and 679 deletions

View File

@@ -0,0 +1,45 @@
-- Generated by Telosys ( https://www.telosys.org/ )
-- $now.date ($now.time)
#set( $env.database = 'PostgreSQL' )
## ---------------------------------------
## For each entity : CREATE TABLE
## ---------------------------------------
#foreach( $entity in $model.allEntites )
## CREATE TABLE IF NOT EXISTS $entity.sqlTableName
## use $entity.databaseSchema if necessary
CREATE TABLE $entity.sqlTableName
(
## COLUMNS DEFINITION :
#foreach( $attribute in $entity.attributes )
#if( $foreach.hasNext() || $entity.hasPrimaryKey() )
#set($EOL=",")
#else
#set($EOL="")
#end
## $sql.columnName($attribute) $sql.columnType($attribute) $sql.columnConstraints($attribute)$EOL
$attribute.sqlColumnName $attribute.sqlColumnType ${attribute.sqlColumnConstraints}$EOL
#end
## PRIMARY KEY DEFINITION :
#if( $entity.hasPrimaryKey() )
## PRIMARY KEY ($sql.pkColumns($entity))
PRIMARY KEY ($entity.sqlPrimaryKeyColumnsAsString)
#end
);
#end## foreach( $entity )
## ---------------------------------------------------------
## For each Foreign Key in each entity : CREATE FOREIGN KEY
## ---------------------------------------------------------
#foreach( $entity in $model.allEntites )
#if ( $entity.hasForeignKeys() )
#set($tableName = $entity.sqlTableName )
#foreach( $fk in $entity.databaseForeignKeys )
ALTER TABLE $tableName
ADD CONSTRAINT "$fk.name" FOREIGN KEY($fk.sqlOriginColumnsAsString)
REFERENCES ${fk.sqlReferencedTableName}($fk.sqlReferencedColumnsAsString) ;
CREATE INDEX ON $tableName($fk.sqlOriginColumnsAsString) ;
#end## foreach( $fk )
#end## if has FK
#end## foreach( $entity )