CRM-12647 - CRM_Utils_Migrate_Export - Cleanup
[civicrm-core.git] / xml / templates / schema.tpl
1 -- +--------------------------------------------------------------------+
2 -- | CiviCRM version 4.3 |
3 -- +--------------------------------------------------------------------+
4 -- | Copyright CiviCRM LLC (c) 2004-2013 |
5 -- +--------------------------------------------------------------------+
6 -- | This file is a part of CiviCRM. |
7 -- | |
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. |
11 -- | |
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. |
16 -- | |
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 -- +--------------------------------------------------------------------+
24 {$database.comments}
25
26 {include file="drop.tpl"}
27
28 -- /*******************************************************
29 -- *
30 -- * Create new tables
31 -- *
32 -- *******************************************************/
33
34 {foreach from=$tables item=table}
35 -- /*******************************************************
36 -- *
37 -- * {$table.name}
38 {if $table.comment}
39 -- *
40 -- * {$table.comment}
41 {/if}
42 -- *
43 -- *******************************************************/
44 CREATE TABLE `{$table.name}` (
45 {assign var='first' value=true}
46
47 {foreach from=$table.fields item=field}
48 {if ! $first},{/if}
49 {assign var='first' value=false}
50
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 *}
53
54 {if $table.primaryKey}
55 {if ! $first},{/if}
56 {assign var='first' value=false}
57
58 PRIMARY KEY ( `{$table.primaryKey.name}` )
59 {/if} {* table.primaryKey *}
60
61 {if $table.index}
62 {foreach from=$table.index item=index}
63 {if ! $first},{/if}
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}
69 {/foreach}
70 )
71 {/foreach} {* table.index *}
72 {/if} {* table.index *}
73
74 {if $table.foreignKey}
75 {foreach from=$table.foreignKey item=foreign}
76 {if ! $first},{/if}
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 *}
82
83 {* ) {if $mysql eq 'modern' }{$table.attributes}{/if}; *}
84 ) {if $mysql eq 'modern' } {$table.attributes_modern} {else} {$table.attributes_simple} {/if} ;
85
86 {/foreach} {* tables *}