2014-09-22 68 views
2

考慮以下僞CQL表結構:定義表複合主鍵卡桑德拉

CREATE TABLE searches (
    category text, 
    timestamp timestamp, 
    no_of_searches int, 
    avg_searches double, 
    PRIMARY KEY((category, timestamp), no_of_searches) 
); 

及以下的Rails Cequel型號:

class Search 
    include Cequel::Record 

    # Table columns 
    key :category,  :text 
    key :timestamp,  :timestamp 
    key :no_of_searches, :int 
    column :avg_searches, :double 
end 

,當我試圖使用模型來同步:

rake cequel:migrate 

以下耙引發錯誤:

rake aborted! 
Cequel::InvalidSchemaMigration: Existing partition keys category,timestamp differ from specified partition keys timestamp 

我試圖讓上面的導軌模型與上面的表使用分區鍵同步,雖然它表明這兩組鍵是不同的。我試着以相同的順序定義鍵,但沒有奏效。

我的目標是獲得預定義的數據庫表,其中分區鍵與導軌模型一起工作。任何幫助將不勝感激!

回答

5

key方法支持選項散列作爲第三個參數。選項散列進一步支持定義的密鑰,如orderpartitioning

基於給定的表定義這將意味着你的表列會是這個樣子:

# Table columns 
key :category,  :text,  { partition: true } 
key :timestamp,  :timestamp, { partition: true } 
key :no_of_searches, :int 
column :avg_searches, :double 

不幸的是,這是不是Cequel自述中記載,但它是在代碼中的記載,對於能夠被發現here