From 6cee3f899e6a617eebc75d1d623efb4ab81b531b Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 18 May 2021 16:06:00 +1200 Subject: [PATCH] Fix extraneous white space in generated sql - trailing space when comment is not declared for a db table - spaces before arguments that don't exist - extra lines Schema.tpl whitespace overhaul Note I tried regenerating civicrm.mysql with this & it looked good - jenkins can pass judgement too... I also tried regenerating the sql in search_kit but I hit what seems to me to be an unreleated regression - ie search_kit generates ROW_FORMAT=DYNAMIC With my version (lastest from master) of civix I get ENGINE = INNODB but not the ROW_FORMAT --- xml/templates/drop.tpl | 7 ++-- xml/templates/schema.tpl | 71 +++++++++++++++------------------------- 2 files changed, 30 insertions(+), 48 deletions(-) diff --git a/xml/templates/drop.tpl b/xml/templates/drop.tpl index bd0aba72cd..808ea919a0 100644 --- a/xml/templates/drop.tpl +++ b/xml/templates/drop.tpl @@ -1,4 +1,4 @@ --- +--------------------------------------------------------------------+ +{*suppress license if within a file that already has the license*}{if !$no_license}-- +--------------------------------------------------------------------+ -- | Copyright CiviCRM LLC. All rights reserved. | -- | | -- | This work is published under the GNU AGPLv3 license with some | @@ -8,10 +8,11 @@ -- -- Generated from {$smarty.template} -- {$generated} --- +--{/if} -- /******************************************************* -- * --- * Clean up the existing tables +-- * Clean up the existing tables{if $no_license} - this section generated from {$smarty.template} +{/if} -- * -- *******************************************************/ diff --git a/xml/templates/schema.tpl b/xml/templates/schema.tpl index 980b8a78a5..6d413c3e78 100644 --- a/xml/templates/schema.tpl +++ b/xml/templates/schema.tpl @@ -8,17 +8,17 @@ -- -- Generated from {$smarty.template} -- {$generated} --- {$database.comment} +--{if $database.comment} {$database.comment}{/if} -{include file="drop.tpl"} +{include file="drop.tpl" no_license=TRUE} -- /******************************************************* -- * -- * Create new tables -- * -- *******************************************************/ - {foreach from=$tables item=table} + -- /******************************************************* -- * -- * {$table.name} @@ -28,47 +28,28 @@ {/if} -- * -- *******************************************************/ -CREATE TABLE `{$table.name}` ( -{assign var='first' value=true} - +CREATE TABLE `{$table.name}` ({assign var='first' value=true} {foreach from=$table.fields item=field} -{if ! $first},{/if} -{assign var='first' value=false} - - `{$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} -{/foreach} {* table.fields *} - -{if $table.primaryKey} -{if ! $first},{/if} -{assign var='first' value=false} - - {assign var='firstIndexField' value=true} - PRIMARY KEY ({foreach from=$table.primaryKey.field item=fieldName}{if $firstIndexField}{assign var='firstIndexField' value=false}{else},{/if}`{$fieldName}`{/foreach}) -{/if} {* table.primaryKey *} - -{if $table.index} - {foreach from=$table.index item=index} - {if ! $first},{/if} - {assign var='first' value=false} - {if $index.unique} UNIQUE{/if} INDEX `{$index.name}`( - {assign var='firstIndexField' value=true} - {foreach from=$index.field item=fieldName} - {if $firstIndexField}{assign var='firstIndexField' value=false}{else}, {/if}{$fieldName} - {/foreach} -) -{/foreach} {* table.index *} -{/if} {* table.index *} - +{if ! $first},{/if}{assign var='first' value=false} + + `{$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} +{/foreach}{* table.fields *}{strip} + +{/strip}{if $table.primaryKey}{if !$first}, +{/if}{assign var='first' value=false}{assign var='firstIndexField' value=true} + PRIMARY KEY ({foreach from=$table.primaryKey.field item=fieldName}{if $firstIndexField}{assign var='firstIndexField' value=false}{else},{/if}`{$fieldName}`{/foreach}){/if}{* table.primaryKey *} +{if $table.index}{foreach from=$table.index item=index}{if !$first}, +{/if}{assign var='first' value=false} + {if $index.unique}UNIQUE {/if}INDEX `{$index.name}`({assign var='firstIndexField' value=true}{foreach from=$index.field item=fieldName}{strip} +{/strip}{if $firstIndexField}{assign var='firstIndexField' value=false}{else}, {/if}{$fieldName}{/foreach}){/foreach}{* table.index *} +{/if}{* table.index *} {if $table.foreignKey} -{foreach from=$table.foreignKey item=foreign} -{if ! $first},{/if} -{assign var='first' value=false} - {if $mysql eq 'simple'} INDEX FKEY_{$foreign.name} ( `{$foreign.name}` ) , {/if} - CONSTRAINT {$foreign.uniqName} FOREIGN KEY (`{$foreign.name}`) REFERENCES `{$foreign.table}`(`{$foreign.key}`) {if $foreign.onDelete}ON DELETE {$foreign.onDelete}{/if} -{/foreach} {* table.foreignKey *} -{/if} {* table.foreignKey *} - -{* ) {if $mysql eq 'modern' }{$table.attributes}{/if}; *} -) {if $mysql eq 'modern' } {$table.attributes_modern} {else} {$table.attributes_simple} {/if} ; - -{/foreach} {* tables *} +{foreach from=$table.foreignKey item=foreign}{if ! $first}, +{/if} +{assign var='first' value=false}{if $mysql eq 'simple'} + INDEX FKEY_{$foreign.name} ( `{$foreign.name}` ),{/if} + CONSTRAINT {$foreign.uniqName} FOREIGN KEY (`{$foreign.name}`) REFERENCES `{$foreign.table}`(`{$foreign.key}`){if $foreign.onDelete} ON DELETE {$foreign.onDelete}{/if}{/foreach}{* table.foreignKey *}{/if}{strip} + {* table.foreignKey *}{/strip} +) +{if $mysql eq 'modern' }{$table.attributes_modern}{else}{$table.attributes_simple}{/if}; +{/foreach}{* tables *} -- 2.25.1