如何在 appengine 上迁移 Datamapper

发布于 2024-09-01 19:01:25 字数 852 浏览 5 评论 0原文

我已将模型从 更改为

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!’对于 DataMapper:Module”,

您可以帮助我如何迁移 DM 模型吗?

I've changed my model from

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

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

to

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

I just added "property :trail_count, Integer, :default => 0"

and i want to migrate the existing appengine table to have the extra field "trail_count"
i've read that DataMapper.auto_upgrade! should do it.

but i get an error "undefined method `auto_upgrade!' for DataMapper:Module"

can you please help How do i migrate the DM models?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏至、离别 2024-09-08 19:01:25

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

这仍然是一种奇怪且不太好的迁移方式。
如何在不迁移的情况下操作数据?就像将“全名”字段拆分为名字和姓氏字段一样?你必须为此进行迁移..

After restarting the server for the third time the field was miraculously added.

It's still a weird and not so good way to do migrations.
how do you manipulate data without migrations? like splitting a field "full name" to first and last name fields? you gotta have a migration for that..

孤千羽 2024-09-08 19:01:25

我一直在寻找同样的问题罗伊,看来迁移在使用数据映射器(或任何其他接口)的应用程序引擎上不起作用。它是数据存储的一项功能,要更新现有数据库条目,您必须查询数据库并一次更新一些条目,以避免达到速率限制。
来源

I've been looking up the same issue Roy and it appears migrations don't work on app engine using datamapper (or any other interface). It's a function of the datastore, and to update existing database entries you'll have to query the database and update a few at a time to avoid hitting rate limits.
source

三生殊途 2024-09-08 19:01:25

尝试要求 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!

此处找到答案

Try requiring the dm-migrations gem. This was how I resolved the issue with Sinatra 1.4.7 and 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文