summaryrefslogtreecommitdiffstats
path: root/dia2pg.rb
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-06-26 14:12:59 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-06-26 14:12:59 +0200
commitabe41a1e45fe080b17c82172b9aec3de14334c12 (patch)
tree77c6839fe9176c853daab3f31d13ed6ec8e6b406 /dia2pg.rb
parentdea7eadd9c26c1fae7c2240d46aadff92f9a6702 (diff)
downloadbin-abe41a1e45fe080b17c82172b9aec3de14334c12.zip
bin-abe41a1e45fe080b17c82172b9aec3de14334c12.tar.gz
dia2pg: support multi row indexes
Diffstat (limited to 'dia2pg.rb')
-rwxr-xr-xdia2pg.rb17
1 files changed, 11 insertions, 6 deletions
diff --git a/dia2pg.rb b/dia2pg.rb
index e00183d..cf02445 100755
--- a/dia2pg.rb
+++ b/dia2pg.rb
@@ -128,13 +128,17 @@ class Table
end
r << "CREATE TABLE #{name}\n(\n"
pk = []
- idx = []
+ idx = {}
uq = { :all=>[] }
@attributes.each do |attr|
sql = attr.to_sql
next if sql.nil?
r << sql
- idx << attr.real_name if attr.index?
+ xi = attr.index
+ if xi
+ idx[xi] ||= []
+ idx[xi] << attr.real_name
+ end
pk << attr.real_name if attr.primary_key
if attr.unique and not attr.primary_key
if attr.comment=~/U./
@@ -150,7 +154,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
+ idx.each do |k,v| r << "CREATE INDEX ON #{name} (#{v.join ','});\n" end
r
end
#
@@ -177,9 +181,10 @@ class Attribute
@type=~/foreign/
end
#
- def index?
- return false if @comment.nil?
- @comment=~/index=1/
+ def index
+ return nil if @comment.nil?
+ return nil if not @comment=~/index=(\d)/
+ $1
end
#
def no_rename?