| 1 | -- +--------------------------------------------------------------------+ |
| 2 | -- | CiviCRM version 5 | |
| 3 | -- +--------------------------------------------------------------------+ |
| 4 | -- | Copyright CiviCRM LLC (c) 2004-2018 | |
| 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 | -- |
| 25 | -- Generated from {$smarty.template} |
| 26 | -- {$generated} |
| 27 | -- |
| 28 | {$database.comments} |
| 29 | |
| 30 | {include file="drop.tpl"} |
| 31 | |
| 32 | -- /******************************************************* |
| 33 | -- * |
| 34 | -- * Create new tables |
| 35 | -- * |
| 36 | -- *******************************************************/ |
| 37 | |
| 38 | {foreach from=$tables item=table} |
| 39 | -- /******************************************************* |
| 40 | -- * |
| 41 | -- * {$table.name} |
| 42 | {if $table.comment} |
| 43 | -- * |
| 44 | -- * {$table.comment} |
| 45 | {/if} |
| 46 | -- * |
| 47 | -- *******************************************************/ |
| 48 | CREATE TABLE `{$table.name}` ( |
| 49 | {assign var='first' value=true} |
| 50 | |
| 51 | {foreach from=$table.fields item=field} |
| 52 | {if ! $first},{/if} |
| 53 | {assign var='first' value=false} |
| 54 | |
| 55 | `{$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} |
| 56 | {/foreach} {* table.fields *} |
| 57 | |
| 58 | {if $table.primaryKey} |
| 59 | {if ! $first},{/if} |
| 60 | {assign var='first' value=false} |
| 61 | |
| 62 | {assign var='firstIndexField' value=true} |
| 63 | PRIMARY KEY ({foreach from=$table.primaryKey.field item=fieldName}{if $firstIndexField}{assign var='firstIndexField' value=false}{else},{/if}`{$fieldName}`{/foreach}) |
| 64 | {/if} {* table.primaryKey *} |
| 65 | |
| 66 | {if $table.index} |
| 67 | {foreach from=$table.index item=index} |
| 68 | {if ! $first},{/if} |
| 69 | {assign var='first' value=false} |
| 70 | {if $index.unique} UNIQUE{/if} INDEX `{$index.name}`( |
| 71 | {assign var='firstIndexField' value=true} |
| 72 | {foreach from=$index.field item=fieldName} |
| 73 | {if $firstIndexField}{assign var='firstIndexField' value=false}{else}, {/if}{$fieldName} |
| 74 | {/foreach} |
| 75 | ) |
| 76 | {/foreach} {* table.index *} |
| 77 | {/if} {* table.index *} |
| 78 | |
| 79 | {if $table.foreignKey} |
| 80 | {foreach from=$table.foreignKey item=foreign} |
| 81 | {if ! $first},{/if} |
| 82 | {assign var='first' value=false} |
| 83 | {if $mysql eq 'simple'} INDEX FKEY_{$foreign.name} ( `{$foreign.name}` ) , {/if} |
| 84 | CONSTRAINT {$foreign.uniqName} FOREIGN KEY (`{$foreign.name}`) REFERENCES `{$foreign.table}`(`{$foreign.key}`) {if $foreign.onDelete}ON DELETE {$foreign.onDelete}{/if} |
| 85 | {/foreach} {* table.foreignKey *} |
| 86 | {/if} {* table.foreignKey *} |
| 87 | |
| 88 | {* ) {if $mysql eq 'modern' }{$table.attributes}{/if}; *} |
| 89 | ) {if $mysql eq 'modern' } {$table.attributes_modern} {else} {$table.attributes_simple} {/if} ; |
| 90 | |
| 91 | {/foreach} {* tables *} |