summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-06-26 10:56:02 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-06-26 10:56:02 +0200
commitdea7eadd9c26c1fae7c2240d46aadff92f9a6702 (patch)
tree53d2694c48a3c2ef853f19ed96371a19a33c289a
parent56f2c559e6f4719a3601c8a34fad8674e67c475f (diff)
downloadbin-dea7eadd9c26c1fae7c2240d46aadff92f9a6702.zip
bin-dea7eadd9c26c1fae7c2240d46aadff92f9a6702.tar.gz
dia2pg: index=1 -> CREATE INDEX ON table(attr);
-rwxr-xr-xdia2pg.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/dia2pg.rb b/dia2pg.rb
index 5886637..e00183d 100755
--- a/dia2pg.rb
+++ b/dia2pg.rb
@@ -128,11 +128,13 @@ class Table
end
r << "CREATE TABLE #{name}\n(\n"
pk = []
+ idx = []
uq = { :all=>[] }
@attributes.each do |attr|
sql = attr.to_sql
next if sql.nil?
r << sql
+ idx << attr.real_name if attr.index?
pk << attr.real_name if attr.primary_key
if attr.unique and not attr.primary_key
if attr.comment=~/U./
@@ -148,6 +150,7 @@ class Table
r.sub!(/,\n$/,"\n")
r << ")\nWITH (\n OIDS=#{@opts.oids ? 'TRUE' : 'FALSE'}\n);\n"
r << "ALTER TABLE #{name} OWNER TO #{@opts.user};\n"
+ idx.each do |attr| r << "CREATE INDEX ON #{name} (#{attr});\n" end
r
end
#
@@ -174,6 +177,11 @@ class Attribute
@type=~/foreign/
end
#
+ def index?
+ return false if @comment.nil?
+ @comment=~/index=1/
+ end
+ #
def no_rename?
return false if @comment.nil?
@comment=~/no_rename=1/