Commit | Line | Data |
---|---|---|
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} | |
f40e2f1f | 11 | -- {$database.comment} |
6a488035 TO |
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 | ||
06459c91 | 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} |
6a488035 TO |
39 | {/foreach} {* table.fields *} |
40 | ||
41 | {if $table.primaryKey} | |
42 | {if ! $first},{/if} | |
43 | {assign var='first' value=false} | |
44 | ||
022785d8 JJ |
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}) | |
6a488035 TO |
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} | |
12616457 | 56 | {if $firstIndexField}{assign var='firstIndexField' value=false}{else}, {/if}{$fieldName} |
6a488035 TO |
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} | |
12616457 | 66 | {if $mysql eq 'simple'} INDEX FKEY_{$foreign.name} ( `{$foreign.name}` ) , {/if} |
6a488035 TO |
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 *} |