<?xml version="1.0" encoding="UTF-8"?>
<!--
CAUTION: Do not modify this file unless you know what you are doing.
 Unexpected results may occur if the code is changed deliberately.
-->
<dbmodel pgmodeler-ver="1.1.0-beta" use-changelog="false" last-position="0,0" last-zoom="0.7" max-obj-count="9"
	 default-schema="public" default-owner="postgres"
	 layers="Default layer"
	 active-layers="0"
	 layer-name-colors="#000000"
	 layer-rect-colors="#ce266e"
	 show-layer-names="false" show-layer-rects="false">
<database name="demodb" is-template="false" allow-conns="true">
</database>

<schema name="public" layers="0" rect-visible="true" fill-color="#6abdb2" name-color="#000000" sql-disabled="true">
</schema>

<schema name="schema_a" layers="0" rect-visible="true" fill-color="#df83eb" name-color="#000000">
	<role name="postgres"/>
</schema>

<schema name="schema_b" layers="0" rect-visible="true" fill-color="#fbe97f" name-color="#000000">
	<role name="postgres"/>
</schema>

<tag name="red_tables">
	<style id="table-body" colors="#fcfcfc,#fcfcfc,#808080"/>
	<style id="table-ext-body" colors="#fcfcfc,#fcfcfc,#808080"/>
	<style id="table-name" colors="#ffffff"/>
	<style id="table-schema-name" colors="#ffffff"/>
	<style id="table-title" colors="#ff0000,#aa0000,#710000"/>
	<style id="table-toggler-body" colors="#fcfcfc,#fcfcfc,#808080"/>
	<style id="table-toggler-btns" colors="#fcfcfc,#fcfcfc,#808080"/>
</tag>
<table name="table_a" layers="0" collapse-mode="2" max-obj-count="2" z-value="0">
	<schema name="public"/>
	<role name="postgres"/>
	<position x="120" y="720"/>
	<column name="id_a" not-null="true">
		<type name="serial" length="1"/>
	</column>
	<column name="name">
		<type name="varchar" length="200"/>
	</column>
	<constraint name="table_a_pk" type="pk-constr" table="public.table_a">
		<columns names="id_a" ref-type="src-columns"/>
	</constraint>
	<constraint name="table_a_uq" type="uq-constr" table="public.table_a">
		<columns names="name" ref-type="src-columns"/>
	</constraint>
</table>

<table name="table_b" layers="0" collapse-mode="2" max-obj-count="2" z-value="0">
	<schema name="public"/>
	<role name="postgres"/>
	<position x="400" y="1000"/>
	<column name="id_b" not-null="true">
		<type name="serial" length="1"/>
	</column>
	<column name="sku" not-null="true">
		<type name="integer" length="1"/>
	</column>
	<constraint name="table_b_pk" type="pk-constr" table="public.table_b">
		<columns names="id_b" ref-type="src-columns"/>
	</constraint>
</table>

<domain name="email" not-null="true">
	<schema name="public"/>
	<role name="postgres"/>
	<type name="varchar" length="256"/>
</domain>

<table name="table_f" layers="0" collapse-mode="2" max-obj-count="1" z-value="0">
	<schema name="schema_a"/>
	<role name="postgres"/>
	<position x="1580" y="1380"/>
	<column name="id_f" not-null="true">
		<type name="bigserial" length="1"/>
	</column>
	<constraint name="table_f_pk" type="pk-constr" table="schema_a.table_f">
		<columns names="id_f" ref-type="src-columns"/>
	</constraint>
</table>

<table name="table_c" layers="0" collapse-mode="2" max-obj-count="6" z-value="0">
	<schema name="public"/>
	<role name="postgres"/>
	<position x="120" y="1240"/>
	<column name="id_c" not-null="true">
		<type name="serial" length="1"/>
	</column>
	<column name="name">
		<type name="varchar" length="200"/>
	</column>
	<column name="date">
		<type name="date" length="1"/>
	</column>
	<column name="email">
		<type name="public.email" length="1"/>
	</column>
	<constraint name="table_c_pk" type="pk-constr" table="public.table_c">
		<columns names="id_c" ref-type="src-columns"/>
	</constraint>
