DataMapper での一意制約の指定方法

DataMapper で一意制約 (unique constraint) をつける方法がドキュメントに見つからないと思った人はおらんかー?
DataMapper では、一意制約には :unique_index オプションをつければよい。

class Department
  include DataMapper::Resource
  property :id, Serial
  ## 単一プロパティに一意制約をつけたいとき
  property :name, String, :nullable=>false, :unique_index=>true
  ## 複数のプロパティにまたがって一意制約をつけたいとき (:u1 は任意)
  property :parent_id, Integer, :nullable=>false, :unique_index=>:u1
  property :code,      String,  :nullable=>false, :unique_index=>:u1
    ## ちなみに :u1 を "u1" と指定すると無限ループになるので注意
    ## http://datamapper.lighthouseapp.com/projects/20609/tickets/637
end


・・・と思っていたんだけど、DataMapper の BTS にこんな ticket が。。。

Currently you pass in a :unique and :unique_index options when declaring properties. The :unique option sets up validation on the property, while the :unique_index sets up the actual unique indexes when using auto_migrate!

I think that :unique_index should be deprecated and the functionality should be rolled into :unique. It makes no sense to use one and not the other as far as I can tell. In fact it could be confusing if you specified :unique_index and forget :unique, and then get DB errors.

#403 Unify unique and unique_index property options - DataMapper - datamapper


なんと、:unique_index は index を作るだけであり、validation をするには :unique も指定しないといけないのだとか。

うわーん、知らなかったよー。

これはいけてないわ。互換性がなくなるのは許すから、:unique_index と :unique を統合してほしい。