开发者

how do I migrate Datamapper on appengine

开发者 https://www.devze.com 2022-12-30 22:08 出处:网络
I\'ve changed my model from class Place include DataMapper::Resource has n, :trails property :id,Serial property :name,String,:length => 140

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,开发者_如何学Go :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?


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..


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消