1 -- +--------------------------------------------------------------------+
2 -- | CiviCRM version 4.3 |
3 -- +--------------------------------------------------------------------+
4 -- | Copyright CiviCRM LLC (c) 2004-2013 |
5 -- +--------------------------------------------------------------------+
6 -- | This file is a part of CiviCRM. |
8 -- | CiviCRM is free software; you can copy, modify, and distribute it |
9 -- | under the terms of the GNU Affero General Public License |
10 -- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
12 -- | CiviCRM is distributed in the hope that it will be useful, but |
13 -- | WITHOUT ANY WARRANTY; without even the implied warranty of |
14 -- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15 -- | See the GNU Affero General Public License for more details. |
17 -- | You should have received a copy of the GNU Affero General Public |
18 -- | License and the CiviCRM Licensing Exception along |
19 -- | with this program; if not, contact CiviCRM LLC |
20 -- | at info[AT]civicrm[DOT]org. If you have questions about the |
21 -- | GNU Affero General Public License or the licensing of CiviCRM, |
22 -- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
23 -- +--------------------------------------------------------------------+
26 {include file="drop.tpl"}
28 -- /*******************************************************
30 -- * Create new tables
32 -- *******************************************************/
34 {foreach from=$tables item=table}
35 -- /*******************************************************
43 -- *******************************************************/
44 CREATE TABLE `{$table.name}` (
45 {assign var='first' value=true}
47 {foreach from=$table.fields item=field}
49 {assign var='first' value=false}
51 `{$field.name}` {$field.sqlType} {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 '{$field.comment}'{/if}
52 {/foreach} {* table.fields *}
54 {if $table.primaryKey}
56 {assign var='first' value=false}
58 PRIMARY KEY ( `{$table.primaryKey.name}` )
59 {/if} {* table.primaryKey *}
62 {foreach from=$table.index item=index}
64 {assign var='first' value=false}
65 {if $index.unique} UNIQUE{/if} INDEX `{$index.name}`(
66 {assign var='firstIndexField' value=true}
67 {foreach from=$index.field item=fieldName}
68 {if $firstIndexField}{assign var='firstIndexField' value=false}{else}, {/if}{$fieldName}
71 {/foreach} {* table.index *}
72 {/if} {* table.index *}
74 {if $table.foreignKey}
75 {foreach from=$table.foreignKey item=foreign}
77 {assign var='first' value=false}
78 {if $mysql eq 'simple'} INDEX FKEY_{$foreign.name} ( `{$foreign.name}` ) , {/if}
79 CONSTRAINT {$foreign.uniqName} FOREIGN KEY (`{$foreign.name}`) REFERENCES `{$foreign.table}`(`{$foreign.key}`) {if $foreign.onDelete}ON DELETE {$foreign.onDelete}{/if}
80 {/foreach} {* table.foreignKey *}
81 {/if} {* table.foreignKey *}
83 {* ) {if $mysql eq 'modern' }{$table.attributes}{/if}; *}
84 ) {if $mysql eq 'modern' } {$table.attributes_modern} {else} {$table.attributes_simple} {/if} ;
86 {/foreach} {* tables *}