Merge pull request #19403 from eileenmcnaughton/mem_order
[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 -- {$database.comment}
12
13 {include file="drop.tpl"}
14
15 -- /*******************************************************
16 -- *
17 -- * Create new tables
18 -- *
19 -- *******************************************************/
20
21 {foreach from=$tables item=table}
22 -- /*******************************************************
23 -- *
24 -- * {$table.name}
25 {if $table.comment}
26 -- *
27 -- * {$table.comment}
28 {/if}
29 -- *
30 -- *******************************************************/
31 CREATE TABLE `{$table.name}` (
32 {assign var='first' value=true}
33
34 {foreach from=$table.fields item=field}
35 {if ! $first},{/if}
36 {assign var='first' value=false}
37
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 *}
40
41 {if $table.primaryKey}
42 {if ! $first},{/if}
43 {assign var='first' value=false}
44
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 *}
48
49 {if $table.index}
50 {foreach from=$table.index item=index}
51 {if ! $first},{/if}
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}
57 {/foreach}
58 )
59 {/foreach} {* table.index *}
60 {/if} {* table.index *}
61
62 {if $table.foreignKey}
63 {foreach from=$table.foreignKey item=foreign}
64 {if ! $first},{/if}
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 *}
70
71 {* ) {if $mysql eq 'modern' }{$table.attributes}{/if}; *}
72 ) {if $mysql eq 'modern' } {$table.attributes_modern} {else} {$table.attributes_simple} {/if} ;
73
74 {/foreach} {* tables *}