All Downloads are FREE. Search and download functionalities are using the official Maven repository.

template.macro.constraints.ftl Maven / Gradle / Ivy

<#--
  ~ Licensed to the Apache Software Foundation (ASF) under one or more
  ~ contributor license agreements.  See the NOTICE file distributed with
  ~ this work for additional information regarding copyright ownership.
  ~ The ASF licenses this file to You under the Apache License, Version 2.0
  ~ (the "License"); you may not use this file except in compliance with
  ~ the License.  You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<#macro PRIMARY_KEY data>
<#if data.columns?size gt 0 >
<#if data.name?? >CONSTRAINT ${data.name} PRIMARY KEY (<#list data.columns as c>
<#if c?counter != 1 >, ${c.column})<#if data.include?size gt 0 >
INCLUDE(<#list data.include as col ><#if col?counter != 1 >, ${col})
<#if data.fillfactor?? >
WITH (FILLFACTOR=${data.fillfactor})
<#if data.spcname?? && data.spcname != "pg_default" >
USING INDEX TABLESPACE ${data.spcname }
<#if data.condeferrable!false >
DEFERRABLE<#if data.condeferred!false > INITIALLY DEFERRED



<#macro UNIQUE unique_data >
<#list unique_data as data >
<#if data.columns?size gt 0 ><#if data?counter !=1 >,
<#if data.name?? >CONSTRAINT ${data.name} UNIQUE (<#list data.columns as c>
<#if c?counter != 1 >, ${c.column})<#if data.include?size gt 0 >
INCLUDE(<#list data.include as col><#if col?counter != 1 >, ${col})
<#if data.fillfactor?? >
WITH (FILLFACTOR=${data.fillfactor})
<#if data.spcname?? && data.spcname != "pg_default" >
USING INDEX TABLESPACE ${data.spcname}
<#if data.condeferrable!false >
DEFERRABLE<#if data.condeferred!false > INITIALLY DEFERRED




<#macro FOREIGN_KEY foreign_key_data >
<#list foreign_key_data as data><#if data?counter != 1 >,
<#if data.name?? >CONSTRAINT ${data.name} FOREIGN KEY (<#list data.columns as columnobj ><#if columnobj?counter != 1 >
, ${columnobj.local_column})
REFERENCES ${data.remote_schema}${data.remote_table } (<#list data.columns as columnobj><#if columnobj?counter != 1 >
, ${columnobj.referenced}) <#if data.confmatchtype!false >MATCH FULL<#else >MATCH SIMPLE
ON UPDATE<#if data.confupdtype  == 'a' >
NO ACTION<#elseif data.confupdtype  == 'r' >
RESTRICT<#elseif data.confupdtype  == 'c' >
CASCADE<#elseif data.confupdtype  == 'n' >
SET NULL<#elseif data.confupdtype  == 'd' >
SET DEFAULT
ON DELETE<#if data.confdeltype  == 'a' >
NO ACTION<#elseif data.confdeltype  == 'r' >
RESTRICT<#elseif data.confdeltype  == 'c' >
CASCADE<#elseif data.confdeltype  == 'n' >
SET NULL<#elseif data.confdeltype  == 'd' >
SET DEFAULT
<#if data.condeferrable >
DEFERRABLE<#if data.condeferred >
INITIALLY DEFERRED

<#if !data.convalidated >
NOT VALID



<#macro CHECK check_data >
<#list check_data as data><#if data?counter !=1 >,
<#if data.name?? >CONSTRAINT ${data.name } CHECK (${ data.consrc })<#if data.convalidated!false >
NOT VALID<#if data.connoinherit!false > NO INHERIT



<#macro EXCLUDE exclude_data >
<#list exclude_data as data ><#if data?counter != 1 >,
<#if data.name?? >CONSTRAINT ${data.name } EXCLUDE <#if data.amname?? && data.amname != '' >USING ${data.amname} (
<#list data.columns as col><#if col?counter != 1 >,
<#if col.is_exp!false >${col.column}<#else >${col.column}<#if col.oper_class?? && col.oper_class != '' > ${col.oper_class}<#if col.order?? && col.is_sort_nulls_applicable!false ><#if col.order!false > ASC<#else > DESC NULLS <#if col.nulls_order!false && col.is_sort_nulls_applicable!false ><#if col.nulls_order!false >FIRST <#else >LAST WITH ${col.operator})
<#if data.include?size gt 0 >
INCLUDE(<#list data.include as col ><#if col?counter != 1 >, ${col})
<#if data.fillfactor?? >
WITH (FILLFACTOR=${data.fillfactor})<#if data.spcname?? && data.spcname != "pg_default" >
USING INDEX TABLESPACE ${data.spcname }<#if data.indconstraint?? >
WHERE (${data.indconstraint})<#if data.condeferrable!false >
DEFERRABLE<#if data.condeferred!false >
INITIALLY DEFERRED




<#macro CONSTRAINT_COMMENTS schema, table, data >
<#list data as d>
<#if d.name?? && d.comment?? >
COMMENT ON CONSTRAINT ${d.name } ON ${schema}.${table}
IS '${d.comment}';







© 2015 - 2025 Weber Informatics LLC | Privacy Policy