</table>

<table name="table_d" layers="0" collapse-mode="2" max-obj-count="3" z-value="0">
	<schema name="schema_a"/>
	<role name="postgres"/>
	<position x="1180" y="760"/>
</table>

<table name="table_h" layers="0" collapse-mode="2" max-obj-count="4" z-value="0">
	<schema name="schema_a"/>
	<role name="postgres"/>
	<position x="1080" y="1240"/>
	<column name="id_h" not-null="true">
		<type name="serial" length="1"/>
	</column>
	<column name="table_a_id">
		<type name="integer" length="1"/>
	</column>
	<column name="table_e_id">
		<type name="integer" length="1"/>
	</column>
	<column name="table_f_id">
		<type name="integer" length="1"/>
	</column>
	<constraint name="table_h_pk" type="pk-constr" table="schema_a.table_h">
		<columns names="id_h" ref-type="src-columns"/>
	</constraint>
</table>

<table name="table_g" layers="0" collapse-mode="2" max-obj-count="2" z-value="0">
	<schema name="schema_b"/>
	<role name="postgres"/>
	<tag name="red_tables"/>
	<position x="120" y="380"/>
</table>

<relationship name="table_a_has_many_table_d" type="rel1n" layers="0"
	 src-col-pattern="{sc}_{st}"
	 pk-pattern="{dt}_pk" uq-pattern="{dt}_uq"
	 src-fk-pattern="{st}_fk"
	 custom-color="#678013"
	 src-table="public.table_a"
	 dst-table="schema_a.table_d"
	 src-required="true" dst-required="false"
	 identifier="true"
>
	<label ref-type="src-label">
		<position x="15.01" y="-12.2"/>
	</label>
	<label ref-type="name-label">
		<position x="35.4574" y="6.59827"/>
	</label>
	<column name="test_attrib" not-null="true">
		<type name="smallint" length="1"/>
	</column>
</relationship>

<relationship name="table_g_copies_table_a" type="reldep" layers="0"
	 pk-pattern="{dt}_pk"
	 custom-color="#145d49"
	 src-table="schema_b.table_g"
	 dst-table="public.table_a">
	<special-pk-cols indexes="0"/>
</relationship>

<relationship name="table_b_has_many_table_d" type="rel1n" layers="0"
	 src-col-pattern="{sc}_{st}"
	 pk-pattern="{dt}_pk" uq-pattern="{dt}_uq"
	 src-fk-pattern="{st}_fk"
	 custom-color="#fe0300"
	 src-table="public.table_b"
	 dst-table="schema_a.table_d"
	 src-required="true" dst-required="false">
	<label ref-type="name-label">
		<position x="98.5197" y="-25.1606"/>
	</label>
</relationship>

<table name="table_e" layers="0" collapse-mode="2" max-obj-count="6" z-value="0">
	<schema name="schema_a"/>
	<role name="postgres"/>
	<position x="1620" y="1020"/>
</table>

<relationship name="table_f_has_many_table_c" type="rel1n" layers="0"
	 src-col-pattern="{sc}_{st}"
	 pk-pattern="{dt}_pk" uq-pattern="{dt}_uq"
	 src-fk-pattern="{st}_fk"
	 custom-color="#456796"
	 src-table="schema_a.table_f"
	 dst-table="public.table_c"
	 src-required="false" dst-required="false">
	<label ref-type="src-label">
		<position x="-46.91" y="0"/>
	</label>
	<label ref-type="name-label">
		<position x="35.5197" y="9.93933"/>
	</label>
</relationship>

<function name="dummy_trig_func"
		window-func="false"
		returns-setof="false"
		behavior-type="CALLED ON NULL INPUT"
		function-type="VOLATILE"
		security-type="SECURITY INVOKER"
		parallel-type="PARALLEL UNSAFE"
		execution-cost="1"
		row-amount="0">
	<schema name="schema_b"/>
	<role name="postgres"/>
	<language name="plpgsql"/>
	<return-type>
	<type name="trigger" length="0"/>
	</return-type>
	<definition> <![CDATA[BEGIN
  -- this functions does nothing! --
  RETURN NEW;
END;]]> </definition>
</function>

