Merge pull request #22439 from eileenmcnaughton/legt
[civicrm-core.git] / xml / templates / schema.tpl
CommitLineData
6a488035 1-- +--------------------------------------------------------------------+
6b7eb9df 2-- | Copyright CiviCRM LLC. All rights reserved. |
6a488035 3-- | |
6b7eb9df
TO
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 |
6a488035 7-- +--------------------------------------------------------------------+
d5864876
ARW
8--
9-- Generated from {$smarty.template}
10-- {$generated}
6cee3f89 11--{if $database.comment} {$database.comment}{/if}
6a488035 12
61940bbf 13{include file="drop.tpl" isOutputLicense=false}
6a488035
TO
14
15-- /*******************************************************
16-- *
17-- * Create new tables
18-- *
19-- *******************************************************/
6a488035 20{foreach from=$tables item=table}
6cee3f89 21
6a488035
TO
22-- /*******************************************************
23-- *
24-- * {$table.name}
25{if $table.comment}
26-- *
27-- * {$table.comment}
28{/if}
29-- *
30-- *******************************************************/
6cee3f89 31CREATE TABLE `{$table.name}` ({assign var='first' value=true}
6a488035 32{foreach from=$table.fields item=field}
6cee3f89
EM
33{if ! $first},{/if}{assign var='first' value=false}
34
1832ba99 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}
6cee3f89
EM
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 *}
1832ba99 41{if !empty($table.index)}{foreach from=$table.index item=index}{if !$first},
6cee3f89 42{/if}{assign var='first' value=false}
1832ba99 43 {if isset($index.unique)}UNIQUE {/if}INDEX `{$index.name}`({assign var='firstIndexField' value=true}{foreach from=$index.field item=fieldName}{strip}
6cee3f89
EM
44{/strip}{if $firstIndexField}{assign var='firstIndexField' value=false}{else}, {/if}{$fieldName}{/foreach}){/foreach}{* table.index *}
45{/if}{* table.index *}
1832ba99 46{if !empty($table.foreignKey)}
6cee3f89
EM
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 *}