1 -- +--------------------------------------------------------------------+
2 -- | Copyright CiviCRM LLC. All rights reserved. |
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 -- +--------------------------------------------------------------------+
9 -- Generated from {$smarty.template}
11 -- {$database.comment}
13 {include file="drop.tpl"}
15 -- /*******************************************************
17 -- * Create new tables
19 -- *******************************************************/
21 {foreach from=$tables item=table}
22 -- /*******************************************************
30 -- *******************************************************/
31 CREATE TABLE `{$table.name}` (
32 {assign var='first' value=true}
34 {foreach from=$table.fields item=field}
36 {assign var='first' value=false}
38 `{$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 $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}
39 {/foreach} {* table.fields *}
41 {if $table.primaryKey}
43 {assign var='first' value=false}
45 {assign var='firstIndexField' value=true}
46 PRIMARY KEY ({foreach from=$table.primaryKey.field item=fieldName}{if $firstIndexField}{assign var='firstIndexField' value=false}{else},{/if}`{$fieldName}`{/foreach})
47 {/if} {* table.primaryKey *}
50 {foreach from=$table.index item=index}
52 {assign var='first' value=false}
53 {if $index.unique} UNIQUE{/if} INDEX `{$index.name}`(
54 {assign var='firstIndexField' value=true}
55 {foreach from=$index.field item=fieldName}
56 {if $firstIndexField}{assign var='firstIndexField' value=false}{else}, {/if}{$fieldName}
59 {/foreach} {* table.index *}
60 {/if} {* table.index *}
62 {if $table.foreignKey}
63 {foreach from=$table.foreignKey item=foreign}
65 {assign var='first' value=false}
66 {if $mysql eq 'simple'} INDEX FKEY_{$foreign.name} ( `{$foreign.name}` ) , {/if}
67 CONSTRAINT {$foreign.uniqName} FOREIGN KEY (`{$foreign.name}`) REFERENCES `{$foreign.table}`(`{$foreign.key}`) {if $foreign.onDelete}ON DELETE {$foreign.onDelete}{/if}
68 {/foreach} {* table.foreignKey *}
69 {/if} {* table.foreignKey *}
71 {* ) {if $mysql eq 'modern' }{$table.attributes}{/if}; *}
72 ) {if $mysql eq 'modern' } {$table.attributes_modern} {else} {$table.attributes_simple} {/if} ;
74 {/foreach} {* tables *}