<trigger name="dummy_trigger" firing-type="BEFORE" per-line="true" constraint="false"
	 ins-event="true" del-event="false" upd-event="false" trunc-event="false"
	 table="schema_a.table_h">
		<function signature="schema_b.dummy_trig_func()"/>
</trigger>

<view name="view_b" layers="0" collapse-mode="2" max-obj-count="2" z-value="0">
	<schema name="schema_b"/>
	<role name="postgres"/>
	<position x="580" y="340"/>
	<reference object="public.table_a" type="table" ref-name="ta" ref-alias="_ta" use-signature="true" format-name="true" use-columns="true"/>
	<reference object="schema_a.table_d" type="table" ref-name="td" ref-alias="_td" use-columns="true"/>
	<simplecol name="expr" type="double precision"/>
	<definition> <![CDATA[SELECT @{ta}.*, @{td}.*, (SELECT random()) AS expr 
FROM
	{ta} AS @{ta}, 
	{td} AS @{td}]]> </definition>
</view>

<relationship name="rel_view_test_table_a" type="reltv" layers="0"
	 custom-color="#8a114b"
	 src-table="schema_b.view_b"
	 dst-table="public.table_a"
	 src-required="false" dst-required="false"/>

<relationship name="rel_view_test_table_d" type="reltv" layers="0"
	 custom-color="#6c7da2"
	 src-table="schema_b.view_b"
	 dst-table="schema_a.table_d"
	 src-required="false" dst-required="false">
	<label ref-type="name-label">
		<position x="-7.45554" y="28.5689"/>
	</label>
</relationship>

<textbox name="pagila_desc" layers="0" z-value="0" width="495.844" font-size="11">
	<position x="20" y="20"/>
	<comment> <![CDATA[[ demodb database ]

This database model demonstrate some features when designing database models. It does not represent any specific context but can be exported to the database since it generates well formed SQL syntax.]]> </comment>
</textbox>

