lib/lhm/migrator.rb in lhm-1.0.0.rc.1 vs lib/lhm/migrator.rb in lhm-1.0.0.rc2

- old
+ new

@@ -59,23 +59,36 @@ # t.add_index([:comment, :created_at]) # end # def add_index(cols) - ddl = "create index `%s` on %s" % [@origin.idx_name(cols), idx_spec(cols)] + ddl = "create index `%s` on %s" % idx_parts(cols) statements << ddl.strip end # + # Add a unique index to a table: + # + # hadron_change_table("users") do |t| + # t.add_unique_index([:comment, :created_at]) + # end + # + + def add_unique_index(cols) + ddl = "create unique index `%s` on %s" % idx_parts(cols) + statements << ddl.strip + end + + # # Remove an index from a table # # hadron_change_table("users") do |t| # t.remove_index(:username, :created_at) # end # - def remove_index(*cols) + def remove_index(cols) ddl = "drop index `%s` on `%s`" % [@origin.idx_name(cols), @name] statements << ddl.strip end # @@ -116,10 +129,14 @@ def destination_read Table.parse(@origin.destination_name, connection) end def idx_spec(cols) - "#{ @name }(#{ [*cols].map(&:to_s).join(', ') })" + "`#{ @name }` (#{ Array(cols).map(&:to_s).join(', ') })" + end + + def idx_parts(cols) + [@origin.idx_name(cols), idx_spec(cols)] end end end