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}
14 {include file="drop.tpl"}
16 -- /*******************************************************
18 -- * Create new tables
20 -- *******************************************************/
22 {foreach from=$tables item=table}
23 -- /*******************************************************
31 -- *******************************************************/
32 CREATE TABLE `{$table.name}` (
33 {assign var='first' value=true}
35 {foreach from=$table.fields item=field}
37 {assign var='first' value=false}
39 `{$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}
40 {/foreach} {* table.fields *}
42 {if $table.primaryKey}
44 {assign var='first' value=false}
46 {assign var='firstIndexField' value=true}
47 PRIMARY KEY ({foreach from=$table.primaryKey.field item=fieldName}{if $firstIndexField}{assign var='firstIndexField' value=false}{else},{/if}`{$fieldName}`{/foreach})
48 {/if} {* table.primaryKey *}
51 {foreach from=$table.index item=index}
53 {assign var='first' value=false}
54 {if $index.unique} UNIQUE{/if} INDEX `{$index.name}`(
55 {assign var='firstIndexField' value=true}
56 {foreach from=$index.field item=fieldName}
57 {if $firstIndexField}{assign var='firstIndexField' value=false}{else}, {/if}{$fieldName}
60 {/foreach} {* table.index *}
61 {/if} {* table.index *}
63 {if $table.foreignKey}
64 {foreach from=$table.foreignKey item=foreign}
66 {assign var='first' value=false}
67 {if $mysql eq 'simple'} INDEX FKEY_{$foreign.name} ( `{$foreign.name}` ) , {/if}
68 CONSTRAINT {$foreign.uniqName} FOREIGN KEY (`{$foreign.name}`) REFERENCES `{$foreign.table}`(`{$foreign.key}`) {if $foreign.onDelete}ON DELETE {$foreign.onDelete}{/if}
69 {/foreach} {* table.foreignKey *}
70 {/if} {* table.foreignKey *}
72 {* ) {if $mysql eq 'modern' }{$table.attributes}{/if}; *}
73 ) {if $mysql eq 'modern' } {$table.attributes_modern} {else} {$table.attributes_simple} {/if} ;
75 {/foreach} {* tables *}