<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Eugene Hutorny &#187; Misc</title>
	<atom:link href="http://hutorny.in.ua/category/misc/feed" rel="self" type="application/rss+xml" />
	<link>http://hutorny.in.ua</link>
	<description>Programming in a small</description>
	<lastBuildDate>Tue, 16 Mar 2010 07:25:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Customizing ErWin templates for PostgreSQL</title>
		<link>http://hutorny.in.ua/misc/customizing-erwin-templates-for-postgresql</link>
		<comments>http://hutorny.in.ua/misc/customizing-erwin-templates-for-postgresql#comments</comments>
		<pubDate>Wed, 22 Jul 2009 16:20:06 +0000</pubDate>
		<dc:creator>Eugene</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://hutorny.in.ua/misc/customizing-erwin-templates-for-postgresql</guid>
		<description><![CDATA[ErWin 7.2 does not provide  support for PostgreSQL, indeed with few tricks it still can be used to model  database and generate valid SQL code.
(Note: In ErWin 7.3 templates  look very different from 7.2, but nevertheless, I believe, similar approach  still can be applied).
Trick 1. Use Oracle 10.x as the target [...]]]></description>
			<content:encoded><![CDATA[<p>ErWin 7.2 does not provide  support for PostgreSQL, indeed with few tricks it still can be used to model  database and generate valid SQL code.</p>
<p><span id="more-99"></span>(Note: <em>In ErWin 7.3 templates  look very different from 7.2, but nevertheless, I believe, similar approach  still can be applied</em>).</p>
<p><strong>Trick 1. Use Oracle 10.x as the target DBMS</strong></p>
<p>PostgreSQL has common  ideology with Oracle and, in my opinion, is the best choice for PostgreSQL needs.</p>
<p><strong>Trick 2. Fix syntax differences</strong><br />
I have encoundered two syntax  differences &#8211; in the order designator in the column specifier of <code>CREATE INDEX</code> statement and extra parenthesis in <code>ALTER TABLE ADD CONSTRAINT</code></p>
<p>Following samples illustrate what causes PostgreSQL to fail with generated code:</p>
<p><code>CREATE INDEX Publisher_xIF1 ON Publisher (PublisherID <strong><del>ASC</del></strong>);</code></p>
<p><code>ALTER TABLE Publisher<br />
ADD <strong><del>(</del></strong>CONSTRAINT Publisher_fObject FOREIGN KEY (ObjectID) REFERENCES Object(ObjectID) ON DELETE CASCADE<strong><del>)</del></strong>;</code></p>
<p>This can be fixed by altering ErWin FE template as the following:</p>
<p>2.1. Copy and rename <code>Oracle.erwin_fe_template</code> to <code>Postgre.erwin_fe_template</code> and then open it in a text editor.</p>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<p>2.2. Find<br />
		<code>SPItemBegin = KeyGroupMembers</code></p>
<p>2.3. Below that find and remove line containing <code>[" " PropertyValueX("Key Group Sort  Order")]</code></p>
</td>
<td valign="top" style="width: 130px"><a title="Key Group Sort Order" class="imagelink" href="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe1.PNG" rel="thumbnail"><img alt="Key Group Sort Order" id="image100" src="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe1.thumbnail.PNG" /></a></td>
</tr>
<tr>
<td>
<p>2.4. Find<code>"ADD "  "("  IsNotNullX(ExecuteX("FKConstraint"),"") ")"</code></p>
<p>2.5. Remove <code>"("  ")"</code>, so it looks like the following:<code>"ADD "  IsNotNullX(ExecuteX("FKConstraint"),"")</code></p>
<p>2.6. Switch you project to  use this template<br />
(Tools>Forward  Engineer>Scema Generation; Database template &#8211; Browse; select  Postgre.erwin_fe_template)</p>
<p>These two tricks are  essential to produce valid SQL code from an ErWin model that contain  no Oracle specific features, like table partitions, logging, validation, etc. If you already have an Oracle model which you prefer to keep intact and still be able to generate SQL for Postgress, you will need to void all parts of FE template responsible for Oracle specific features.</p>
</td>
<td valign="top"><a class="imagelink" title="Add constraint" href="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe2.PNG" rel="thumbnail"><img id="image101" alt="Add constraint" src="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe2.thumbnail.PNG" /></a></td>
</tr>
<tr>
<td>
<p><strong>Trick 3. Implement use of <code>INHERITS</code> for subtype relationships</strong><br />
This part is optional and  necessary if you really need to use table inheritance.</p>
<p>3.1. Find first occurrence of <code>[ExecuteX("EndOfStatementX")]</code> after <code>SPItemBegin = Create Entity</code></p>
</td>
<td></td>
</tr>
<tr>
<td>
<p>3.2. Add <code>[ExecuteX("Extra  Properties")]</code> before <code>[ExecuteX("EndOfStatementX")]</code></p>
<p><code>[ExecuteX("Table  Properties")]<br />
<ins>[ExecuteX("Extra Properties")]</ins><br />
[ExecuteX("EndOfStatementX")]<br />
</code></p>
</td>
<td valign="top"><a class="imagelink" title="Extra Properties" href="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe3.PNG" rel="thumbnail"><img id="image102" alt="Extra Properties" src="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe3.thumbnail.PNG" /></a></td>
</tr>
<tr>
<td>
<p>3.3. At the end of the file add</p>
</td>
<td></td>
</tr>
<tr>
<td>
<pre>SPItemBegin = Extra Properties
  10000:
  {#
  ForEachVectorReferenceX("Child Relations Ref")
  {
    [ IsPropertyEqual("Type","9")
        " INHERITS("

          [
              PushReferenceX("Parent Entity Ref")
              [ [OwnerX"."]PhysicalNameX ]
              PopX
          ]
       ")"
     ]
   }
   #}
   SPItemEnd
</pre>
</td>
<td valign="top"><a class="imagelink" title="Extra Properties Implemetation" href="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe4.PNG" rel="thumbnail"><img id="image103" alt="Extra Properties Implemetation" src="http://hutorny.in.ua/wp-content/uploads/2009/07/postgress_fe4.thumbnail.PNG" /></a></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://hutorny.in.ua/misc/customizing-erwin-templates-for-postgresql/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
