<p>Also I have changed this:</p>
<pre><code>--- a/lib/SQL/Translator/Producer/PostgreSQL.pm
+++ b/lib/SQL/Translator/Producer/PostgreSQL.pm
@@ -595,12 +595,10 @@ sub create_index
if ( $type eq PRIMARY_KEY ) {
push @constraint_defs, "${def_start}PRIMARY KEY ".$field_names;
}
- elsif ( $type eq UNIQUE ) {
- push @constraint_defs, "${def_start}UNIQUE " .$field_names;
- }
- elsif ( $type eq NORMAL ) {
+ elsif ( $type eq NORMAL || $type eq UNIQUE ) {
+ my $unique = $type eq UNIQUE ? 'UNIQUE' : '';
$index_def =
- 'CREATE INDEX ' . $generator->quote($name) . ' on ' . $generator->quote($table_name) . ' ' .
+ "CREATE $unique INDEX " . $generator->quote($name) . ' on ' . $generator->quote($table_name) . ' ' .
join ' ', grep { defined } $index_using, $field_names, $index_where;
}
else {
</code></pre>
<p>This allows me create UNIQUE INDEX instead of constraint. I think this is better.</p>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/dbsrgits/sql-translator/issues/82#issuecomment-276290608">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AASeAgUz5TNBmsUbGFnohANfE-wCm1_vks5rXt3OgaJpZM4Isz-E">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AASeAoFS1k_W2Zv18M3kt3xUDNmzXXiLks5rXt3OgaJpZM4Isz-E.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
<link itemprop="url" href="https://github.com/dbsrgits/sql-translator/issues/82#issuecomment-276290608"></link>
<meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/dbsrgits/sql-translator","title":"dbsrgits/sql-translator","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/dbsrgits/sql-translator"}},"updates":{"snippets":[{"icon":"PERSON","message":"@KES777 in #82: Also I have changed this:\r\n```\r\n--- a/lib/SQL/Translator/Producer/PostgreSQL.pm\r\n+++ b/lib/SQL/Translator/Producer/PostgreSQL.pm\r\n@@ -595,12 +595,10 @@ sub create_index\r\n if ( $type eq PRIMARY_KEY ) {\r\n push @constraint_defs, \"${def_start}PRIMARY KEY \".$field_names;\r\n }\r\n- elsif ( $type eq UNIQUE ) {\r\n- push @constraint_defs, \"${def_start}UNIQUE \" .$field_names;\r\n- }\r\n- elsif ( $type eq NORMAL ) {\r\n+ elsif ( $type eq NORMAL || $type eq UNIQUE ) {\r\n+ my $unique = $type eq UNIQUE ? 'UNIQUE' : '';\r\n $index_def =\r\n- 'CREATE INDEX ' . $generator-\u003equote($name) . ' on ' . $generator-\u003equote($table_name) . ' ' .\r\n+ \"CREATE $unique INDEX \" . $generator-\u003equote($name) . ' on ' . $generator-\u003equote($table_name) . ' ' .\r\n join ' ', grep { defined } $index_using, $field_names, $index_where;\r\n }\r\n else {\r\n\r\n```\r\n\r\nThis allows me create UNIQUE INDEX instead of constraint. I think this is better."}],"action":{"name":"View Issue","url":"https://github.com/dbsrgits/sql-translator/issues/82#issuecomment-276290608"}}}</script>