如何在appengine上迁移Datamapper

时间:2010-05-14 22:29:09

标签: ruby-on-rails google-app-engine datamapper migrate

我从

改变了我的模型
class Place
  include DataMapper::Resource
  has n, :trails

  property :id,           Serial
  property :name,         String,         :length => 140
  property :tag,          String,         :required => true
  timestamps :at 
end

class Place
  include DataMapper::Resource
  has n, :trails

  property :id,           Serial
  property :name,         String,         :length => 140
  property :tag,          String,         :required => true
  property :trail_count,  Integer,        :default => 0
  timestamps :at 
end

我刚刚添加了“property:trail_count,Integer,:default => 0”

我希望将现有的appengine表迁移到额外的字段“trail_count” 我读过DataMapper.auto_upgrade!应该这样做。

但我得到一个错误“未定义的方法`auto_upgrade!' for DataMapper:Module“

请帮助我如何迁移DM模型?

3 个答案:

答案 0 :(得分:1)

第三次重启服务器后,奇迹般地添加了该字段。

进行迁移仍然是一种奇怪而不太好的方式。 如何在没有迁移的情况下操纵数据?比如将字段“全名”拆分为名字和姓氏字段?你必须有一个迁移..

答案 1 :(得分:0)

我一直在查找相同的问题Roy,看起来迁移不适用于使用datamapper(或任何其他界面)的app引擎。它是数据存储区的一个功能,要更新现有的数据库条目,您必须查询数据库并一次更新一些数据库,以避免达到速率限制。 source

答案 2 :(得分:0)

尝试要求dm-migrations gem。这就是我用Sinatra 1.4.7和do_sqlite3 0.10.17解决问题的方法。

require 'dm-migrations'

require 'rubygems'
require 'sinatra'
require 'dm-core'
require 'dm-timestamps'
require 'dm-sqlite-adapter'
require 'dm-migrations'

DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/adserver.db")

class Ad

  include DataMapper::Resource

  property :id,                     Serial
  property :title,                  String
  property :content,                Text
  property :width,                  Integer
  property :height,                 Integer
  property :filename,               String
  property :url,                    String
  property :is_active,              Boolean
  property :created_at,             DateTime
  property :updated_at,             DateTime
  property :size,                   Integer
  property :content_type,           String

end

# Create or upgrade all table at once, like magic
DataMapper.auto_upgrade!

answer found here