<textbox name="view_test_txt" layers="0" z-value="0" width="213.547" font-size="10">
	<position x="840" y="280"/>
	<comment> <![CDATA[Views can be constructed from references to tables, foreign tables and views. Alternatively, one can define the full view's definition SQL command without working with references.]]> </comment>
</textbox>

<textbox name="tag_txt" layers="0" z-value="0" width="306.719" font-size="10">
	<position x="220" y="240"/>
	<comment> <![CDATA[Note the table below with a different color. pgModeler implements the concept of "tags" in order to permit user to graphically separate tables through different colors.]]> </comment>
</textbox>

<textbox name="col_propag_txt" layers="0" z-value="0" width="464.188" font-size="10">
	<position x="120" y="1480"/>
	<comment> <![CDATA[pgModeler implements a mechanism called "column propagation" when using relationships 1:1, 1:n and generalization.

This mechanism creates the needed columns and constraints in a cascade way on all set of tables affected by one or more relationships.

For instance, the "table_c" is linked to "table_f" through the column "id_f_table_f" generated by
the relationship that connects them. Ahead, the "table_e" inherits "table_c", and, as a result, all columns of the latter are copied to the first, including the column "id_f_table_f" product of another relationship.]]> </comment>
</textbox>

<textbox name="fk_rel_txt" layers="0" z-value="0" width="298.953" font-size="10">
	<position x="1080" y="1520"/>
	<comment> <![CDATA[User is not obligated to use the relationships to generate the foreign keys. You can manually create your own foreign keys on the desired tables and pgModeler will automatically create the relationships to graphically represent the link between them.

You can check that situation on "table_h". There we have three foreign keys created by hand 
pointing repectively to "table_a", "table_e" and  "table_f". Note the relationships linking the 
mentioned tables, those objects weren't created by the user.]]> </comment>
</textbox>

<relationship name="table_e_inherits_table_c" type="relgen" layers="0"
	 pk-pattern="{dt}_pk"
	 custom-color="#124544"
	 src-table="schema_a.table_e"
	 dst-table="public.table_c">
	<special-pk-cols indexes="0"/>
</relationship>

<relationship name="many_table_e_has_many_table_e" type="relnn" layers="0"
	 src-col-pattern="{sc}_{st}" dst-col-pattern="{sc}_{dt}"
	 pk-pattern="{gt}_pk" uq-pattern="{gt}_uq"
	 src-fk-pattern="{st}_fk" dst-fk-pattern="{dt}_fk"
	 pk-col-pattern="id"
	 custom-color="#d28818"
	 src-table="schema_a.table_e"
	 dst-table="schema_a.table_e"
	 src-required="false" dst-required="false"
	 table-name="many_table_e_has_many_table_e">
	<line>
		<position x="1883.26" y="1083.51"/>
	<position x="1883.26" y="987"/>
	<position x="1773.5" y="987"/>
	</line>
	<label ref-type="src-label">
		<position x="8" y="-15.76"/>
	</label>
	<label ref-type="name-label">
		<position x="151.207" y="92.42"/>
	</label>
</relationship>

<view name="view_a" layers="0" collapse-mode="2" max-obj-count="2" z-value="0">
	<schema name="schema_a"/>
	<role name="postgres"/>
	<position x="1360" y="440"/>
	<reference object="public.table_b" type="table" ref-name="tb" ref-alias="_tb" use-signature="true" format-name="true" use-columns="true"/>
	<reference object="schema_b.view_b" type="view" ref-name="va" ref-alias="_va" use-signature="true" format-name="true" use-columns="true"/>
	<definition> <![CDATA[SELECT @{tb}.*, @{va}.* 
FROM
	{tb} AS @{tb},
	{va} AS @{va}
]]> </definition>
</view>

<relationship name="rel_view_b_view_test" type="reltv" layers="0"
	 custom-color="#17c2cb"
	 src-table="schema_a.view_a"
	 dst-table="schema_b.view_b"
	 src-required="false" dst-required="false"/>

<relationship name="rel_view_b_table_b" type="reltv" layers="0"
	 custom-color="#ef1f38"
	 src-table="schema_a.view_a"
	 dst-table="public.table_b"
	 src-required="false" dst-required="false"/>

<constraint name="table_a_fk" type="fk-constr" comparison-type="MATCH FULL"
	 upd-action="NO ACTION" del-action="NO ACTION" ref-table="public.table_a" table="schema_a.table_h">
	<columns names="table_a_id" ref-type="src-columns"/>
	<columns names="id_a" ref-type="dst-columns"/>
</constraint>

<constraint name="table_g_fk" type="fk-constr" comparison-type="MATCH FULL"
	 upd-action="NO ACTION" del-action="NO ACTION" ref-table="schema_a.table_f" table="schema_a.table_h">
	<columns names="table_f_id" ref-type="src-columns"/>
	<columns names="id_f" ref-type="dst-columns"/>
</constraint>

<constraint name="table_e_fk" type="fk-constr" comparison-type="MATCH FULL"
	 upd-action="NO ACTION" del-action="NO ACTION" ref-table="schema_a.table_e" table="schema_a.table_h">
	<columns names="table_e_id" ref-type="src-columns"/>
	<columns names="id_c" ref-type="dst-columns"/>
</constraint>

<relationship name="rel_table_h_table_a" type="relfk" layers="0"
	 custom-color="#0a21ad"
	 src-table="schema_a.table_h"
	 dst-table="public.table_a" reference-fk="table_a_fk"
	 src-required="false" dst-required="false">
	<label ref-type="dst-label">
		<position x="9.54001" y="35.8"/>
	</label>
</relationship>

<relationship name="rel_table_h_table_f" type="relfk" layers="0"
	 custom-color="#1c70ed"
	 src-table="schema_a.table_h"
	 dst-table="schema_a.table_f" reference-fk="table_g_fk"
	 src-required="false" dst-required="false"/>

<relationship name="rel_table_h_table_e" type="relfk" layers="0"
	 src-table="schema_a.table_h"
	 dst-table="schema_a.table_e" reference-fk="table_e_fk"
	 src-required="false" dst-required="false"/>

</dbmodel>
