Merge pull request #23155 from eileenmcnaughton/ret2
[civicrm-core.git] / xml / templates / schema.tpl
1 -- +--------------------------------------------------------------------+
2 -- | Copyright CiviCRM LLC. All rights reserved. |
3 -- | |
4 -- | This work is published under the GNU AGPLv3 license with some |
5 -- | permitted exceptions and without any warranty. For full license |
6 -- | and copyright information, see https://civicrm.org/licensing |
7 -- +--------------------------------------------------------------------+
8 --
9 -- Generated from {$smarty.template}
10 -- {$generated}
11 --{if $database.comment} {$database.comment}{/if}
12
13 {include file="drop.tpl" isOutputLicense=false}
14
15 -- /*******************************************************
16 -- *
17 -- * Create new tables
18 -- *
19 -- *******************************************************/
20 {foreach from=$tables item=table}
21
22 -- /*******************************************************
23 -- *
24 -- * {$table.name}
25 {if $table.comment}
26 -- *
27 -- * {$table.comment}
28 {/if}
29 -- *
30 -- *******************************************************/
31 CREATE TABLE `{$table.name}` ({assign var='first' value=true}
32 {foreach from=$table.fields item=field}
33 {if ! $first},{/if}{assign var='first' value=false}
34
35 `{$field.name}` {$field.sqlType}{if $field.collate} COLLATE {$field.collate}{/if}{if $field.required} {if $field.required == "false"}NULL{else}NOT NULL{/if}{/if}{if isset($field.autoincrement)} AUTO_INCREMENT{/if}{if $field.default|count_characters} DEFAULT {$field.default}{/if}{if $field.comment} COMMENT '{ts escape=sql}{$field.comment}{/ts}'{/if}
36 {/foreach}{* table.fields *}{strip}
37
38 {/strip}{if $table.primaryKey}{if !$first},
39 {/if}{assign var='first' value=false}{assign var='firstIndexField' value=true}
40 PRIMARY KEY ({foreach from=$table.primaryKey.field item=fieldName}{if $firstIndexField}{assign var='firstIndexField' value=false}{else},{/if}`{$fieldName}`{/foreach}){/if}{* table.primaryKey *}
41 {if !empty($table.index)}{foreach from=$table.index item=index}{if !$first},
42 {/if}{assign var='first' value=false}
43 {if isset($index.unique)}UNIQUE {/if}INDEX `{$index.name}`({assign var='firstIndexField' value=true}{foreach from=$index.field item=fieldName}{strip}
44 {/strip}{if $firstIndexField}{assign var='firstIndexField' value=false}{else}, {/if}{$fieldName}{/foreach}){/foreach}{* table.index *}
45 {/if}{* table.index *}
46 {if !empty($table.foreignKey)}
47 {foreach from=$table.foreignKey item=foreign}{if ! $first},
48 {/if}
49 {assign var='first' value=false}{if $mysql eq 'simple'}
50 INDEX FKEY_{$foreign.name} ( `{$foreign.name}` ),{/if}
51 CONSTRAINT {$foreign.uniqName} FOREIGN KEY (`{$foreign.name}`) REFERENCES `{$foreign.table}`(`{$foreign.key}`){if $foreign.onDelete} ON DELETE {$foreign.onDelete}{/if}{/foreach}{* table.foreignKey *}{/if}{strip}
52 {* table.foreignKey *}{/strip}
53 )
54 {if $mysql eq 'modern' }{$table.attributes_modern}{else}{$table.attributes_simple}{/if};
55 {/foreach}{* tables *}