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} | |
11 | -- | |
6a488035 TO |
12 | {$database.comments} |
13 | ||
14 | {include file="drop.tpl"} | |
15 | ||
16 | -- /******************************************************* | |
17 | -- * | |
18 | -- * Create new tables | |
19 | -- * | |
20 | -- *******************************************************/ | |
21 | ||
22 | {foreach from=$tables item=table} | |
23 | -- /******************************************************* | |
24 | -- * | |
25 | -- * {$table.name} | |
26 | {if $table.comment} | |
27 | -- * | |
28 | -- * {$table.comment} | |
29 | {/if} | |
30 | -- * | |
31 | -- *******************************************************/ | |
32 | CREATE TABLE `{$table.name}` ( | |
33 | {assign var='first' value=true} | |
34 | ||
35 | {foreach from=$table.fields item=field} | |
36 | {if ! $first},{/if} | |
37 | {assign var='first' value=false} | |
38 | ||
06459c91 | 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} |
6a488035 TO |
40 | {/foreach} {* table.fields *} |
41 | ||
42 | {if $table.primaryKey} | |
43 | {if ! $first},{/if} | |
44 | {assign var='first' value=false} | |
45 | ||
022785d8 JJ |
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}) | |
6a488035 TO |
48 | {/if} {* table.primaryKey *} |
49 | ||
50 | {if $table.index} | |
51 | {foreach from=$table.index item=index} | |
52 | {if ! $first},{/if} | |
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} | |
12616457 | 57 | {if $firstIndexField}{assign var='firstIndexField' value=false}{else}, {/if}{$fieldName} |
6a488035 TO |
58 | {/foreach} |
59 | ) | |
60 | {/foreach} {* table.index *} | |
61 | {/if} {* table.index *} | |
62 | ||
63 | {if $table.foreignKey} | |
64 | {foreach from=$table.foreignKey item=foreign} | |
65 | {if ! $first},{/if} | |
66 | {assign var='first' value=false} | |
12616457 | 67 | {if $mysql eq 'simple'} INDEX FKEY_{$foreign.name} ( `{$foreign.name}` ) , {/if} |
6a488035 TO |
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 *} | |
71 | ||
72 | {* ) {if $mysql eq 'modern' }{$table.attributes}{/if}; *} | |
73 | ) {if $mysql eq 'modern' } {$table.attributes_modern} {else} {$table.attributes_simple} {/if} ; | |
74 | ||
75 | {/foreach} {* tables *} |